chiark / gitweb /
git-debrebase: do not add -i in default invocation
[dgit.git] / git-debrebase
index 2f34029a996e3cbeff566806e93789832a67489a..50fa1bc96cfb22e169f9c27406b165047e5b1152 100755 (executable)
@@ -98,13 +98,17 @@ sub badusage ($) {
     die "bad usage: $m\n";
 }
 
-sub cfg ($) {
-    my ($k) = @_;
+sub cfg ($;$) {
+    my ($k, $optional) = @_;
     $/ = "\0";
     my @cmd = qw(git config -z);
     push @cmd, qw(--get-all) if wantarray;
     push @cmd, $k;
-    my $out = cmdoutput @cmd;
+    my $out = cmdoutput_errok @cmd;
+    if (!defined $out) {
+       fail "missing required git config $k" unless $optional;
+       return ();
+    }
     return split /\0/, $out;
 }
 
@@ -791,7 +795,10 @@ sub walk ($;$$) {
     return @r
 }
 
-sub get_head () { return git_rev_parse qw(HEAD); }
+sub get_head () {
+    git_check_unmodified();
+    return git_rev_parse qw(HEAD);
+}
 
 sub update_head ($$$) {
     my ($old, $new, $mrest) = @_;
@@ -827,7 +834,6 @@ sub defaultcmd_rebase () {
     my $old = get_head();
     my ($tip,$breakwater) = walk $old;
     update_head_postlaunder $old, $tip, 'launder for rebase';
-    @ARGV = qw(-i) unless @ARGV; # make configurable
     runcmd @git, qw(rebase), @ARGV, $breakwater;
 }
 
@@ -838,7 +844,7 @@ sub cmd_analyse () {
     if (defined $old) {
        $old = git_rev_parse $old;
     } else {
-       $old = get_head();
+       $old = git_rev_parse 'HEAD';
     }
     my ($dummy,$breakwater) = walk $old, 1,*STDOUT;
     STDOUT->error and die $!;
@@ -864,13 +870,13 @@ sub record_ffq_prev () {
     my $currentval = get_head();
 
     my $exists = git_get_ref $ffq_prev;
-    return ('exists',"$ffq_prev already exists") if defined $exists;
+    return ('exists',"$ffq_prev already exists") if $exists;
 
     return ('not-branch', 'HEAD symref is not to refs/heads/')
        unless $current =~ m{^refs/heads/};
     my $branch = $';
 
-    my @check_specs = split /\;/, (cfg "branch.$branch.ffq-ffrefs") // '*';
+    my @check_specs = split /\;/, (cfg "branch.$branch.ffq-ffrefs",1) // '*';
     my %checked;
 
     my $check = sub {
@@ -897,7 +903,7 @@ sub record_ffq_prev () {
        }
     };
 
-    my $merge = cfg "branch.$branch.merge";
+    my $merge = cfg "branch.$branch.merge",1;
     if (defined $merge && $merge =~ m{^refs/heads/}) {
        my $rhs = $';
        my $check_remote = sub {
@@ -905,17 +911,19 @@ sub record_ffq_prev () {
            return unless defined $remote;
            $check->("refs/remotes/$remote/$rhs", $desc);
        };
-       $check_remote->((cfg "branch.$branch.remote"),
+       $check_remote->((cfg "branch.$branch.remote",1),
                        'remote fetch/merge branch');
-       $check_remote->((cfg "branch.$branch.pushRemote") //
-                       (cfg "branch.$branch.pushDefault"),
+       $check_remote->((cfg "branch.$branch.pushRemote",1) //
+                       (cfg "branch.$branch.pushDefault",1),
                        'remote push branch');
     }
     if ($branch =~ m{^dgit/}) {
        $check->("remotes/dgit/$branch", 'remote dgit branch');
+    } elsif ($branch =~ m{^master$}) {
+       $check->("remotes/dgit/dgit/sid", 'remote dgit branch for sid');
     }
 
-    fproblems_maybe_fail();
+    fproblems_maybe_bail();
     runcmd @git, qw(update-ref -m), "record current head for preservation",
        $ffq_prev, $currentval, $git_null_obj;
     print "Recorded current head for preservation\n" or die $!;
@@ -923,7 +931,6 @@ sub record_ffq_prev () {
 }
 
 sub cmd_new_upstream_v0 () {
-    # tree should be clean and this is not checked
     # automatically and unconditionally launders before rebasing
     # if rebase --abort is used, laundering has still been done
 
@@ -1101,6 +1108,17 @@ END
     # now it's for the user to sort out
 }
 
+sub cmd_record_ffq_prev () {
+    badusage "no arguments allowed" if @ARGV;
+    my ($status, $msg) = record_ffq_prev();
+    if ($status eq 'exists' && $opt_noop_ok) {
+       print "Previous head already recorded\n" or die $!;
+    } elsif ($status eq 'written') {
+    } else {
+       fail "Could not preserve: $msg";
+    }
+}
+
 sub cmd_gbp2debrebase () {
     badusage "needs 1 optional argument, the upstream" unless @ARGV<=1;
     my ($upstream_spec) = @ARGV;
@@ -1163,7 +1181,7 @@ sub cmd_gbp2debrebase () {
        # rebase the patch queue onto the new breakwater
        runcmd @git, qw(reset --quiet --hard patch-queue/gdr-internal);
        runcmd @git, qw(rebase --quiet --onto), $work, qw(gdr-internal);
-       $work = get_head();
+       $work = git_rev_parse 'HEAD';
     };
 
     update_head_checkout $old_head, $work, 'gbp2debrebase';