chiark / gitweb /
git-debrebase: new-upstream-v0: support passing git-rebase options
[dgit.git] / git-debrebase
index df5d27e627b6c8093076b61e34dff6b58b834c30..b3a78ae2f0139678d2271e5db146bb454fcdfa53 100755 (executable)
@@ -21,6 +21,7 @@
 #    git-debrebase new-upstreams-v0 \
 #             NEW-VERSION ORIG-COMMITISH
 #            [EXTRA-ORIG-NAME EXTRA-ORIG-COMMITISH ...]
+#            [<git-rebase options>]
 
 # usages:
 #    git-debrebase status
@@ -785,13 +786,18 @@ sub update_head_checkout ($$$) {
     update_head $old, $new, $mrest;
 }
 
+sub update_head_postlaunder ($$$) {
+    my ($old, $tip, $reflogmsg) = @_;
+    update_head $old, $tip, $reflogmsg;
+    # no tree changes except debian/patches
+    runcmd @git, qw(rm --quiet --ignore-unmatch -rf debian/patches);
+}
+
 sub cmd_launder () {
     badusage "no arguments to launder allowed" if @ARGV;
     my $old = get_head();
     my ($tip,$breakwater,$last_upstream_merge) = walk $old;
-    update_head $old, $tip, 'launder';
-    # no tree changes except debian/patches
-    runcmd @git, qw(rm --quiet --ignore-unmatch -rf debian/patches);
+    update_head_postlaunder $old, $tip, 'launder';
     printf "# breakwater tip\n%s\n", $breakwater;
     printf "# working tip\n%s\n", $tip;
     printf "# last upstream merge\n%s\n", $last_upstream_merge;
@@ -811,16 +817,14 @@ sub cmd_analyse () {
 }
 
 sub cmd_new_upstream_v0 () {
-    # xxx would like to support more git-rebase options
-    badusage
- "need NEW-VERSION UPS-COMMITISH [EXTRA-UPS-NAME EXTRA-UPS-COMMITISH...]"
-       unless @ARGV % 2 == 0 and @ARGV >= 2;
     # 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
 
     my %pieces;
 
+    badusage "need NEW-VERSION UPS-COMMITTISH" unless @ARGV >= 2;
+
     # parse args - low commitment
     my $new_version = (new Dpkg::Version scalar(shift @ARGV), check => 1);
     my $new_upstream_version = $new_version->version();
@@ -848,8 +852,12 @@ sub cmd_new_upstream_v0 () {
         OldIx => 0,
         New => $new_upstream,
     );
-    while (@ARGV) {
+    while (@ARGV && $ARGV[0] !~ m{^-}) {
        my $n = shift @ARGV;
+
+        badusage "for each EXTRA-UPS-NAME need EXTRA-UPS-COMMITISH"
+            unless @ARGV && $ARGV[0] !~ m{^-};
+
        my $c = git_rev_parse shift @ARGV;
        die unless $n =~ m/^$extra_orig_namepart_re$/;
        $newpiece->($n, New => $c);
@@ -939,15 +947,12 @@ sub cmd_new_upstream_v0 () {
 
        if (@newpieces > 1) {
            # need to make the upstream subtree merge commit
-           my $us_tree = cmdoutput @git, qw(write-tree);
-           my @cmd = (@git, qw(commit-tree), $us_tree);
-           push @cmd, qw(-p), $_ foreach @upstream_merge_parents;
-           push @cmd, qw(-m), "Combine upstreams for $new_upstream_version";
-           push @cmd, qw(-m),
-               "[git-debrebase new-upstream combine . ".
-               (join " ", map { $_->{Name} } @newpieces[1..$#newpieces]).
-                "]";
-           $new_upstream = cmdoutput @cmd;
+            $new_upstream = make_commit \@upstream_merge_parents,
+                [ "Combine upstreams for $new_upstream_version",
+                  ("[git-debrebase new-upstream combine . ".
+                   (join " ", map { $_->{Name} } @newpieces[1..$#newpieces]).
+                   "]"),
+                ];
        }
 
        # $new_upstream is either the single upstream commit, or the
@@ -964,10 +969,10 @@ sub cmd_new_upstream_v0 () {
 
        # Now we have to add a changelog stanza so the Debian version
        # is right.
-
        die if unlink "debian";
-       die $! unless $!==ENOTEMPTY;
-       unlink "debian/changelog" or die $!;
+       die $! unless $!==ENOENT or $!==ENOTEMPTY;
+       unlink "debian/changelog" or $!==ENOENT or die $!;
+        mkdir "debian" or die $!;
        open CN, ">", "debian/changelog" or die $!;
        my $oldclog = git_cat_file ":debian/changelog";
        $oldclog =~ m/^($package_re) \(\S+\) / or
@@ -995,9 +1000,10 @@ END
     # the laundering output, because git-rebase can't easily be made
     # to make a replay list which is based on some other branch
 
-    update_head $old_head, $old_laundered_tip, 'launder for new upstream';
+    update_head_postlaunder $old_head, $old_laundered_tip,
+        'launder for new upstream';
 
-    my @cmd = (@git, qw(rebase --onto), $new_bw, $old_bw);
+    my @cmd = (@git, qw(rebase --onto), $new_bw, $old_bw, @ARGV);
     runcmd @cmd;
     # now it's for the user to sort out
 }