chiark / gitweb /
git-debrebase: Implement make-patches
[dgit.git] / git-debrebase
index 7d5d5bdd72254bc0dcbac180037d0355095d58cb..7c8d54dbc558208a1aecb7bfa890275f8ca4d2ac 100755 (executable)
@@ -1362,6 +1362,44 @@ sub make_patches_staged ($) {
     };
 }
 
+sub make_patches ($) {
+    my ($head) = @_;
+    keycommits $head, 0, \&snag;
+    make_patches_staged $head;
+    my $out;
+    in_workarea sub {
+       my $ptree = cmdoutput @git, qw(write-tree --prefix=debian/patches/);
+       runcmd @git, qw(read-tree), $head;
+       read_tree_subdir 'debian/patches', $ptree;
+       $out = make_commit [$head], [
+            'Commit patch queue (exported by git-debrebase)',
+            '[git-debrebase: export and commit patches]',
+        ];
+    };
+    my $d = get_differs $head, $out;
+    if ($d == 0) {
+       return undef; # nothing to do
+    } elsif ($d == D_PAT_ADD) {
+       return $out; # OK
+    } else {
+       fail "Patch export produced patch amendments".
+           " (abandoned output commit $out).".
+           "  Try laundering first.";
+    }
+}
+
+sub cmd_make_patches () {
+    badusage "no arguments allowed" if @ARGV;
+    my $old_head = get_head();
+    my $new = make_patches $old_head;
+    snags_maybe_bail();
+    if (!$new) {
+       fail "No (more) patches to export." unless $opt_noop_ok;
+       return;
+    }
+    update_head_checkout $old_head, $new, 'make-patches';
+}
+
 sub cmd_convert_from_gbp () {
     badusage "needs 1 optional argument, the upstream git rev"
        unless @ARGV<=1;