chiark / gitweb /
git-debrebase: wip stitch
[dgit.git] / git-debrebase
index 50fa1bc96cfb22e169f9c27406b165047e5b1152..5fcec5461a2e51143de9818b50ad09aa6e0516db 100755 (executable)
@@ -29,6 +29,7 @@
 #    git-debrebase [<options> --] [<git-rebase options...>]
 #    git-debrebase [<options>] analyse
 #    git-debrebase [<options>] launder         # prints breakwater tip etc.
+#    git-debrebase [<options>] stitch [--prose=<for commit message>]
 #    git-debrebase [<options>] downstream-rebase-launder-v0  # experimental
 #
 #    git-debrebase [<options>] gbp2debrebase-v0 \
@@ -100,7 +101,7 @@ sub badusage ($) {
 
 sub cfg ($;$) {
     my ($k, $optional) = @_;
-    $/ = "\0";
+    local $/ = "\0";
     my @cmd = qw(git config -z);
     push @cmd, qw(--get-all) if wantarray;
     push @cmd, $k;
@@ -832,6 +833,12 @@ sub cmd_launder () {
 
 sub defaultcmd_rebase () {
     my $old = get_head();
+    my ($status, $message) = record_ffq_prev();
+    if ($status eq 'written' || $status eq 'exists') {
+    } else {
+       fproblem $status, "could not record ffq-prev: $message";
+       fproblems_maybe_bail();
+    }
     my ($tip,$breakwater) = walk $old;
     update_head_postlaunder $old, $tip, 'launder for rebase';
     runcmd @git, qw(rebase), @ARGV, $breakwater;
@@ -850,6 +857,20 @@ sub cmd_analyse () {
     STDOUT->error and die $!;
 }
 
+sub ffq_prev_branchinfo () {
+    # => ('status', "message", [$current, $ffq_prev])
+    # 'status' may be
+    #    branch         message is undef
+    #    weird-symref   } no $current,
+    #    notbranch      }  no $ffq_prev
+    my $current = git_get_symref();
+    return ('detached', 'detached HEAD') unless defined $current;
+    return ('weird-symref', 'HEAD symref is not to refs/')
+       unless $current =~ m{^refs/};
+    my $ffq_prev = "refs/$ffq_refprefix/$'";
+    return ('branch', undef, $current, $ffq_prev);
+}
+
 sub record_ffq_prev () {
     # => ('status', "message")
     # 'status' may be
@@ -861,11 +882,8 @@ sub record_ffq_prev () {
     # if not ff from some branch we should be ff from, is an fproblem
     # if "written", will have printed something about that to stdout,
     #   and also some messages about ff checks
-    my $current = git_get_symref();
-    return ('detached', 'detached HEAD') unless defined $current;
-    return ('weird-symref', 'HEAD symref is not to refs/')
-       unless $current =~ m{^refs/};
-    my $ffq_prev = "refs/$ffq_refprefix/$'";
+    my ($status, $message, $current, $ffq_prev) = ffq_prev_branchinfo();
+    return ($status, $message) unless $status eq 'branch';
 
     my $currentval = get_head();
 
@@ -1119,6 +1137,30 @@ sub cmd_record_ffq_prev () {
     }
 }
 
+sub cmd_stitch () {
+    my $prose = '';
+    GetOptions('prose=s', \$prose) or die badusage("bad options to stitch");
+    badusage "no arguments allowed" if @ARGV;
+    my ($status, $message, $current, $ffq_prev) = ffq_prev_branchinfo();
+    if ($status ne 'branch') {
+       fproblem $status, "could not check ffq-prev: $message";
+       fproblems_maybe_bail();
+    }
+    my $prev = $ffq_prev && git_get_ref $ffq_prev;
+    if (!$prev) {
+       fail "No ffq-prev to stitch." unless $opt_noop_ok;
+    }
+    $prose = ", $prose" if length $prose;
+    runcmd @git, qw(merge -s ours --no-edit -m), <<END;
+Declare fast forward / record previous work
+
+[git-debrebase pseudomerge: stitch$prose]
+END
+    # xxx should delete old ffq-prev
+    # xxx should avoid making pseudomerge if not needed
+    # xxx should make pseudomerge in temp tree so can do atomic update
+}
+
 sub cmd_gbp2debrebase () {
     badusage "needs 1 optional argument, the upstream" unless @ARGV<=1;
     my ($upstream_spec) = @ARGV;