chiark / gitweb /
git-debrebase: Provide status subcommand
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Jun 2018 19:42:22 +0000 (20:42 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Jun 2018 21:40:14 +0000 (22:40 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
git-debrebase
git-debrebase.1.pod

index c180a2946c28c50c10f806c54b7e7d922b99449f..634ed763b1989edd2c9607b0cccdbcffae8b8019 100755 (executable)
@@ -1369,6 +1369,83 @@ sub cmd_breakwater () {
     print "$bw\n" or die $!;
 }
 
+sub cmd_status () {
+    badusage "no arguments allowed" if @ARGV;
+
+    my $oldest = [ 0 ];
+    my $newest;
+    my $note = sub {
+       my ($badness, $ourmsg, $snagname, $kcmsg, $cl) = @_;
+       if ($oldest->[0] < $badness) {
+           $oldest = $newest = undef;
+       }
+       $oldest = \@_; # we're walking backwards
+       $newest //= \@_;
+    };
+    my ($anchor, $bw) = keycommits +(git_rev_parse 'HEAD'),
+       sub { $note->(1, 'branch contains furniture (not laundered)', @_); },
+       sub { $note->(2, 'branch is unlaundered', @_); },
+       sub { $note->(3, 'branch needs laundering', @_); },
+       sub { $note->(4, 'branch not in git-debrebase form', @_); };
+
+    my $prcommitinfo = sub {
+       my ($cid) = @_;
+       flush STDOUT or die $!;
+       runcmd @git, qw(--no-pager log -n1),
+           '--pretty=format:    %h %s%n',
+           $cid;
+    };
+
+    print "current branch contents, in git-debrebase terms:\n";
+    if (!$oldest->[0]) {
+       print "  branch is laundered\n";
+    } else {
+       print "  $oldest->[1]\n";
+       my $printed = '';
+       foreach my $info ($oldest, $newest) {
+           my $cid = $info->[4]{CommitId};
+           next if $cid eq $printed;
+           $printed = $cid;
+           print "  $info->[3]\n";
+           $prcommitinfo->($cid);
+       }
+    }
+
+    my $prab = sub {
+       my ($cid, $what) = @_;
+       if (!defined $cid) {
+           print "  $what is not well-defined\n";
+       } else {
+           print "  $what\n";
+           $prcommitinfo->($cid);
+       }
+    };
+    print "key git-debrebase commits:\n";
+    $prab->($anchor, 'anchor');
+    $prab->($bw, 'breakwater');
+
+    my ($ffqstatus, $ffq_msg, $current, $ffq_prev, $gdrlast) =
+       ffq_prev_branchinfo();
+
+    print "branch and ref status, in git-debrebase terms:\n";
+    if ($ffq_msg) {
+       print "  $ffq_msg\n";
+    } else {
+       $ffq_prev = git_get_ref $ffq_prev;
+       $gdrlast = git_get_ref $gdrlast;
+       if ($ffq_prev) {
+           print "  unstitched; previous tip was:\n";
+           $prcommitinfo->($ffq_prev);
+       } elsif (!$gdrlast) {
+           print "  stitched? (no record of git-debrebase work)\n";
+       } elsif (is_fast_fwd $gdrlast, 'HEAD') {
+           print "  stitched\n";
+       } else {
+           print "  not git-debrebase (diverged since last stitch)\n"
+       }
+    }
+}
+
 sub cmd_stitch () {
     my $prose = 'stitch';
     GetOptions('prose=s', \$prose) or die badusage("bad options to stitch");
index 5da532029049951d43682eed5671df153e3e75e1..27b5c9337596e0235957bfbda32f5ad36a4edf07 100644 (file)
@@ -55,6 +55,19 @@ The options for git-rebase must either start with C<-i>,
 or be prececded by C<-->,
 to distinguish them from options for git-debrebase.
 
+=item git-debrebase status
+
+Analyise the current branch,
+both in terms of its conents,
+and the refs which are relevant to git-debrebase,
+and print a human-readable summary.
+
+Please do not attempt to parse the output;
+it may be reformatted or reorganised in the future.
+Instead,
+use one of the L<UNDERLYING AND SUPPLEMENTARY OPERATIONS>
+described below.
+
 =item git-debrebase conclude
 
 Finishes a git-debrebase session,