chiark / gitweb /
FIX
[dgit.git] / git-debrebase
index fee793c92597f19761828bcda353167385d93420..f0cd2c88630375e89fcf00b4051346494cead12c 100755 (executable)
@@ -2537,7 +2537,12 @@ sub complete_convert_from ($$$$) {
     update_head_checkout $old_head, $new_head, $mrest;
 }
 
-sub cmd_convert_from_gbp () {
+sub cmd_convert_from_unapplied () { convert_from_some_unapplied(0); }
+sub cmd_convert_from_gbp () { convert_from_some_unapplied(0); }
+sub cmd_convert_from_bare_debian () { convert_from_some_unapplied(1); }
+
+sub convert_from_some_unapplied ($) {
+    my ($bare) = @_;
     badusage __ "want only 1 optional argument, the upstream git commitish"
        unless @ARGV<=1;
 
@@ -2553,31 +2558,39 @@ sub cmd_convert_from_gbp () {
 
     my ($old_head, $gdrlastinfo) = begin_convert_from();
 
-    my $upsdiff = get_differs $upstream, $old_head;
-    if ($upsdiff & D_UPS) {
-       runcmd @git, qw(--no-pager diff --stat),
-           $upstream, $old_head,
-           qw( -- :!/debian :/);
-       fail f_ <<END, $upstream_spec, $upstream_spec;
+    if ($bare) {
+       snag 'unfinished-conversion-mode', <<END
+The convert-from-bare-debian mode is not very finished.  In particular it does not check that the input branch was in fact bare.  Nor does it check that the upstream branch you provided was correct (not sure how it could).  So on your head be it.
+END
+    }
+
+    if (!$bare) {
+       my $upsdiff = get_differs $upstream, $old_head;
+       if ($upsdiff & D_UPS) {
+           runcmd @git, qw(--no-pager diff --stat),
+               $upstream, $old_head,
+               qw( -- :!/debian :/);
+           fail f_ <<END, $upstream_spec, $upstream_spec;
 upstream (%s) and HEAD are not
 identical in upstream files.  See diffstat above, or run
   git diff %s HEAD -- :!/debian :/
 END
-    }
+       }
 
-    if (!is_fast_fwd $upstream, $old_head) {
-       snag 'upstream-not-ancestor',
-           f_ "upstream (%s) is not an ancestor of HEAD", $upstream;
-    } else {
-       my $wrong = cmdoutput
-           (@git, qw(rev-list --ancestry-path), "$upstream..HEAD",
-            qw(-- :/ :!/debian));
-       if (length $wrong) {
-           snag 'unexpected-upstream-changes', f_
-               "history between upstream (%s) and HEAD contains direct changes to upstream files - are you sure this is a gbp (patches-unapplied) branch?",
-               $upstream;
-           print STDERR f_ "list expected changes with:  %s\n", 
- "git log --stat --ancestry-path $upstream_spec..HEAD -- :/ ':!/debian'";
+       if (!is_fast_fwd $upstream, $old_head) {
+           snag 'upstream-not-ancestor',
+               f_ "upstream (%s) is not an ancestor of HEAD", $upstream;
+       } else {
+           my $wrong = cmdoutput
+               (@git, qw(rev-list --ancestry-path), "$upstream..HEAD",
+                qw(-- :/ :!/debian));
+           if (length $wrong) {
+               snag 'unexpected-upstream-changes', f_
+                   "history between upstream (%s) and HEAD contains direct changes to upstream files - are you sure this is a gbp (patches-unapplied) branch?",
+                   $upstream;
+               print STDERR f_ "list expected changes with:  %s\n", 
+                   "git log --stat --ancestry-path $upstream_spec..HEAD -- :/ ':!/debian'";
+           }
        }
     }
 
@@ -2636,11 +2649,18 @@ END
 
     fresh_workarea();
     in_workarea sub {
-       runcmd @git, qw(checkout -q -b gdr-internal), $old_head;
+       if ($bare) {
+           runcmd @git, qw(checkout -q -b gdr-internal), $upstream;
+           runcmd @git, qw(rm --quiet -rf --ignore-unmatch debian);
+           runcmd @git, qw(checkout -q), $old_head, qw(debian);
+           runcmd @git, qw(commit --allow-empty -q -m ADD-DEBIAN);
+       } else {
+           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);
+       runcmd @git, qw(checkout -q), $old_head;
        rm_subdir_cached 'debian/patches';
        $work = make_commit ['HEAD'], [
  'git-debrebase convert-from-gbp: drop patches from tree',
@@ -2649,6 +2669,9 @@ END
                              ];
        # make the anchor merge
        # the tree is already exactly right
+       if ($bare) {
+           runcmd @git, qw(reset -q), $upstream, qw(-- :/ :!/debian);
+       }
        $work = make_commit [$work, $upstream], [
  'git-debrebase import: declare upstream',
  'First breakwater merge.',