#!/bin/sh -ef

## usage: girar-nmu-helper-task-add-git [-t <task id>] path/to/repo1.git ...

REPOPREFIX=00-tmp-
gitbranch=nmu
TASKID=
GITALTHOST=
gitname=

while getopts b:d:hH:n:p:t: opt; do
	case "$opt" in
		b) repobranch="${OPTARG:?}"
			readonly repobranch ;;
		d) gitbranch="${OPTARG:?}" ;;
		H) GITALTHOST="${OPTARG:?}"
			readonly GITALTHOST ;;
		p) REPOPREFIX="${OPTARG:?}" ;;
		t) TASKID="${OPTARG:?}"
			readonly TASKID ;;
		n) gitname="${OPTARG:?}"
			readonly gitname ;;
		h) pod2usage --exit=0 "$0"; exit 0 ;;
		*) pod2usage --exit=2 "$0"; exit 2 ;;
	esac
done
shift "$((OPTIND-1))"

if [ -z "$TASKID" ]; then
    taskadd='-A'
else
    taskadd="-a $TASKID"
fi

for repopath in "$@"; do
    if [ -z "$repopath" ] || [ x"$repopath" = x"-h" ]; then
	echo "usage: girar-nmu-helper-task-add-git path/to/repo.git [task id]"
	exit 1;
    fi

    if ! [ -d "$repopath/.git" ]; then
	echo "error: $repopath is not a git repository directory"
	exit 1;
    fi

    girar-nmu-helper-git-push-build -T -K -p "$REPOPREFIX" -d "$gitbranch" \
	${GITALTHOST:+-H $GITALTHOST} ${repobranch:+-b $repobranch} \
	${gitname:+-n "$gitname"} $taskadd $repopath
done


: <<'__EOF__'

=head1	NAME

girar-nmu-task-helper-add-git - add NMU generated git repos to the given task.

=head1	SYNOPSIS

B<girar-nmu-helper-task-add-git>
[B<-h>] 
[B<-b> I<repository>]
[B<-d> I<local branch>]
[B<-n> I<remote git name>]
[B<-p> I<prefix>]
[B<-t> I<task>]
I<path ...>

=head1	DESCRIPTION

B<girar-nmu-task-add> 
add NMU generated packages to the given task in prescribed order.

=head1	OPTIONS

=over

=item	B<-b> I<repository name>

Name of the repository branch. Values are: sisyphus|5.1|p5|..
Default is sisyphus.

=item	B<-d> I<local branch name>

Name of the local branch to build from. Default is nmu.

=item	B<-H> [I<git.alt ssh alias>]

By default, git.altlinux.org account should be configured as git.alt in ~/.ssh/config.
If you does not follow that convention, use -H <git.alt your ssh alias> option.

=item	B<-p> I<prefix>

Prefix to add before git repository name.
Useful to distinguish among automated and own repositories.
By default prefix is "00-tmp-".

=item	B<-t> [I<task ID>]

Id of task to add packages to; git.alt task [I<task ID>] add.

=item	B<-h>

Display this help and exit.

=back

=head1	AUTHOR

Written by Igor Vlasenko <viy@altlinux.org>.

=head1	COPYING

Copyright (c) 2010 Igor Vlasenko, ALT Linux Team.

This is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

=cut

__EOF__
