+ $dstdir ||= "$package";
+ clone($dstdir);
+}
+
+sub branchsuite () {
+ my $branch = cmdoutput_errok @git, qw(symbolic-ref HEAD);
+ if ($branch =~ m#$lbranch_re#o) {
+ return $1;
+ } else {
+ return undef;
+ }
+}
+
+sub fetchpullargs () {
+ if (!defined $package) {
+ my $sourcep = parsecontrol('debian/control','debian/control');
+ $package = getfield $sourcep, 'Source';
+ }
+ if (@ARGV==0) {
+# $isuite = branchsuite(); # this doesn't work because dak hates canons
+ if (!$isuite) {
+ my $clogp = parsechangelog();
+ $isuite = getfield $clogp, 'Distribution';
+ }
+ canonicalise_suite();
+ print "fetching from suite $csuite\n";
+ } elsif (@ARGV==1) {
+ ($isuite) = @ARGV;
+ canonicalise_suite();
+ } else {
+ badusage "incorrect arguments to dgit fetch or dgit pull";
+ }
+}
+
+sub cmd_fetch {
+ parseopts();
+ fetchpullargs();
+ fetch();
+}
+
+sub cmd_pull {
+ parseopts();
+ fetchpullargs();
+ pull();
+}
+
+sub cmd_push {
+ parseopts();
+ badusage "-p is not allowed with dgit push" if defined $package;
+ runcmd @git, qw(diff --quiet HEAD);
+ my $clogp = parsechangelog();
+ $package = getfield $clogp, 'Source';
+ if (@ARGV==0) {
+ $isuite = getfield $clogp, 'Distribution';
+ if ($new_package) {
+ local ($package) = $existing_package; # this is a hack
+ canonicalise_suite();
+ }
+ } else {
+ badusage "incorrect arguments to dgit push";
+ }
+ if (check_for_git()) {
+ git_fetch_us();
+ }
+ if (fetch_from_archive()) {
+ is_fast_fwd(lrref(), 'HEAD') or die;
+ } else {
+ $new_package or
+ fail "package appears to be new in this suite;".
+ " if this is intentional, use --new";
+ }
+ dopush();
+}
+
+sub cmd_build {
+ # we pass further options and args to git-buildpackage
+ badusage "-p is not allowed with dgit build" if defined $package;
+ my $clogp = parsechangelog();
+ $isuite = getfield $clogp, 'Distribution';
+ $package = getfield $clogp, 'Source';
+ my @cmd =
+ (qw(git-buildpackage -us -uc --git-no-sign-tags),
+ "--git-builder=@dpkgbuildpackage");
+ unless (grep { m/^--git-debian-branch/ } @ARGV) {
+ canonicalise_suite();
+ push @cmd, "--git-debian-branch=".lbranch();
+ }
+ runcmd_ordryrun @cmd, @ARGV;
+ printdone "build successful\n";
+}
+
+sub cmd_sbuild {
+ check_not_dirty();
+ badusage "-p is not allowed with dgit sbuild" if defined $package;
+ my $clogp = parsechangelog();
+ $package = getfield $clogp, 'Source';
+ my $isuite = getfield $clogp, 'Distribution';
+ my $version = getfield $clogp, 'Version';
+ runcmd_ordryrun (@dpkgbuildpackage, qw(-us -uc -S));
+ chdir ".." or die $!;
+ my $sourcechanges = "${package}_${version}_source.changes";
+ my $dscfn = dscfn($version);
+ my $pat = "${package}_${version}_*.changes";
+ if (!$dryrun) {
+ stat $dscfn or fail "$dscfn (in parent directory): $!";
+ stat $sourcechanges or fail "$sourcechanges (in parent directory): $!";
+ foreach my $cf (glob $pat) {
+ next if $cf eq $sourcechanges;
+ unlink $cf or fail "remove $cf: $!";
+ }
+ }
+ runcmd_ordryrun @sbuild, @ARGV, qw(-d), $isuite, $dscfn;
+ runcmd_ordryrun @mergechanges, glob $pat;
+ my $multichanges = "${package}_${version}_multi.changes";
+ if (!$dryrun) {
+ stat $multichanges or fail "$multichanges: $!";
+ }
+ printdone "build successful, results in $multichanges\n" or die $!;
+}
+
+sub cmd_quilt_fixup {
+ badusage "incorrect arguments to dgit quilt-fixup";
+ my $clogp = parsechangelog();
+ commit_quilty_patch((getfield $clogp, 'Version'));