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';
37 our $existing_package = 'dpkg';
39 our %format_ok = map { $_=>1 } ("1.0","3.0 (native)","3.0 (quilt)");
42 our (@dget) = qw(dget);
43 our (@dput) = qw(dput);
44 our (@debsign) = qw(debsign);
45 our (@sbuild) = qw(sbuild);
46 our (@dpkgbuildpackage) = qw(dpkg-buildpackage -i\.git/ -I.git);
47 our (@mergechanges) = qw(mergechanges -f);
50 our %opts_opt_map = ('dget' => \@dget,
52 'debsign' => \@debsign,
54 'dpkg-buildpackage' => \@dpkgbuildpackage,
55 'mergechanges' => \@mergechanges);
60 open DEBUG, ">/dev/null" or die $!;
62 our $remotename = 'dgit';
63 our $ourdscfield = 'Vcs-Dgit-Master';
64 our $branchprefix = 'dgit';
67 sub lbranch () { return "$branchprefix/$csuite"; }
68 my $lbranch_re = '^refs/heads/'.$branchprefix.'/([^/.]+)$';
69 sub lref () { return "refs/heads/".lbranch(); }
70 sub lrref () { return "refs/remotes/$remotename/$csuite"; }
71 sub rrref () { return "refs/$branchprefix/$csuite"; }
72 sub debiantag ($) { return "debian/$_[0]"; }
74 sub dscfn ($) { return "${package}_${1}.dsc"; }
78 sub fail { die "$us: @_\n"; }
80 sub badcfg { print STDERR "$us: invalid configuration: @_\n"; exit 12; }
82 sub no_such_package () {
83 print STDERR "$us: package $package does not exist in suite $isuite\n";
89 return "+".rrref().":".lrref();
96 $ua = LWP::UserAgent->new();
100 print "downloading $what...\n";
101 my $r = $ua->get(@_) or die $!;
102 $r->is_success or fail "failed to fetch $what: ".$r->status_line;
103 return $r->decoded_content();
106 our ($dscdata,$dscurl,$dsc);
110 my $intro = shift @_;
111 print $fh $intro or die $!;
115 if (s{['\\]}{\\$&}g || m{\s} || m{[^-_./0-9a-z]}i) {
116 print $fh " '$_'" or die $!;
118 print $fh " $_" or die $!;
121 print $fh "\n" or die $!;
125 { local ($!); printcmd \*STDERR, "$_[0]: failed command:", @_ or die $!; };
127 fail "failed to fork/exec: $!";
128 } elsif (!($? & 0xff)) {
129 fail "subprocess failed with error exit status ".($?>>8);
131 fail "subprocess crashed (wait status $?)";
133 fail "subprocess produced invalid output";
138 printcmd(\*DEBUG,"+",@_) if $debug>0;
140 failedcmd @_ if system @_;
145 print "dgit ok: @_\n";
147 print "would be ok: @_ (but dry run only)\n";
151 sub cmdoutput_errok {
152 die Dumper(\@_)." ?" if grep { !defined } @_;
153 printcmd(\*DEBUG,"|",@_) if $debug>0;
154 open P, "-|", @_ or die $!;
157 { local $/ = undef; $d = <P>; }
159 if (!close P) { print DEBUG "=>!$?\n" if $debug>0; return undef; }
162 print DEBUG "=> \`$&'",(length $' ? '...' : ''),"\n" if $debug>0; #';
167 my $d = cmdoutput_errok @_;
168 defined $d or failedcmd @_;
173 printcmd(\*STDOUT,"#",@_);
176 sub runcmd_ordryrun {
184 our $helpmsg = <<END;
186 dgit [dgit-opts] clone [dgit-opts] package [suite] [./dir|/dir]
187 dgit [dgit-opts] fetch|pull [dgit-opts] [suite]
188 dgit [dgit-opts] build [git-buildpackage-opts|dpkg-buildpackage-opts]
189 dgit [dgit-opts] push [dgit-opts] [suite]
190 important dgit options:
191 -k<keyid> sign tag and package with <keyid> instead of default
192 --dry-run -n do not change anything, but go through the motions
193 --new -N allow introducing a new package
194 --debug -D increase debug level
195 -c<name>=<value> set git config option (used directly by dgit too)
199 print STDERR "$us: @_\n", $helpmsg or die $!;
204 print $helpmsg or die $!;
208 our %defcfg = ('dgit.default.distro' => 'debian',
209 'dgit.default.username' => '',
210 'dgit.default.archive-query-default-component' => 'main',
211 'dgit.default.ssh' => 'ssh',
212 'dgit-distro.debian.git-host' => 'dgit.debian.net',
213 'dgit-distro.debian.git-proto' => 'git+ssh://',
214 'dgit-distro.debian.git-path' => '/git/dgit-repos',
215 'dgit-distro.debian.git-check' => 'ssh-cmd',
216 'dgit-distro.debian.git-create' => 'ssh-cmd',
217 'dgit-distro.debian.sshdakls-host' => 'coccia.debian.org',
218 'dgit-distro.debian.sshdakls-dir' =>
219 '/srv/ftp-master.debian.org/ftp/dists',
220 'dgit-distro.debian.mirror' => 'http://http.debian.net/debian/');
224 return undef if $c =~ /RETURN-UNDEF/;
225 my @cmd = (@git, qw(config --), $c);
228 local ($debug) = $debug-1;
229 $v = cmdoutput_errok @cmd;
236 my $dv = $defcfg{$c};
237 return $dv if defined $dv;
239 badcfg "need value for one of: @_";
242 sub access_distro () {
243 return cfg("dgit-suite.$isuite.distro",
244 "dgit.default.distro");
249 my $distro = access_distro();
250 my $value = cfg(map { ("dgit-distro.$distro.$_",
251 "dgit.default.$_") } @keys);
255 sub access_someuserhost ($) {
257 my $user = access_cfg("$some-user",'username');
258 my $host = access_cfg("$some-host");
259 return length($user) ? "$user\@$host" : $host;
262 sub access_gituserhost () {
263 return access_someuserhost('git');
266 sub access_giturl () {
267 my $url = access_cfg('git-url','RETURN-UNDEF');
270 access_cfg('git-proto').
271 access_gituserhost().
272 access_cfg('git-path');
274 return "$url/$package.git";
277 sub parsecontrolfh ($$@) {
278 my ($fh, $desc, @opts) = @_;
279 my $c = Dpkg::Control::Hash->new({ 'name' => $desc, @opts });
280 $c->parse($fh) or die "parsing of $desc failed";
284 my ($file, $desc) = @_;
285 my $fh = new IO::File '<', $file or die "$file: $!";
286 my $c = parsecontrolfh($fh,$desc);
287 $fh->error and die $!;
293 my ($dctrl,$field) = @_;
294 my $v = $dctrl->{$field};
295 return $v if defined $v;
296 fail "missing field $field in ".$v->get_option('name');
300 my $c = Dpkg::Control::Hash->new();
301 my $p = new IO::Handle;
302 my @cmd = (qw(dpkg-parsechangelog));
303 open $p, '-|', @cmd or die $!;
305 $?=0; $!=0; close $p or failedcmd @cmd;
311 sub archive_query ($) {
313 my $query = access_cfg('archive-query','RETURN-UNDEF');
314 if (!defined $query) {
315 my $distro = access_distro();
316 if ($distro eq 'debian') {
317 $query = "sshdakls:".
318 access_someuserhost('sshdakls').':'.
319 access_cfg('sshdakls-dir');
321 $query = "madison:$distro";
324 $query =~ s/^(\w+):// or badcfg "invalid archive-query method \`$query'";
327 { no strict qw(refs); &{"${method}_${proto}"}($proto,$data); }
330 sub archive_query_madison ($$) {
331 my ($proto,$data) = @_;
332 die unless $proto eq 'madison';
333 $rmad{$package} ||= cmdoutput
334 qw(rmadison -asource),"-s$isuite","-u$data",$package;
335 my $rmad = $rmad{$package};
336 return madison_parse($rmad);
339 sub archive_query_sshdakls ($$) {
340 my ($proto,$data) = @_;
341 $data =~ s/:.*// or badcfg "invalid sshdakls method string \`$data'";
342 my $dakls = cmdoutput
343 access_cfg('ssh'), $data, qw(dak ls -asource),"-s$isuite",$package;
344 return madison_parse($dakls);
347 sub canonicalise_suite_sshdakls ($$) {
348 my ($proto,$data) = @_;
349 $data =~ m/:/ or badcfg "invalid sshdakls method string \`$data'";
351 (access_cfg('ssh'), $`,
353 " if test -h $isuite; then readlink $isuite; exit 0; fi;".
354 " if test -d $isuite; then echo $isuite; exit 0; fi;".
356 my $dakls = cmdoutput @cmd;
357 failedcmd @cmd unless $dakls =~ m/^\w/;
361 sub madison_parse ($) {
366 $rmad =~ m{^ \s*( [^ \t|]+ )\s* \|
367 \s*( [^ \t|]+ )\s* \|
368 \s*( [^ \t|/]+ )(?:/([^ \t|/]+))? \s* \|
369 \s*( [^ \t|]+ )\s* }x or die "$rmad $?";
370 $1 eq $package or die "$rmad $package ?";
377 $component = access_cfg('archive-query-default-component');
379 $5 eq 'source' or die "$rmad ?";
380 my $prefix = substr($package, 0, $package =~ m/^l/ ? 4 : 1);
381 my $subpath = "/pool/$component/$prefix/$package/${package}_$vsn.dsc";
382 return ($vsn,$subpath,$newsuite);
385 sub canonicalise_suite_madison ($$) {
386 my @r = archive_query_madison($_[0],$_[1]);
388 "unable to canonicalise suite using package $package".
389 " which does not appear to exist in suite $isuite;".
390 " --existing-package may help";
394 sub canonicalise_suite () {
395 $csuite = archive_query('canonicalise_suite');
396 if ($isuite ne $csuite) {
397 # madison canonicalises for us
398 print "canonical suite name for $isuite is $csuite\n";
402 sub get_archive_dsc () {
403 my ($vsn,$subpath) = archive_query('archive_query');
404 canonicalise_suite();
405 if (!defined $vsn) { $dsc=undef; return undef; }
406 $dscurl = access_cfg('mirror').$subpath;
407 $dscdata = url_get($dscurl);
408 my $dscfh = new IO::File \$dscdata, '<' or die $!;
409 print DEBUG Dumper($dscdata) if $debug>1;
410 $dsc = parsecontrolfh($dscfh,$dscurl, allow_pgp=>1);
411 print DEBUG Dumper($dsc) if $debug>1;
412 my $fmt = getfield $dsc, 'Format';
413 fail "unsupported source format $fmt, sorry" unless $format_ok{$fmt};
416 sub check_for_git () {
418 my $how = access_cfg('git-check');
419 if ($how eq 'ssh-cmd') {
421 (access_cfg('ssh'),access_gituserhost(),
422 " set -e; cd ".access_cfg('git-path').";".
423 " if test -d $package.git; then echo 1; else echo 0; fi");
424 my $r= cmdoutput @cmd;
425 failedcmd @cmd unless $r =~ m/^[01]$/;
428 badcfg "unknown git-check \`$how'";
432 sub create_remote_git_repo () {
433 my $how = access_cfg('git-create');
434 if ($how eq 'ssh-cmd') {
436 (access_cfg('ssh'),access_gituserhost(),
437 "set -e; cd ".access_cfg('git-path').";".
438 " mkdir -p $package.git;".
440 " if ! test -d objects; then git init --bare; fi");
442 badcfg "unknown git-create \`$how'";
446 our ($dsc_hash,$upload_hash);
448 our $ud = '.git/dgit/unpack';
456 sub mktree_in_ud_from_only_subdir () {
457 # changes into the subdir
460 $dirs[0] =~ m#^([^/]+)/\.$# or die;
462 chdir $dir or die "$dir $!";
464 die $! unless $!==&ENOENT;
465 runcmd qw(git init -q);
466 rmtree('.git/objects');
467 symlink '../../../../objects','.git/objects' or die $!;
468 runcmd @git, qw(add -Af);
469 my $tree = cmdoutput @git, qw(write-tree);
470 $tree =~ m/^\w+$/ or die "$tree ?";
475 my $field = $dsc->{'Checksums-Sha256'} || $dsc->{Files};
476 fail "missing both Checksums-Sha256 and Files in ".$dsc->get_option('name');
478 m/^\w+ \d+ (\S+)$/ or
479 fail "could not parse .dsc Files/Checksums line \`$_'";
481 } grep m/\S/, split /\n/, $field;
484 sub is_orig_file ($) {
486 m/\.orig(?:-\w+)?\.tar\.\w+$/;
489 sub make_commit ($) {
491 return cmdoutput @git, qw(hash-object -w -t commit), $file;
494 sub generate_commit_from_dsc () {
498 foreach my $f (dsc_files()) {
499 die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#;
501 link "../../../$f", $f
505 runcmd @dget, qw(--), $dscurl;
506 foreach my $f (grep { is_orig_file($_) } @files) {
507 link $f, "../../../../$f"
511 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
512 runcmd qw(sh -ec), 'dpkg-parsechangelog >../changelog.tmp';
513 my $clogp = parsecontrol('../changelog.tmp',"commit's changelog");
514 my $date = cmdoutput qw(date), '+%s %z', qw(-d), getfield($clogp,'Date');
515 my $author = getfield $clogp, 'Maintainer';
516 $author =~ s#,.*##ms;
517 my $authline = "$author $date";
518 $authline =~ m/^[^<>]+ \<\S+\> \d+ [-+]\d+$/ or
519 fail "unexpected commit author line format \`$authline'".
520 " (was generated from changelog Maintainer field)";
521 my $changes = getfield $clogp, 'Changes';
522 open C, ">../commit.tmp" or die $!;
523 print C <<END or die $!;
530 # imported from the archive
533 my $outputhash = make_commit qw(../commit.tmp);
534 my $cversion = getfield $clogp, 'Version';
535 print "synthesised git commit from .dsc $cversion\n";
537 runcmd @git, qw(reset --hard), $upload_hash;
538 runcmd qw(sh -ec), 'dpkg-parsechangelog >>../changelogold.tmp';
539 my $oldclogp = parsecontrol('../changelogold.tmp','previous changelog');
540 my $oversion = getfield $oldclogp, 'Version';
542 version_compare_string($oversion, $cversion);
544 # git upload/ is earlier vsn than archive, use archive
545 open C, ">../commit2.tmp" or die $!;
546 print C <<END or die $!;
553 Record $package ($cversion) in archive suite $csuite
555 $outputhash = make_commit qw(../commit2.tmp);
556 } elsif ($vcmp > 0) {
557 print STDERR <<END or die $!;
558 Version actually in archive: $cversion (older)
559 Last allegedly pushed/uploaded: $oversion (newer or same)
560 Perhaps the upload is stuck in incoming. Using the version from git.
562 $outputhash = $upload_hash;
563 } elsif ($outputhash ne $upload_hash) {
564 fail "version in archive ($cversion)".
565 " is same as version in git".
566 " to-be-uploaded (upload/) branch ($oversion)".
567 " but archive version hash no commit hash?!";
570 chdir '../../../..' or die $!;
571 runcmd @git, qw(update-ref -m),"dgit fetch import $cversion",
572 'DGIT_ARCHIVE', $outputhash;
573 cmdoutput @git, qw(log -n2), $outputhash;
574 # ... gives git a chance to complain if our commit is malformed
579 sub ensure_we_have_orig () {
580 foreach my $f (dsc_files()) {
581 next unless is_orig_file($f);
583 die "$f ?" unless -f _;
585 die "$f $!" unless $!==&ENOENT;
587 my $origurl = $dscurl;
588 $origurl =~ s{/[^/]+$}{};
590 die "$f ?" unless $f =~ m/^${package}_/;
591 die "$f ?" if $f =~ m#/#;
592 runcmd_ordryrun qw(sh -ec),'cd ..; exec "$@"','x',
598 return cmdoutput @git, qw(rev-parse), "$_[0]~0";
601 sub is_fast_fwd ($$) {
602 my ($ancestor,$child) = @_;
603 my $mb = cmdoutput @git, qw(merge-base), $ancestor, $child;
604 return rev_parse($mb) eq rev_parse($ancestor);
607 sub git_fetch_us () {
608 badusage "cannot dry run with fetch" if $dryrun;
609 runcmd @git, qw(fetch),access_giturl(),fetchspec();
612 sub fetch_from_archive () {
613 # ensures that lrref() is what is actually in the archive,
615 get_archive_dsc() or return 0;
616 $dsc_hash = $dsc->{$ourdscfield};
617 if (defined $dsc_hash) {
618 $dsc_hash =~ m/\w+/ or fail "invalid hash in .dsc \`$dsc_hash'";
620 print "last upload to archive specified git hash\n";
622 print "last upload to archive has NO git hash\n";
625 my $lrref_fn = ".git/".lrref();
626 if (open H, $lrref_fn) {
629 die "$lrref_fn $upload_hash ?" unless $upload_hash =~ m/^\w+$/;
630 } elsif ($! == &ENOENT) {
635 print DEBUG "previous reference hash $upload_hash\n";
637 if (defined $dsc_hash) {
638 fail "missing git history even though dsc has hash -".
639 " could not find commit $dsc_hash".
640 " (should be in ".access_giturl()."#".rref().")"
643 ensure_we_have_orig();
645 $hash = generate_commit_from_dsc();
647 print DEBUG "current hash $hash\n";
649 fail "not fast forward on last upload branch!".
650 " (archive's version left in DGIT_ARCHIVE)"
651 unless is_fast_fwd($upload_hash, $hash);
653 if ($upload_hash ne $hash) {
654 my @upd_cmd = (@git, qw(update-ref -m), 'dgit fetch', lrref(), $hash);
658 dryrun_report @upd_cmd;
666 canonicalise_suite();
667 badusage "dry run makes no sense with clone" if $dryrun;
668 mkdir $dstdir or die "$dstdir $!";
669 chdir "$dstdir" or die "$dstdir $!";
670 runcmd @git, qw(init -q);
671 runcmd @git, qw(config), "remote.$remotename.fetch", fetchspec();
672 open H, "> .git/HEAD" or die $!;
673 print H "ref: ".lref()."\n" or die $!;
675 runcmd @git, qw(remote add), 'origin', access_giturl();
676 if (check_for_git()) {
677 print "fetching existing git history\n";
679 runcmd @git, qw(fetch origin);
681 print "starting new git history\n";
683 fetch_from_archive() or no_such_package;
684 runcmd @git, qw(reset --hard), lrref();
685 printdone "ready for work in $dstdir";
689 if (check_for_git()) {
692 fetch_from_archive() or no_such_package();
693 printdone "fetched into ".lrref();
698 runcmd_ordryrun @git, qw(merge -m),"Merge from $csuite [dgit]",
700 printdone "fetched to ".lrref()." and merged into HEAD";
703 sub check_not_dirty () {
704 runcmd @git, qw(diff --quiet HEAD);
707 sub commit_quilty_patch ($) {
709 my $output = cmdoutput @git, qw(status --porcelain);
710 my %fixups = map {$_=>1}
711 (".pc/debian-changes-$vsn/","debian/patches/debian-changes-$vsn");
713 foreach my $l (split /\n/, $output) {
714 next unless $l =~ s/^\?\? //;
715 next unless $fixups{$l};
718 print DEBUG "checking for quilty\n", Dumper(\@files);
720 my $m = "Commit Debian 3.0 (quilt) metadata";
722 runcmd_ordryrun @git, qw(add), @files;
723 runcmd_ordryrun @git, qw(commit -m), $m;
728 print DEBUG "actually entering push\n";
729 my $clogp = parsechangelog();
730 $package = getfield $clogp, 'Source';
731 my $cversion = getfield $clogp, 'Version';
732 my $dscfn = dscfn($cversion);
734 fail "looked for .dsc $dscfn, but $!;".
735 " maybe you forgot to build";
736 $dsc = parsecontrol("../$dscfn","$dscfn");
737 my $dscpackage = getfield $dsc, 'Source';
738 my $format = getfield $dsc, 'Format';
739 my $dversion = getfield $dsc, 'Version';
740 ($dscpackage eq $package && $dversion eq $cversion) or
741 fail "$dsc is for $dscpackage $dversion".
742 " but debian/changelog is for $package $cversion";
743 print DEBUG "format $format\n";
744 if ($format eq '3.0 (quilt)') {
745 print "Format \`$format', urgh\n";
746 commit_quilty_patch($dversion);
751 print "checking that $dscfn corresponds to HEAD\n";
752 runcmd qw(dpkg-source -x --), "../../../../$dscfn";
753 my ($tree,$dir) = mktree_in_ud_from_only_subdir();
754 chdir '../../../..' or die $!;
755 printcmd \*DEBUG,"+",@_;
756 my @diffcmd = (@git, qw(diff --exit-code), $tree);
758 if (system @diffcmd) {
760 fail "$dscfn specifies a different tree to your HEAD commit;".
761 " perhaps you forgot to build";
767 #do fast forward check and maybe fake merge
768 # if (!is_fast_fwd(mainbranch
769 # runcmd @git, qw(fetch -p ), "$alioth_git/$package.git",
770 # map { lref($_).":".rref($_) }
772 $dsc->{$ourdscfield} = rev_parse('HEAD');
773 $dsc->save("../$dscfn.tmp") or die $!;
775 my $multi = "${package}_${cversion}_multi.changes";
777 $changesfile = $multi;
779 $!==&ENOENT or die "$multi: $!";
780 my $pat = "${package}_${cversion}_*.changes";
781 my @cs = glob "../$pat";
782 fail "failed to find unique changes file".
783 " (looked for $pat in ..); perhaps you need to use dgit -C"
785 ($changesfile) = @cs;
788 my $tag = debiantag($dversion);
789 if (!check_for_git()) {
790 create_remote_git_repo();
792 runcmd_ordryrun @git, qw(push),access_giturl(),"HEAD:".rrref();
794 rename "../$dscfn.tmp","../$dscfn" or die "$dscfn $!";
796 print "[new .dsc left in $dscfn.tmp]\n";
799 my @tag_cmd = (@git, qw(tag -s -m),
800 "Release $dversion for $csuite [dgit]");
801 push @tag_cmd, qw(-u),$keyid if defined $keyid;
803 runcmd_ordryrun @tag_cmd;
804 my @debsign_cmd = @debsign;
805 push @debsign_cmd, "-k$keyid" if defined $keyid;
806 push @debsign_cmd, $changesfile;
807 runcmd_ordryrun @debsign_cmd;
809 runcmd_ordryrun @git, qw(push),access_giturl(),"refs/tags/$tag";
810 my $host = access_cfg('upload-host','RETURN-UNDEF');
811 my @hostarg = defined($host) ? ($host,) : ();
812 runcmd_ordryrun @dput, @hostarg, $changesfile;
813 printdone "pushed and uploaded $dversion";
819 badusage "-p is not allowed with clone; specify as argument instead"
823 } elsif (@ARGV==2 && $ARGV[1] =~ m#^\w#) {
824 ($package,$isuite) = @ARGV;
825 } elsif (@ARGV==2 && $ARGV[1] =~ m#^[./]#) {
826 ($package,$dstdir) = @ARGV;
828 ($package,$isuite,$dstdir) = @ARGV;
830 badusage "incorrect arguments to dgit clone";
832 $dstdir ||= "$package";
837 my $branch = cmdoutput_errok @git, qw(symbolic-ref HEAD);
838 if ($branch =~ m#$lbranch_re#o) {
845 sub fetchpullargs () {
846 if (!defined $package) {
847 my $sourcep = parsecontrol('debian/control','debian/control');
848 $package = getfield $sourcep, 'Source';
851 # $isuite = branchsuite(); # this doesn't work because dak hates canons
853 my $clogp = parsechangelog();
854 $isuite = getfield $clogp, 'Distribution';
856 canonicalise_suite();
857 print "fetching from suite $csuite\n";
860 canonicalise_suite();
862 badusage "incorrect arguments to dgit fetch or dgit pull";
880 badusage "-p is not allowed with dgit push" if defined $package;
881 runcmd @git, qw(diff --quiet HEAD);
882 my $clogp = parsechangelog();
883 $package = getfield $clogp, 'Source';
885 $isuite = getfield $clogp, 'Distribution';
887 local ($package) = $existing_package; # this is a hack
888 canonicalise_suite();
891 badusage "incorrect arguments to dgit push";
893 if (fetch_from_archive()) {
894 is_fast_fwd(lrref(), 'HEAD') or die;
896 fail "package appears to be new in this suite;".
897 " if this is intentional, use --new";
903 # we pass further options and args to git-buildpackage
904 badusage "-p is not allowed with dgit build" if defined $package;
905 my $clogp = parsechangelog();
906 $isuite = getfield $clogp, 'Distribution';
907 $package = getfield $clogp, 'Source';
909 (qw(git-buildpackage -us -uc --git-no-sign-tags),
910 "--git-builder=@dpkgbuildpackage");
911 unless (grep { m/^--git-debian-branch/ } @ARGV) {
912 canonicalise_suite();
913 push @cmd, "--git-debian-branch=".lbranch();
915 runcmd_ordryrun @cmd, @ARGV;
916 print "build successful\n";
921 badusage "-p is not allowed with dgit sbuild" if defined $package;
922 my $clogp = parsechangelog();
923 $package = getfield $clogp, 'Source';
924 my $version = getfield $clogp, 'Version';
925 runcmd (@dpkgbuildpackage, qw(-us -uc -S));
926 chdir ".." or die $!;
927 my $sourcechanges = "${package}_${version}_source.changes";
928 my $dscfn = dscfn($version);
929 stat "../$dscfn" or fail "$dscfn (in parent directory): $!";
930 stat "../$sourcechanges" or fail "$sourcechanges (in parent directory): $!";
931 my $pat = "${package}_${version}_*.changes";
932 foreach my $cf (glob $pat) {
933 next if $cf eq $sourcechanges;
934 unlink $cf or fail "remove $cf: $!";
936 runcmd @sbuild, @ARGV, $sourcechanges;
937 runcmd @mergechanges, glob $pat;
938 my $multichanges = "${package}_${version}_multi.changes";
939 stat $multichanges or fail "$multichanges: $!";
940 print "build successful, results in $multichanges\n" or die $!;
943 sub cmd_quilt_fixup {
944 badusage "incorrect arguments to dgit quilt-fixup";
945 my $clogp = parsechangelog();
946 commit_quilty_patch((getfield $clogp, 'Version'));
952 last unless $ARGV[0] =~ m/^-/;
956 if (m/^--dry-run$/) {
958 } elsif (m/^--no-sign$/) {
960 } elsif (m/^--help$/) {
962 } elsif (m/^--new$/) {
964 } elsif (m/^--(\w+)=(.*)/s && ($om = $opts_opt_map{$1})) {
966 } elsif (m/^--(\w+):(.*)/s && ($om = $opts_opt_map{$1})) {
968 } elsif (m/^--existing-package=(.*)/s) {
969 $existing_package = $1;
971 badusage "unknown long option \`$_'";
980 open DEBUG, ">&STDERR" or die $!;
984 } elsif (s/^-c(.*=.*)//s) {
986 } elsif (s/^-C(.*)//s) {
988 } elsif (s/^-k(.*)//s) {
991 badusage "unknown short option \`$_'";
999 print STDERR "DRY RUN ONLY\n" if $dryrun;
1001 print STDERR $helpmsg or die $!;
1004 my $cmd = shift @ARGV;
1006 { no strict qw(refs); &{"cmd_$cmd"}(); }