chiark / gitweb /
git-debrebase: insist that breakwater merges are merges
[dgit.git] / git-debrebase
index 50f5e1674c6574afa7d42c8e7d04a33c31b99867..6d8091e63bfb880b42a56aa1387d8d0b1a0aacfd 100755 (executable)
@@ -162,7 +162,7 @@ sub get_differs ($$) {
        my @cmd = (@git, qw(diff-tree -z --no-renames));
        push @cmd, @$opts;
        push @cmd, "$_:" foreach $x, $y;
-       push @cmd, @$limits;
+       push @cmd, '--', @$limits;
        my $diffs = cmdoutput @cmd;
        foreach (split /\0/, $diffs) { $fn->(); }
     };
@@ -371,7 +371,13 @@ sub classify ($) {
        return $r;
     };
 
+    my $claims_to_be_breakwater =
+       $r->{Msg} =~ m{^\[git-debrebase breakwater.*\]$}m;
+
     if (@p == 1) {
+       if ($claims_to_be_breakwater) {
+           return $unknown->("single-parent git-debrebase breakwater \`merge'");
+       }
        my $d = $r->{Parents}[0]{Differs};
        if ($d == D_PAT_ADD) {
            return $classify->(qw(AddPatches));
@@ -405,7 +411,10 @@ sub classify ($) {
     }
 
     my @identical = grep { !$_->{Differs} } @p;
-    if (@p == 2 && @identical == 1) {
+    if (@p == 2 && @identical == 1 && !$claims_to_be_breakwater
+       # breakwater merges can look like pseudomerges, if they are
+       # "declare" commits (ie, there are no upstream changes)
+       ) {
        my @overwritten = grep { $_->{Differs} } @p;
        confess "internal error $objid ?" unless @overwritten==1;
        return $classify->(qw(Pseudomerge),
@@ -492,10 +501,11 @@ sub walk ($;$$) {
 
     my $cl;
     my $xmsg = sub {
-       my ($appendinfo) = @_;
+       my ($prose, $info) = @_;
        my $ms = $cl->{Msg};
        chomp $ms;
-       $ms .= "\n\n[git-debrebase $appendinfo]\n";
+       $info //= '';
+       $ms .= "\n\n[git-debrebase$info: $prose]\n";
        return (Msg => $ms);
     };
     my $rewrite_from_here = sub {
@@ -628,7 +638,8 @@ sub walk ($;$$) {
                    push @brw_cl, {
                        %$cl,
                        SpecialMethod => 'DgitImportUpstreamUpdate',
-                       $xmsg->("convert dgit import: upstream changes")
+                       $xmsg->("convert dgit import: upstream changes",
+                               " breakwater")
                    };
                }
                $prline->(" Import");
@@ -770,9 +781,8 @@ sub update_head ($$$) {
 
 sub update_head_checkout ($$$) {
     my ($old, $new, $mrest) = @_;
-    my $symref = git_get_symref();
-    runcmd @git, qw(checkout), $new, qw(.);
     update_head $old, $new, $mrest;
+    runcmd @git, qw(reset --hard);
 }
 
 sub update_head_postlaunder ($$$) {
@@ -877,7 +887,7 @@ sub cmd_new_upstream_v0 () {
 
     if ($old_upstream->{Msg} =~ m{^\[git-debrebase }m) {
        if ($old_upstream->{Msg} =~
- m{^\[git-debrebase (?:\w*-)?upstream combine \.((?: $extra_orig_namepart_re)+)\]}
+ m{^\[git-debrebase upstream-combine \.((?: $extra_orig_namepart_re)+)\:.*\]$}m
           ) {
            my @oldpieces = ('', split / /, $1);
            my $parentix = -1 + scalar @{ $old_upstream->{Parents} };
@@ -887,7 +897,7 @@ sub cmd_new_upstream_v0 () {
            }
        } else {
            fproblem "previous upstream $old_upstream->{CommitId} is from".
-                 " git-debrebase but not an \`upstream combine' commit";
+                 " git-debrebase but not an \`upstream-combine' commit";
        }
     }
 
@@ -931,9 +941,9 @@ sub cmd_new_upstream_v0 () {
            # need to make the upstream subtree merge commit
             $new_upstream = make_commit \@upstream_merge_parents,
                 [ "Combine upstreams for $new_upstream_version",
                 ("[git-debrebase new-upstream combine . ".
                  (join " ", map { $_->{Name} } @newpieces[1..$#newpieces]).
                  "]"),
("[git-debrebase upstream-combine . ".
+ (join " ", map { $_->{Name} } @newpieces[1..$#newpieces]).
": new upstream]"),
                 ];
        }
 
@@ -946,7 +956,7 @@ sub cmd_new_upstream_v0 () {
        # index now contains the breakwater merge contents
         $new_bw = make_commit [ $old_bw, $new_upstream ],
             [ "Update to upstream $new_upstream_version",
             "[git-debrebase new-upstream breakwater $new_upstream_version]",
"[git-debrebase breakwater: new upstream $new_upstream_version, merge]",
             ];
 
        # Now we have to add a changelog stanza so the Debian version
@@ -974,7 +984,7 @@ END
        # Now we have the final new breakwater branch in the index
         $new_bw = make_commit [ $new_bw ],
             [ "Update changelog for new upstream $new_upstream_version",
-              "[git-debrebase new-upstream changelog $new_upstream_version]",
+              "[git-debrebase: new upstream $new_upstream_version, changelog]",
             ];
     };
 
@@ -1020,13 +1030,39 @@ sub cmd_gbp2debrebase () {
     if ((git_cat_file "$upstream:debian")[0] ne 'missing') {
        fproblem "upstream ($upstream) contains debian/ directory";
     }
-    die;
+
+    fproblems_maybe_bail();
+
+    my $work;
 
     fresh_workarea();
     in_workarea sub {
-       runcmd @git, qw(checkout -b work), $old_head;
-       
+       runcmd @git, qw(checkout -q -b gdr-internal), $old_head;
+       # make a branch out of the patch queue - we'll want this in a mo
+       runcmd qw(gbp pq import);
+       # strip the patches out
+       runcmd @git, qw(checkout -q gdr-internal~0);
+       rm_subdir_cached 'debian/patches';
+       $work = make_commit ['HEAD'], [
+ 'git-debrebase import: drop patch queue',
+ 'Delete debian/patches, as part of converting to git-debrebase format.',
+ '[git-debrebase: gbp2debrebase, drop patches]'
+                             ];
+       # make the breakwater pseudomerge
+       # the tree is already exactly right
+       $work = make_commit [$work, $upstream], [
+ 'git-debrebase import: declare upstream',
+ 'First breakwater merge.',
+ '[git-debrebase breakwater: declare upstream]'
+                             ];
+
+       # 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();
     };
+
+    update_head_checkout $old_head, $work, 'gbp2debrebase';
 }
 
 sub cmd_downstream_rebase_launder_v0 () {