3 # Integration between git and Debian-style archives
5 # Copyright (C)2013 Ian Jackson
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 use Dpkg::Control::Hash;
30 our $isuite = 'unstable';
38 our $existing_package = 'dpkg';
40 our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
43 our (@dget) = qw(dget);
44 our (@dput) = qw(dput);
45 our (@debsign) = qw(debsign);
46 our (@sbuild) = qw(sbuild -A);
47 our (@dpkgbuildpackage) = qw(dpkg-buildpackage -i\.git/ -I.git);
48 our (@mergechanges) = qw(mergechanges -f);
51 our %opts_opt_map = ('dget' => \@dget,
53 'debsign' => \@debsign,
55 'dpkg-buildpackage' => \@dpkgbuildpackage,
56 'mergechanges' => \@mergechanges);
61 open DEBUG, ">/dev/null" or die $!;
63 our $remotename = 'dgit';
64 our $ourdscfield = 'Vcs-Dgit-Master';
65 our $branchprefix = 'dgit';
68 sub lbranch () { return "$branchprefix/$csuite"; }
69 my $lbranch_re = '^refs/heads/'.$branchprefix.'/([^/.]+)$';
70 sub lref () { return "refs/heads/".lbranch(); }
71 sub lrref () { return "refs/remotes/$remotename/$branchprefix/$csuite"; }
72 sub rrref () { return "refs/$branchprefix/$csuite"; }
79 sub dscfn ($) { return "${package}_$_[0].dsc"; }
83 sub fail { die "$us: @_\n"; }
85 sub badcfg { print STDERR "$us: invalid configuration: @_\n"; exit 12; }
87 sub no_such_package () {
88 print STDERR "$us: package $package does not exist in suite $isuite\n";
94 return "+".rrref().":".lrref();
101 $ua = LWP::UserAgent->new();
105 print "downloading $what...\n";
106 my $r = $ua->get(@_) or die $!;
107 return undef if $r->code == 404;
108 $r->is_success or fail "failed to fetch $what: ".$r->status_line;
109 return $r->decoded_content();
112 our ($dscdata,$dscurl,$dsc);
116 my $intro = shift @_;
117 print $fh $intro or die $!;
121 if (s{['\\]}{\\$&}g || m{\s} || m{[^-_./0-9a-z]}i) {
122 print $fh " '$_'" or die $!;
124 print $fh " $_" or die $!;
127 print $fh "\n" or die $!;
131 { local ($!); printcmd \*STDERR, "$_[0]: failed command:", @_ or die $!; };
133 fail "failed to fork/exec: $!";
134 } elsif (!($? & 0xff)) {
135 fail "subprocess failed with error exit status ".($?>>8);
137 fail "subprocess crashed (wait status $?)";
139 fail "subprocess produced invalid output";
144 printcmd(\*DEBUG,"+",@_) if $debug>0;
146 failedcmd @_ if system @_;
151 print "dgit ok: @_\n";
153 print "would be ok: @_ (but dry run only)\n";
157 sub cmdoutput_errok {
158 die Dumper(\@_)." ?" if grep { !defined } @_;
159 printcmd(\*DEBUG,"|",@_) if $debug>0;
160 open P, "-|", @_ or die $!;
163 { local $/ = undef; $d = <P>; }
165 if (!close P) { print DEBUG "=>!$?\n" if $debug>0; return undef; }
168 print DEBUG "=> \`$&'",(length $' ? '...' : ''),"\n" if $debug>0; #';
173 my $d = cmdoutput_errok @_;
174 defined $d or failedcmd @_;
179 printcmd(\*STDOUT,"#",@_);
182 sub runcmd_ordryrun {
190 our $helpmsg = <<END;
192 dgit [dgit-opts] clone [dgit-opts] package [suite] [./dir|/dir]
193 dgit [dgit-opts] fetch|pull [dgit-opts] [suite]
194 dgit [dgit-opts] build [git-buildpackage-opts|dpkg-buildpackage-opts]
195 dgit [dgit-opts] push [dgit-opts] [suite]
196 important dgit options:
197 -k<keyid> sign tag and package with <keyid> instead of default
198 --dry-run -n do not change anything, but go through the motions
199 --new -N allow introducing a new package
200 --debug -D increase debug level
201 -c<name>=<value> set git config option (used directly by dgit too)
204 our $later_warning_msg = <<END;
205 Perhaps the upload is stuck in incoming. Using the version from git.
209 print STDERR "$us: @_\n", $helpmsg or die $!;
214 print $helpmsg or die $!;
218 our %defcfg = ('dgit.default.distro' => 'debian',
219 'dgit.default.username' => '',
220 'dgit.default.archive-query-default-component' => 'main',
221 'dgit.default.ssh' => 'ssh',
222 'dgit-distro.debian.git-host' => 'git.debian.org',
223 'dgit-distro.debian.git-proto' => 'git+ssh://',
224 'dgit-distro.debian.git-path' => '/git/dgit-repos',
225 'dgit-distro.debian.git-check' => 'ssh-cmd',
226 'dgit-distro.debian.git-create' => 'ssh-cmd',
227 'dgit-distro.debian.sshdakls-host' => 'coccia.debian.org',
228 'dgit-distro.debian.sshdakls-dir' =>
229 '/srv/ftp-master.debian.org/ftp/dists',
230 'dgit-distro.debian.mirror' => 'http://http.debian.net/debian/');
234 return undef if $c =~ /RETURN-UNDEF/;
235 my @cmd = (@git, qw(config --), $c);
238 local ($debug) = $debug-1;
239 $v = cmdoutput_errok @cmd;
246 my $dv = $defcfg{$c};
247 return $dv if defined $dv;
249 badcfg "need value for one of: @_";
252 sub access_distro () {
253 return cfg("dgit-suite.$isuite.distro",
254 "dgit.default.distro");
259 my $distro = $idistro || access_distro();
260 my $value = cfg(map { ("dgit-distro.$distro.$_",
261 "dgit.default.$_") } @keys);
265 sub access_someuserhost ($) {
267 my $user = access_cfg("$some-user",'username');
268 my $host = access_cfg("$some-host");
269 return length($user) ? "$user\@$host" : $host;
272 sub access_gituserhost () {
273 return access_someuserhost('git');
276 sub access_giturl () {
277 my $url = access_cfg('git-url','RETURN-UNDEF');
280 access_cfg('git-proto').
281 access_gituserhost().
282 access_cfg('git-path');
284 return "$url/$package.git";
287 sub parsecontrolfh ($$@) {
288 my ($fh, $desc, @opts) = @_;
289 my %opts = ('name' => $desc, @opts);
290 my $c = Dpkg::Control::Hash->new(%opts);
291 $c->parse($fh) or die "parsing of $desc failed";
296 my ($file, $desc) = @_;
297 my $fh = new IO::Handle;
298 open $fh, '<', $file or die "$file: $!";
299 my $c = parsecontrolfh($fh,$desc);
300 $fh->error and die $!;
306 my ($dctrl,$field) = @_;
307 my $v = $dctrl->{$field};
308 return $v if defined $v;
309 fail "missing field $field in ".$v->get_option('name');
313 my $c = Dpkg::Control::Hash->new();
314 my $p = new IO::Handle;
315 my @cmd = (qw(dpkg-parsechangelog));
316 open $p, '-|', @cmd or die $!;
318 $?=0; $!=0; close $p or failedcmd @cmd;
324 sub archive_query ($) {
326 my $query = access_cfg('archive-query','RETURN-UNDEF');
327 if (!defined $query) {
328 my $distro = access_distro();
329 if ($distro eq 'debian') {
330 $query = "sshdakls:".
331 access_someuserhost('sshdakls').':'.
332 access_cfg('sshdakls-dir');
334 $query = "madison:$distro";
337 $query =~ s/^(\w+):// or badcfg "invalid archive-query method \`$query'";
340 { no strict qw(refs); &{"${method}_${proto}"}($proto,$data); }
343 sub archive_query_madison ($$) {
344 my ($proto,$data) = @_;
345 die unless $proto eq 'madison';
346 $rmad{$package} ||= cmdoutput
347 qw(rmadison -asource),"-s$isuite","-u$data",$package;
348 my $rmad = $rmad{$package};
349 return madison_parse($rmad);
352 sub archive_query_sshdakls ($$) {
353 my ($proto,$data) = @_;
354 $data =~ s/:.*// or badcfg "invalid sshdakls method string \`$data'";
355 my $dakls = cmdoutput
356 access_cfg('ssh'), $data, qw(dak ls -asource),"-s$isuite",$package;
357 return madison_parse($dakls);
360 sub canonicalise_suite_sshdakls ($$) {
361 my ($proto,$data) = @_;
362 $data =~ m/:/ or badcfg "invalid sshdakls method string \`$data'";
364 (access_cfg('ssh'), $`,
366 " if test -h $isuite; then readlink $isuite; exit 0; fi;".
367 " if test -d $isuite; then echo $isuite; exit 0; fi;".
369 my $dakls = cmdoutput @cmd;
370 failedcmd @cmd unless $dakls =~ m/^\w/;
374 sub madison_parse ($) {
377 foreach my $l (split /\n/, $rmad) {
378 $l =~ m{^ \s*( [^ \t|]+ )\s* \|
379 \s*( [^ \t|]+ )\s* \|
380 \s*( [^ \t|/]+ )(?:/([^ \t|/]+))? \s* \|
381 \s*( [^ \t|]+ )\s* }x or die "$rmad $?";
382 $1 eq $package or die "$rmad $package ?";
389 $component = access_cfg('archive-query-default-component');
391 $5 eq 'source' or die "$rmad ?";
392 my $prefix = substr($package, 0, $package =~ m/^l/ ? 4 : 1);
393 my $subpath = "/pool/$component/$prefix/$package/${package}_$vsn.dsc";
394 push @out, [$vsn,$subpath,$newsuite];
396 return sort { -version_compare_string($a->[0],$b->[0]); } @out;
399 sub canonicalise_suite_madison ($$) {
400 my @r = archive_query_madison($_[0],$_[1]);
402 "unable to canonicalise suite using package $package".
403 " which does not appear to exist in suite $isuite;".
404 " --existing-package may help";
408 sub canonicalise_suite () {
409 $csuite = archive_query('canonicalise_suite');
410 if ($isuite ne $csuite) {
411 # madison canonicalises for us
412 print "canonical suite name for $isuite is $csuite\n";
416 sub get_archive_dsc () {
417 canonicalise_suite();
418 my @vsns = archive_query('archive_query');
419 foreach my $vinfo (@vsns) {
420 my ($vsn,$subpath) = @$vinfo;
421 $dscurl = access_cfg('mirror').$subpath;
422 $dscdata = url_get($dscurl);
423 next unless defined $dscdata;
424 $dscurl = access_cfg('mirror').$subpath;
425 $dscdata = url_get($dscurl);
426 my $dscfh = new IO::File \$dscdata, '<' or die $!;
427 print DEBUG Dumper($dscdata) if $debug>1;
428 $dsc = parsecontrolfh($dscfh,$dscurl, allow_pgp=>1);
429 print DEBUG Dumper($dsc) if $debug>1;
430 my $fmt = getfield $dsc, 'Format';
431 fail "unsupported source format $fmt, sorry" unless $format_ok{$fmt};
437 sub check_for_git () {
439 my $how = access_cfg('git-check');
440 if ($how eq 'ssh-cmd') {
442 (access_cfg('ssh'),access_gituserhost(),
443 " set -e; cd ".access_cfg('git-path').";".
444 " if test -d $package.git; then echo 1; else echo 0; fi");
445 my $r= cmdoutput @cmd;
446 failedcmd @cmd unless $r =~ m/^[01]$/;
449 badcfg "unknown git-check \`$how'";
453 sub create_remote_git_repo () {
454 my $how = access_cfg('git-create');
455 if ($how eq 'ssh-cmd') {
457 (access_cfg('ssh'),access_gituserhost(),
458 "set -e; cd ".access_cfg('git-path').";".
459 " mkdir -p $package.git;".
461 " if ! test -d objects; then git init --bare; fi");
463 badcfg "unknown git-create \`$how'";
467 our ($dsc_hash,$upload_hash);
469 our $ud = '.git/dgit/unpack';
477 sub mktree_in_ud_from_only_subdir () {
478 # changes into the subdir
481 $dirs[0] =~ m#^([^/]+)/\.$# or die;
483 chdir $dir or die "$dir $!";
485 die $! unless $!==&ENOENT;
486 runcmd qw(git init -q);
487 rmtree('.git/objects');
488 symlink '../../../../objects','.git/objects' or die $!;
489 runcmd @git, qw(add -Af);
490 my $tree = cmdoutput @git, qw(write-tree);
491 $tree =~ m/^\w+$/ or die "$tree ?";
496 my $field = $dsc->{'Checksums-Sha256'} || $dsc->{Files};
498 fail "missing both Checksums-Sha256 and Files in ".
499 $dsc->get_option('name');
501 m/^\w+ \d+ (\S+)$/ or
502 fail "could not parse .dsc Files/Checksums line \`$_'";
504 } grep m/\S/, split /\n/, $field;
507 sub is_orig_file ($) {
509 m/\.orig(?:-\w+)?\.tar\.\w+$/;
512 sub make_commit ($) {
514 return cmdoutput @git, qw(hash-object -w -t commit), $file;
517 sub generate_commit_from_dsc () {
521 foreach my $f (dsc_files()) {
522 die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
524 link "../../../$f", $f
528 runcmd @dget, qw(--), $dscurl;
529 foreach my $f (grep { is_orig_file($_) } @files) {
530 link $f, "../../../../$f"
534 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
535 runcmd qw(sh -ec), 'dpkg-parsechangelog >../changelog.tmp';
536 my $clogp = parsecontrol('../changelog.tmp',"commit's changelog");
537 my $date = cmdoutput qw(date), '+%s %z', qw(-d), getfield($clogp,'Date');
538 my $author = getfield $clogp, 'Maintainer';
539 $author =~ s#,.*##ms;
540 my $authline = "$author $date";
541 $authline =~ m/^[^<>]+ \<\S+\> \d+ [-+]\d+$/ or
542 fail "unexpected commit author line format \`$authline'".
543 " (was generated from changelog Maintainer field)";
544 my $changes = getfield $clogp, 'Changes';
545 open C, ">../commit.tmp" or die $!;
546 print C <<END or die $!;
553 # imported from the archive
556 my $outputhash = make_commit qw(../commit.tmp);
557 my $cversion = getfield $clogp, 'Version';
558 print "synthesised git commit from .dsc $cversion\n";
560 runcmd @git, qw(reset --hard), $upload_hash;
561 runcmd qw(sh -ec), 'dpkg-parsechangelog >>../changelogold.tmp';
562 my $oldclogp = parsecontrol('../changelogold.tmp','previous changelog');
563 my $oversion = getfield $oldclogp, 'Version';
565 version_compare_string($oversion, $cversion);
567 # git upload/ is earlier vsn than archive, use archive
568 open C, ">../commit2.tmp" or die $!;
569 print C <<END or die $!;
576 Record $package ($cversion) in archive suite $csuite
578 $outputhash = make_commit qw(../commit2.tmp);
579 } elsif ($vcmp > 0) {
580 print STDERR <<END or die $!;
582 Version actually in archive: $cversion (older)
583 Last allegedly pushed/uploaded: $oversion (newer or same)
586 $outputhash = $upload_hash;
587 } elsif ($outputhash ne $upload_hash) {
588 fail "version in archive ($cversion)".
589 " is same as version in git".
590 " to-be-uploaded (upload/) branch ($oversion)".
591 " but archive version hash no commit hash?!";
594 chdir '../../../..' or die $!;
595 runcmd @git, qw(update-ref -m),"dgit fetch import $cversion",
596 'DGIT_ARCHIVE', $outputhash;
597 cmdoutput @git, qw(log -n2), $outputhash;
598 # ... gives git a chance to complain if our commit is malformed
603 sub ensure_we_have_orig () {
604 foreach my $f (dsc_files()) {
605 next unless is_orig_file($f);
607 die "$f ?" unless -f _;
609 die "$f $!" unless $!==&ENOENT;
611 my $origurl = $dscurl;
612 $origurl =~ s{/[^/]+$}{};
614 die "$f ?" unless $f =~ m/^${package}_/;
615 die "$f ?" if $f =~ m#/#;
616 runcmd_ordryrun qw(sh -ec),'cd ..; exec "$@"','x',
622 return cmdoutput @git, qw(rev-parse), "$_[0]~0";
625 sub is_fast_fwd ($$) {
626 my ($ancestor,$child) = @_;
627 my $mb = cmdoutput @git, qw(merge-base), $ancestor, $child;
628 return rev_parse($mb) eq rev_parse($ancestor);
631 sub git_fetch_us () {
632 badusage "cannot dry run with fetch" if $dryrun;
633 runcmd @git, qw(fetch),access_giturl(),fetchspec();
636 sub fetch_from_archive () {
637 # ensures that lrref() is what is actually in the archive,
639 get_archive_dsc() or return 0;
640 $dsc_hash = $dsc->{$ourdscfield};
641 if (defined $dsc_hash) {
642 $dsc_hash =~ m/\w+/ or fail "invalid hash in .dsc \`$dsc_hash'";
644 print "last upload to archive specified git hash\n";
646 print "last upload to archive has NO git hash\n";
649 my $lrref_fn = ".git/".lrref();
650 if (open H, $lrref_fn) {
653 die "$lrref_fn $upload_hash ?" unless $upload_hash =~ m/^\w+$/;
654 } elsif ($! == &ENOENT) {
659 print DEBUG "previous reference hash=$upload_hash\n";
661 if (defined $dsc_hash) {
662 fail "missing git history even though dsc has hash -".
663 " could not find commit $dsc_hash".
664 " (should be in ".access_giturl()."#".rref().")"
667 ensure_we_have_orig();
668 if (is_fast_fwd($dsc_hash,$upload_hash)) {
669 print STDERR <<END or die $!;
671 Git commit in archive is behind the last version allegedly pushed/uploaded.
672 Commit referred to by archive: $dsc_hash
673 Last allegedly pushed/uploaded: $upload_hash
676 $hash = $upload_hash;
679 $hash = generate_commit_from_dsc();
681 print DEBUG "current hash=$hash\n";
683 fail "not fast forward on last upload branch!".
684 " (archive's version left in DGIT_ARCHIVE)"
685 unless is_fast_fwd($upload_hash, $hash);
687 if ($upload_hash ne $hash) {
688 my @upd_cmd = (@git, qw(update-ref -m), 'dgit fetch', lrref(), $hash);
692 dryrun_report @upd_cmd;
700 canonicalise_suite();
701 badusage "dry run makes no sense with clone" if $dryrun;
702 mkdir $dstdir or die "$dstdir $!";
703 chdir "$dstdir" or die "$dstdir $!";
704 runcmd @git, qw(init -q);
705 runcmd @git, qw(config), "remote.$remotename.fetch", fetchspec();
706 open H, "> .git/HEAD" or die $!;
707 print H "ref: ".lref()."\n" or die $!;
709 runcmd @git, qw(remote add), 'origin', access_giturl();
710 if (check_for_git()) {
711 print "fetching existing git history\n";
713 runcmd @git, qw(fetch origin);
715 print "starting new git history\n";
717 fetch_from_archive() or no_such_package;
718 runcmd @git, qw(reset --hard), lrref();
719 printdone "ready for work in $dstdir";
723 if (check_for_git()) {
726 fetch_from_archive() or no_such_package();
727 printdone "fetched into ".lrref();
732 runcmd_ordryrun @git, qw(merge -m),"Merge from $csuite [dgit]",
734 printdone "fetched to ".lrref()." and merged into HEAD";
737 sub check_not_dirty () {
738 my @cmd = (@git, qw(diff --quiet HEAD));
739 printcmd(\*DEBUG,"+",@cmd) if $debug>0;
740 $!=0; $?=0; system @cmd;
741 return if !$! && !$?;
742 if (!$! && $?==256) {
743 fail "working tree is dirty (does not match HEAD)";
749 sub commit_quilty_patch ($) {
751 my $output = cmdoutput @git, qw(status --porcelain);
752 my %fixups = map {$_=>1}
753 (".pc/debian-changes-$vsn/","debian/patches/debian-changes-$vsn");
755 foreach my $l (split /\n/, $output) {
756 next unless $l =~ s/^\?\? //;
757 next unless $fixups{$l};
760 print DEBUG "checking for quilty\n", Dumper(\@files);
762 my $m = "Commit Debian 3.0 (quilt) metadata";
764 runcmd_ordryrun @git, qw(add), @files;
765 runcmd_ordryrun @git, qw(commit -m), $m;
770 print DEBUG "actually entering push\n";
771 my $clogp = parsechangelog();
772 $package = getfield $clogp, 'Source';
773 my $cversion = getfield $clogp, 'Version';
774 my $dscfn = dscfn($cversion);
776 fail "looked for .dsc $dscfn, but $!;".
777 " maybe you forgot to build";
778 $dsc = parsecontrol("../$dscfn","$dscfn");
779 my $dscpackage = getfield $dsc, 'Source';
780 my $format = getfield $dsc, 'Format';
781 my $dversion = getfield $dsc, 'Version';
782 ($dscpackage eq $package && $dversion eq $cversion) or
783 fail "$dsc is for $dscpackage $dversion".
784 " but debian/changelog is for $package $cversion";
785 print DEBUG "format $format\n";
786 if ($format eq '3.0 (quilt)') {
787 print "Format \`$format', urgh\n";
788 commit_quilty_patch($dversion);
793 print "checking that $dscfn corresponds to HEAD\n";
794 runcmd qw(dpkg-source -x --), "../../../../$dscfn";
795 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
796 chdir '../../../..' or die $!;
797 printcmd \*DEBUG,"+",@_;
798 my @diffcmd = (@git, qw(diff --exit-code), $tree);
800 if (system @diffcmd) {
802 fail "$dscfn specifies a different tree to your HEAD commit;".
803 " perhaps you forgot to build";
809 #do fast forward check and maybe fake merge
810 # if (!is_fast_fwd(mainbranch
811 # runcmd @git, qw(fetch -p ), "$alioth_git/$package.git",
812 # map { lref($_).":".rref($_) }
814 $dsc->{$ourdscfield} = rev_parse('HEAD');
815 $dsc->save("../$dscfn.tmp") or die $!;
817 my $multi = "../${package}_${cversion}_multi.changes";
819 $changesfile = $multi;
821 $!==&ENOENT or die "$multi: $!";
822 my $pat = "${package}_${cversion}_*.changes";
823 my @cs = glob "../$pat";
824 fail "failed to find unique changes file".
825 " (looked for $pat in .., or $multi);".
826 " perhaps you need to use dgit -C"
828 ($changesfile) = @cs;
831 my $tag = debiantag($dversion);
832 if (!check_for_git()) {
833 create_remote_git_repo();
835 runcmd_ordryrun @git, qw(push),access_giturl(),"HEAD:".rrref();
837 rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!";
839 print "[new .dsc left in $dscfn.tmp]\n";
842 if (!defined $keyid) {
843 $keyid = access_cfg('keyid','RETURN-UNDEF');
845 my @tag_cmd = (@git, qw(tag -s -m),
846 "Release $dversion for $csuite [dgit]");
847 push @tag_cmd, qw(-u),$keyid if defined $keyid;
849 runcmd_ordryrun @tag_cmd;
850 my @debsign_cmd = @debsign;
851 push @debsign_cmd, "-k$keyid" if defined $keyid;
852 push @debsign_cmd, $changesfile;
853 runcmd_ordryrun @debsign_cmd;
855 runcmd_ordryrun @git, qw(push),access_giturl(),"refs/tags/$tag";
856 my $host = access_cfg('upload-host','RETURN-UNDEF');
857 my @hostarg = defined($host) ? ($host,) : ();
858 runcmd_ordryrun @dput, @hostarg, $changesfile;
859 printdone "pushed and uploaded $dversion";
865 badusage "-p is not allowed with clone; specify as argument instead"
869 } elsif (@ARGV==2 && $ARGV[1] =~ m#^\w#) {
870 ($package,$isuite) = @ARGV;
871 } elsif (@ARGV==2 && $ARGV[1] =~ m#^[./]#) {
872 ($package,$dstdir) = @ARGV;
874 ($package,$isuite,$dstdir) = @ARGV;
876 badusage "incorrect arguments to dgit clone";
878 $dstdir ||= "$package";
883 my $branch = cmdoutput_errok @git, qw(symbolic-ref HEAD);
884 if ($branch =~ m#$lbranch_re#o) {
891 sub fetchpullargs () {
892 if (!defined $package) {
893 my $sourcep = parsecontrol('debian/control','debian/control');
894 $package = getfield $sourcep, 'Source';
897 # $isuite = branchsuite(); # this doesn't work because dak hates canons
899 my $clogp = parsechangelog();
900 $isuite = getfield $clogp, 'Distribution';
902 canonicalise_suite();
903 print "fetching from suite $csuite\n";
906 canonicalise_suite();
908 badusage "incorrect arguments to dgit fetch or dgit pull";
926 badusage "-p is not allowed with dgit push" if defined $package;
927 runcmd @git, qw(diff --quiet HEAD);
928 my $clogp = parsechangelog();
929 $package = getfield $clogp, 'Source';
931 $isuite = getfield $clogp, 'Distribution';
933 local ($package) = $existing_package; # this is a hack
934 canonicalise_suite();
937 badusage "incorrect arguments to dgit push";
939 if (fetch_from_archive()) {
940 is_fast_fwd(lrref(), 'HEAD') or die;
943 fail "package appears to be new in this suite;".
944 " if this is intentional, use --new";
950 # we pass further options and args to git-buildpackage
951 badusage "-p is not allowed with dgit build" if defined $package;
952 my $clogp = parsechangelog();
953 $isuite = getfield $clogp, 'Distribution';
954 $package = getfield $clogp, 'Source';
956 (qw(git-buildpackage -us -uc --git-no-sign-tags),
957 "--git-builder=@dpkgbuildpackage");
958 unless (grep { m/^--git-debian-branch/ } @ARGV) {
959 canonicalise_suite();
960 push @cmd, "--git-debian-branch=".lbranch();
962 runcmd_ordryrun @cmd, @ARGV;
963 printdone "build successful\n";
968 badusage "-p is not allowed with dgit sbuild" if defined $package;
969 my $clogp = parsechangelog();
970 $package = getfield $clogp, 'Source';
971 my $isuite = getfield $clogp, 'Distribution';
972 my $version = getfield $clogp, 'Version';
973 runcmd_ordryrun (@dpkgbuildpackage, qw(-us -uc -S));
974 chdir ".." or die $!;
975 my $sourcechanges = "${package}_${version}_source.changes";
976 my $dscfn = dscfn($version);
977 my $pat = "${package}_${version}_*.changes";
979 stat $dscfn or fail "$dscfn (in parent directory): $!";
980 stat $sourcechanges or fail "$sourcechanges (in parent directory): $!";
981 foreach my $cf (glob $pat) {
982 next if $cf eq $sourcechanges;
983 unlink $cf or fail "remove $cf: $!";
986 runcmd_ordryrun @sbuild, @ARGV, qw(-d), $isuite, $dscfn;
987 runcmd_ordryrun @mergechanges, glob $pat;
988 my $multichanges = "${package}_${version}_multi.changes";
990 stat $multichanges or fail "$multichanges: $!";
992 printdone "build successful, results in $multichanges\n" or die $!;
995 sub cmd_quilt_fixup {
996 badusage "incorrect arguments to dgit quilt-fixup";
997 my $clogp = parsechangelog();
998 commit_quilty_patch((getfield $clogp, 'Version'));
1004 last unless $ARGV[0] =~ m/^-/;
1008 if (m/^--dry-run$/) {
1010 } elsif (m/^--no-sign$/) {
1012 } elsif (m/^--help$/) {
1014 } elsif (m/^--new$/) {
1016 } elsif (m/^--(\w+)=(.*)/s && ($om = $opts_opt_map{$1})) {
1018 } elsif (m/^--(\w+):(.*)/s && ($om = $opts_opt_map{$1})) {
1020 } elsif (m/^--existing-package=(.*)/s) {
1021 $existing_package = $1;
1022 } elsif (m/^--distro=(.*)/s) {
1025 badusage "unknown long option \`$_'";
1031 } elsif (s/^-h/-/) {
1033 } elsif (s/^-D/-/) {
1034 open DEBUG, ">&STDERR" or die $!;
1036 } elsif (s/^-N/-/) {
1038 } elsif (s/^-c(.*=.*)//s) {
1039 push @git, '-c', $1;
1040 } elsif (s/^-d(.*)//s) {
1042 } elsif (s/^-C(.*)//s) {
1044 } elsif (s/^-k(.*)//s) {
1047 badusage "unknown short option \`$_'";
1055 print STDERR "DRY RUN ONLY\n" if $dryrun;
1057 print STDERR $helpmsg or die $!;
1060 my $cmd = shift @ARGV;
1062 { no strict qw(refs); &{"cmd_$cmd"}(); }