chiark / gitweb /
git-debrebase: Defend against missing snags_maybe_bail calls
[dgit.git] / git-debrebase
index 5aaa6601965a09c9e494c09b9ef3b47603cc635c..6211fb633d85ecee3fcb2f6173dde3f9184d0a1f 100755 (executable)
@@ -99,12 +99,18 @@ sub fresh_workarea () {
     in_workarea sub { playtree_setup };
 }
 
+our $snags_forced;
+our $snags_tripped;
+our $snags_checked;
 our @deferred_updates;
 our @deferred_update_messages;
 
 sub run_deferred_updates ($) {
     my ($mrest) = @_;
 
+    confess 'dangerous internal error' if
+       !$snags_checked || $snags_tripped || $snags_forced;
+
     my @upd_cmd = (@git, qw(update-ref --stdin -m), "debrebase: $mrest");
     debugcmd '>|', @upd_cmd;
     open U, "|-", @upd_cmd or die $!;
@@ -227,8 +233,6 @@ sub make_commit ($$) {
 }
 
 our @snag_force_opts;
-our $snags_forced;
-our $snags_tripped;
 sub snag ($$) {
     my ($tag,$msg) = @_;
     if (grep { $_ eq $tag } @snag_force_opts) {
@@ -241,16 +245,19 @@ sub snag ($$) {
 }
 
 sub snags_maybe_bail () {
+    $snags_checked++;
     if ($snags_forced) {
        printf STDERR
            "%s: snags: %d overriden by individual -f options\n",
            $us, $snags_forced;
+       $snags_forced=0;
     }
     if ($snags_tripped) {
        if ($opt_force) {
            printf STDERR
                "%s: snags: %d overriden by global --force\n",
                $us, $snags_tripped;
+           $snags_tripped=0;
        } else {
            fail sprintf
   "%s: snags: %d blockers (you could -f<tag>, or --force)",
@@ -560,7 +567,7 @@ sub keycommits ($;$$$) {
            $breakwater = undef;
        } elsif ($ty eq 'Mixed') {
            $x->($unclean, 'mixed',
-                'found mixed upstream/packaging commit ($head)');
+                "found mixed upstream/packaging commit ($head)");
            $clogonly = undef;
            $breakwater = undef;
        } elsif ($ty eq 'Pseudomerge' or
@@ -901,6 +908,7 @@ sub do_launder_head ($) {
     my $old = get_head();
     record_ffq_auto();
     my ($tip,$breakwater) = walk $old;
+    snags_maybe_bail();
     update_head_postlaunder $old, $tip, $reflogmsg;
     return ($tip,$breakwater);
 }
@@ -1094,6 +1102,7 @@ sub do_stitch ($;$) {
     my $dangling_head = get_head();
 
     keycommits $dangling_head, $unclean,$unclean,$unclean;
+    snags_maybe_bail();
 
     stitch($dangling_head, $ffq_prev, $gdrlast, $ffq_prev_commitish, $prose);
 }
@@ -1316,7 +1325,7 @@ sub cmd_stitch () {
     my $prose = 'stitch';
     GetOptions('prose=s', \$prose) or die badusage("bad options to stitch");
     badusage "no arguments allowed" if @ARGV;
-    do_stitch $prose, \&snag;
+    do_stitch $prose, 0;
 }
 sub cmd_prepush () { cmd_stitch(); }
 
@@ -1429,6 +1438,7 @@ sub cmd_convert_to_gbp () {
        push @deferred_updates, "delete $ffq";
        push @deferred_updates, "delete $gdrlast";
     }
+    snags_maybe_bail();
     update_head_checkout $head, $out, "convert to gbp (v0)";
     print <<END or die $!;
 git-debrebase: converted to git-buildpackage branch format