chiark / gitweb /
wip
[topbloke.git] / tb-create.pl
index 79d42749015088e8e6c883348733bad87dcbc7af..591a72e0bb397b4264e073c1986b8c842a1a8a1a 100755 (executable)
@@ -44,6 +44,13 @@ length($spec->{Date})==18 or die "partial date specified, not supported\n";
 check_no_unwanted_metadata('HEAD')
     if $current->{Kind} ne 'tip';
 
+# For the metadata files in .topbloke, we hope that the user
+# doesn't modify them.  If they do then they get to keep all the pieces.
+#
+# For .topbloke/msg, if it's modified by the user (ie, if working
+# version differs from HEAD) we keep that, and we stage it unless
+# the cached version differs from the HEAD.
+
 my $newbranch = "$spec->{Email}\@$spec->{Domain}/$spec->{Date}/$spec->{Nick}";
 
 $newbranch = run_git_1line(qw(check-ref-format --print), $newbranch);
@@ -52,3 +59,34 @@ printf "creating %s\n", $newbranch;
 
 setup_config();
 
+if (!run_git_test_anyoutput(qw(diff --name-only HEAD -- .topbloke/msg)) {
+    open NM, '>', ".topbloke/msg.tmp" or die $!;
+    my $author = run_git_1line(qw(var GIT_AUTHOR_IDENT));
+    $author =~ s/ \d+ [-+]\d+$//;
+    print NM "From: $author\n" or die $!;
+    foreach my $h (qw(To CC BCC)) {
+       my $estatus;
+       run_git(\$estatus, sub { print NM "$h: $_" or die $!; },
+               qw(config), "topbloke.".lc $h);
+       die "$h $estatus" unless $estatus==0 || $estatus==256;
+    }
+    $subjprefix = git_config('topbloke.subjectprefix', '');
+    print NM <END or die $!;
+Subject: [${subprefix}PATCH] $spec->{Nick}
+
+<patch description>
+
+Signed-off-by: $author
+END
+    run_git(qw(add .topbloke/msg));
+    print " created and staged new .topbloke/msg\n";
+} else {
+    if (!run_git_test_anyoutput(qw(diff --cached --name-only HEAD --
+                                  .topblokemsg))) {
+       print " staged your modified .topbloke/msg\n";
+       run_git(qw(add .topbloke/msg));
+    } else {
+       print " left your (partially staged?) .topbloke/msg\n";
+    }
+}
+