Skip to content

Commit

Permalink
git-whats learns --key to say which key to set; 'what' is the default
Browse files Browse the repository at this point in the history
This way you can use git-whats to record more tha none piece of
information per branch.  For example, I intent to use
  git-whats --key=unf --set=1234
to record the Unfuddle ticket number pertaining to the current branch.

Also, --unset is now a synonym for --clear.
  • Loading branch information
Mark Jason Dominus committed Apr 9, 2014
1 parent cebae8e commit 6236c3b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions git-whats
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ $ENV{GIT_GET_NO_NEWLINE} = 1;
use Getopt::Long;
my $message;
my ($clear, $prune, $verbose, $noaction);
my $key_name = "what";
GetOptions ("set=s" => \$message,
"clear" => \$clear,
"clear|unset" => \$clear,
"prune" => \$prune,
"key|k=s" => \$key_name,
"verbose|v" => \$verbose,
"dry-run|n" => \$noaction,
)
Expand Down Expand Up @@ -51,23 +53,23 @@ if (defined $message) {

sub config_key {
my ($ref) = @_;
return "branch.$ref.what";
return "branch.$ref.$key_name";
}

sub prune_whats {
chomp(my @heads = qx{git get heads});
my %head = map { $_ => 1 } @heads;
for my $key (qx{git get config-keys}) {
chomp $key;
my ($branch) = $key =~ /^branch\.([^.]+)\.what$/ or next;
my ($branch) = $key =~ /^branch\.([^.]+)\.\Q$key_name\E$/ or next;
if (! $head{$branch}) {
warn "deleting $key\n";
system("git config --unset-all $key") unless $noaction;
warn "deleting '$key'\n";
system("git config --unset-all '$key'") unless $noaction;
}
}
}

sub usage {
die "Usage: git-whats [--set=...] [--clear] [branch]
die "Usage: git-whats [--key=...] [--set=...] [--clear] [branch]
git-whats [-v] --prune\n";
}

0 comments on commit 6236c3b

Please sign in to comment.