chiark / gitweb /
git-debrebase: make-patches: Handle case when there are no patches
[dgit.git] / git-debrebase
index 353b405ffa9cbec39ebefd2d001614da02426bf1..10dadc55cab4f731768601f65e47a409ff132e69 100755 (executable)
@@ -1081,9 +1081,8 @@ sub keycommits ($;$$$$$) {
     my ($head, $furniture, $unclean, $trouble, $fatal, $claimed_bw) = @_;
     # => ($anchor, $breakwater)
 
-    # $unclean->("unclean-$tagsfx", $msg, $cl)
     # $furniture->("unclean-$tagsfx", $msg, $cl)
-    # $dgitimport->("unclean-$tagsfx", $msg, $cl))
+    # $unclean->("unclean-$tagsfx", $msg, $cl)
     #   is callled for each situation or commit that
     #   wouldn't be found in a laundered branch
     # $furniture is for furniture commits such as might be found on an
@@ -2408,12 +2407,17 @@ sub make_patches_staged ($) {
 sub make_patches ($) {
     my ($head) = @_;
     keycommits $head, 0, \&snag;
-    make_patches_staged $head;
+    my $any = make_patches_staged $head;
     my $out;
     in_workarea sub {
-       my $ptree = cmdoutput @git, qw(write-tree --prefix=debian/patches/);
+       my $ptree = !$any ? undef :
+           cmdoutput @git, qw(write-tree --prefix=debian/patches/);
        runcmd @git, qw(read-tree), $head;
-       read_tree_subdir 'debian/patches', $ptree;
+       if ($ptree) {
+           read_tree_subdir 'debian/patches', $ptree;
+       } else {
+           rm_subdir_cached 'debian/patches';
+       }
        $out = make_commit [$head], [
             'Commit patch queue (exported by git-debrebase)',
             '[git-debrebase make-patches: export and commit patches]',
@@ -2635,13 +2639,18 @@ sub cmd_convert_to_gbp () {
     my (undef, undef, undef, $ffq, $gdrlast) = ffq_prev_branchinfo();
     my ($anchor, $breakwater) = keycommits $head, 0;
     my $out = $breakwater;
-    make_patches_staged $head;
-    in_workarea sub {
-       $out = make_commit [$out], [
-            'Commit patch queue (converted from git-debrebase format)',
-            '[git-debrebase convert-to-gbp: commit patches]',
-        ];
-    };
+    my $any = make_patches_staged $head;
+    if ($any) {
+       in_workarea sub {
+           $out = make_commit [$out], [
+               'Commit patch queue (converted from git-debrebase format)',
+               '[git-debrebase convert-to-gbp: commit patches]',
+           ];
+       };
+    } else {
+       # in this case, it can be fast forward
+       $out = $head;
+    }
     if (defined $ffq) {
        push @deferred_updates, "delete $ffq";
        push @deferred_updates, "delete $gdrlast";