summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2018-06-16 20:42:22 +0100
committerIan Jackson <ijackson@chiark.greenend.org.uk>2018-06-16 22:40:14 +0100
commit77f1c1c558d5492e70c6121a6a8cda3f658cd9ca (patch)
tree3a0749c3600bda6d40edea085b36f9407d3fcc39
parent39e84f67e266f87368e4bce44d4b4b469ef7165a (diff)
git-debrebase: Provide status subcommand
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
-rwxr-xr-xgit-debrebase77
-rw-r--r--git-debrebase.1.pod13
2 files changed, 90 insertions, 0 deletions
diff --git a/git-debrebase b/git-debrebase
index c180a29..634ed76 100755
--- a/git-debrebase
+++ b/git-debrebase
@@ -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");
diff --git a/git-debrebase.1.pod b/git-debrebase.1.pod
index 5da5320..27b5c93 100644
--- a/git-debrebase.1.pod
+++ b/git-debrebase.1.pod
@@ -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,