#!/bin/sh

# copyright, licensing and documentation at the end

set -e
set -u

usage() {
    perl -MPod::Usage=pod2usage -e"pod2usage(-input => '$0', -verbose=>99, -sections=>[qw(SYNOPSIS DESCRIPTION COMMANDS)])"
    exit 1
}


[ -n "${1:-}" ] || usage
[ -z "${2:-}" ] || usage

cd "${DPT_PACKAGES:=.}"

if [ -d "$1" ]; then
    echo "Updating existing checkout in ${DPT_PACKAGES}/$1"
    cd "$1"
    gbp-pull
else
    gbp-clone --all git+ssh://git.debian.org/git/pkg-perl/packages/$1.git

    echo "$1 ready in ${DPT_PACKAGES}/$1"
fi

exit 0

POD=<<'EOF'
=head1 NAME

dpt-checkout - work on a pkg-perl package

=head1 SYNOPSIS

B<dpt checkout> I<package-name>

=head1 DESCRIPTION

B<dpt checkout> puts you in the working copy for the packaging of a given package.

If the package directory exists, the clone is updated by calling
L<gbp-pull(1)>. If it doesn't exist, it is cloned off pkg-perl git
repositories via L<gbp-clone(1)>.

=head1 CONFIGURATION

B<dpt checkout> uses the C<DPT_PACKAGES> environment variable. If
C<DPT_PACKAGES> is not defined, the current working directory is used.

See L<dpt-config(5)> for details.

=head1 COPYRIGHT & LICENSE

Copyright 2013 gregor herrmann L<gregoa@debian.org>
Copyright 2013 Damyan Ivanov L<dmn@debian.org>

This program is free software, licensed under the same term as perl.

=cut
EOF
