Browse files

Merge branch 'git-whats'

  • Loading branch information...
2 parents 4e853a6 + ddfc320 commit 7c6ac9db30587d3cba51cb2eb32a07f3f9c8adc0 @mjdominus committed Mar 17, 2013
Showing with 59 additions and 0 deletions.
  1. +5 −0 NOTES/git-whats
  2. +54 −0 git-whats
View
5 NOTES/git-whats
@@ -0,0 +1,5 @@
+Needs a git-commit hook that detects when you are making a commit to a
+nonmaster branch that has no .whats file, prompts you for a
+message. and then redoes the commit. It should also detect a merge and
+prompt you for a new message, or, if the merge is to master, destroys
+the .whats file automatically.
View
54 git-whats
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+
+$ENV{GIT_GET_NO_NEWLINE} = 1;
+
+sub usage {
+ die "Usage:\tgit-whats [commit-ish]
+ git-whats --set 'description'
+ git-whats --clear\n";
+}
+
+use Getopt::Long;
+my $message_file = join "/",
+ scalar(qx{git get repo-rootdir-relative}), ".what";
+my $message;
+my $clear;
+GetOptions ("set=s" => \$message,
+ "clear" => \$clear,
+ )
+ or usage();
+
+if ($clear) {
+ # --clear is incompatible with --set MESSAGE
+ usage() if defined($message);
+ $message = "";
+}
+
+if (defined $message) {
+ usage() if @ARGV && (@ARGV != 1 || $ARGV[0] ne "HEAD");
+
+ if ($message =~ /\S/) {
+ $message .= "\n" unless $message =~ /\n\z/;
+ open my($f), ">", $message_file
+ or die "Couldn't write '$message_file': $!";
+ print $f $message;
+ system(qw(git add), $message_file) == 0
+ or die sprintf "git-add '$message_file' failed with status %d\n",
+ $? >> 8;
+ system(qw(git commit --amend -C HEAD --), $message_file) == 0
+ or die sprintf "git-commit -C HEAD failed with status %d\n",
+ $? >> 8;
+ } else {
+ system(qw(git rm), $message_file) == 0
+ or die sprintf "git-rm '$message_file' failed with status %d\n",
+ $? >> 8;
+ system(qw(git commit --amend -C HEAD)) == 0
+ or die sprintf "git-commit -C HEAD failed with status %d\n",
+ $? >> 8;
+ }
+ exit 0;
+} else {
+ my ($commit_ish) = shift @ARGV || 'HEAD';
+ system(qw(git show), "$commit_ish:$message_file");
+}
+

0 comments on commit 7c6ac9d

Please sign in to comment.