chiark / gitweb /
Test suite: Print better info on t-ref-same failure
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 835366eaed8a5efd42878ce52c261f73e56397b9..b8f00c39e70564da68a060fe48c829c8ab9d7734 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -213,6 +213,16 @@ sub quiltmode_splitbrain () {
 #  where <rargs> is <push-host-dir> <supported-proto-vsn>,... ...
 #  < dgit-remote-push-ready <actual-proto-vsn>
 #
+# occasionally:
+#
+#  > progress NBYTES
+#  [NBYTES message]
+#
+#  > supplementary-message NBYTES          # $protovsn >= 3
+#  [NBYTES message]
+#
+# main sequence:
+#
 #  > file parsed-changelog
 #  [indicates that output of dpkg-parsechangelog follows]
 #  > data-block NBYTES
@@ -227,6 +237,10 @@ sub quiltmode_splitbrain () {
 #  [etc]
 #
 #  > param head HEAD
+#  > param csuite SUITE
+#
+#  > previously REFNAME=OBJNAME       # if --deliberately-not-fast-forward
+#                                     # goes into tag, for replay prevention
 #
 #  > want signed-tag
 #  [indicates that signed tag is wanted]
@@ -398,7 +412,7 @@ our ($dscdata,$dscurl,$dsc,$dsc_checked,$skew_warning_vsn);
 
 sub runcmd {
     debugcmd "+",@_;
-    $!=0; $?=0;
+    $!=0; $?=-1;
     failedcmd @_ if system @_;
 }
 
@@ -533,7 +547,7 @@ sub git_slurp_config () {
     my @cmd = (@git, qw(config -z --get-regexp .*));
     debugcmd "|",@cmd;
 
-    open GITS, "-|", @cmd or failedcmd @cmd;
+    open GITS, "-|", @cmd or die $!;
     while (<GITS>) {
        chomp or die;
        printdebug "=> ", (messagequote $_), "\n";
@@ -1160,7 +1174,7 @@ sub check_for_git () {
             " set -e; cd ".access_cfg('git-path').";".
             " if test -d $package.git; then echo 1; else echo 0; fi");
        my $r= cmdoutput @cmd;
-       if ($r =~ m/^divert (\w+)$/) {
+       if (defined $r and $r =~ m/^divert (\w+)$/) {
            my $divert=$1;
            my ($usedistro,) = access_distros();
            # NB that if we are pushing, $usedistro will be $distro/push
@@ -1169,7 +1183,7 @@ sub check_for_git () {
            progress "diverting to $divert (using config for $instead_distro)";
            return check_for_git();
        }
-       failedcmd @cmd unless $r =~ m/^[01]$/;
+       failedcmd @cmd unless defined $r and $r =~ m/^[01]$/;
        return $r+0;
     } elsif ($how eq 'url') {
        my $prefix = access_cfg('git-check-url','git-url');
@@ -1243,7 +1257,7 @@ sub git_write_tree () {
 sub remove_stray_gits () {
     my @gitscmd = qw(find -name .git -prune -print0);
     debugcmd "|",@gitscmd;
-    open GITS, "-|", @gitscmd or failedcmd @gitscmd;
+    open GITS, "-|", @gitscmd or die $!;
     {
        local $/="\0";
        while (<GITS>) {
@@ -1259,7 +1273,7 @@ sub remove_stray_gits () {
 sub mktree_in_ud_from_only_subdir () {
     # changes into the subdir
     my (@dirs) = <*/.>;
-    die unless @dirs==1;
+    die "@dirs ?" unless @dirs==1;
     $dirs[0] =~ m#^([^/]+)/\.$# or die;
     my $dir = $1;
     changedir $dir;
@@ -1782,9 +1796,9 @@ sub check_not_dirty () {
 
     my @cmd = (@git, qw(diff --quiet HEAD));
     debugcmd "+",@cmd;
-    $!=0; $?=0; system @cmd;
-    return if !$! && !$?;
-    if (!$! && $?==256) {
+    $!=0; $?=-1; system @cmd;
+    return if !$?;
+    if ($?==256) {
        fail "working tree is dirty (does not match HEAD)";
     } else {
        failedcmd @cmd;
@@ -1995,9 +2009,26 @@ END
     my $format = getfield $dsc, 'Format';
     printdebug "format $format\n";
 
+    my $head = git_rev_parse('HEAD');
+
     if (madformat($format)) {
        # user might have not used dgit build, so maybe do this now:
-       commit_quilty_patch();
+       if (quiltmode_splitbrain()) {
+           my $upstreamversion = $clogp->{Version};
+           $upstreamversion =~ s/-[^-]*$//;
+           changedir $ud;
+           quilt_make_fake_dsc($upstreamversion);
+           my ($dgitview, $cachekey) =
+               quilt_check_splitbrain_cache($head, $upstreamversion);
+           $dgitview or fail
+ "--quilt=$quilt_mode but no cached dgit view:
+ perhaps tree changed since dgit build[-source] ?";
+           $split_brain = 1;
+           changedir '../../../..';
+           prep_ud(); # so _only_subdir() works, below
+       } else {
+           commit_quilty_patch();
+       }
     }
 
     die 'xxx fast forward (should not depend on quilt mode, but will always be needed if we did $split_brain)' if $split_brain;
@@ -2013,7 +2044,7 @@ END
     my $diffopt = $debuglevel>0 ? '--exit-code' : '--quiet';
     my @diffcmd = (@git, qw(diff), $diffopt, $tree);
     debugcmd "+",@diffcmd;
-    $!=0; $?=0;
+    $!=0; $?=-1;
     my $r = system @diffcmd;
     if ($r) {
        if ($r==256) {
@@ -2025,7 +2056,6 @@ END
            failedcmd @diffcmd;
        }
     }
-    my $head = git_rev_parse('HEAD');
     if (!$changesfile) {
        my $pat = changespat $cversion;
        my @cs = glob "$buildproductsdir/$pat";
@@ -2994,20 +3024,15 @@ END
 
 sub quilt_check_splitbrain_cache ($$) {
     my ($headref, $upstreamversion) = @_;
-    # Checks to see if we are in (potentially) split brain mode.
-    # If so, computes the cache key and looks in the cache.
-    # If split brain is not applicable, returns (undef,0).
-    # Otherwise returns ($cachekey,HIT) where
-    # HIT=0: miss; HIT=1: hit, needs different commit; HIT=2: same commit OK
-
-    quilt_make_fake_dsc($upstreamversion);
-
-    return (undef,0) unless quiltmode_splitbrain();
+    # Called only if we are in (potentially) split brain mode.
+    # Called in $ud.
+    # Computes the cache key and looks in the cache.
+    # Returns ($dgit_view_commitid, $cachekey) or (undef, $cachekey)
 
     my $splitbrain_cachekey;
     
     progress
- "dgit: split brain (separate dgit view) may needed (--quilt=$quilt_mode).";
+ "dgit: split brain (separate dgit view) may be needed (--quilt=$quilt_mode).";
     # we look in the reflog of dgit-intern/quilt-cache
     # we look for an entry whose message is the key for the cache lookup
     my @cachekey = (qw(dgit), $our_version);
@@ -3020,6 +3045,7 @@ sub quilt_check_splitbrain_cache ($$) {
     my $srcshash = Digest::SHA->new(256);
     my %sfs = ( %INC, '$0(dgit)' => $0 );
     foreach my $sfk (sort keys %sfs) {
+       next unless m/^\$0\b/ || m{^Debian/Dgit\b};
        $srcshash->add($sfk,"  ");
        $srcshash->add(hashfile($sfs{$sfk}));
        $srcshash->add("\n");
@@ -3052,16 +3078,16 @@ sub quilt_check_splitbrain_cache ($$) {
            progress "dgit view: found cached (commit id $cachehit)";
            runcmd @git, qw(checkout -q -b dgit-view), $cachehit;
            $split_brain = 1;
-           return ($splitbrain_cachekey, 1);
+           return ($cachehit, $splitbrain_cachekey);
        }
        progress "dgit view: found cached, no changes required";
-       return ($splitbrain_cachekey, 2);
+       return ($headref, $splitbrain_cachekey);
     }
     die $! if GC->error;
     failedcmd unless close GC;
 
     printdebug "splitbrain cache miss\n";
-    return ($splitbrain_cachekey, 0);
+    return (undef, $splitbrain_cachekey);
 }
 
 sub quilt_fixup_multipatch ($$$) {
@@ -3138,10 +3164,16 @@ sub quilt_fixup_multipatch ($$$) {
     # afterwards with dpkg-source --before-build.  That lets us save a
     # tree object corresponding to .origs.
 
-    my ($splitbrain_cachekey,$cachehit) =
-       quilt_check_splitbrain_cache($headref, $upstreamversion);
+    my $splitbrain_cachekey;
+
+    quilt_make_fake_dsc($upstreamversion);
 
-    return if $splitbrain_cachekey && $cachehit;
+    if (quiltmode_splitbrain()) {
+       my $cachehit;
+       ($cachehit, $splitbrain_cachekey) =
+           quilt_check_splitbrain_cache($headref, $upstreamversion);
+       return if $cachehit;
+    }
 
     runcmd qw(sh -ec),
         'exec dpkg-source --no-check --skip-patches -x fake.dsc >/dev/null';