Permalink
Browse files

Add git-treehash

It compares the SHA1 hashes of the *trees* of the refs named on the
command line.  This is useful, for example, if you are squashing or
otherwise cleaning up commit history, and you want to know if the
resulting tree is identical to the one you had before.

For this reason, the default refs are HEAD and ORIG_HEAD, for
comparing the trees before and after using git-rebase.
  • Loading branch information...
1 parent 1bd9dac commit a794af7c78391f5db3b53779f91ab6c4e8a18af0 @mjdominus committed Dec 22, 2011
Showing with 27 additions and 0 deletions.
  1. +27 −0 git-treehash
View
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+my %opt;
+use Getopt::Std;
+getopts("q", \%opt);
+
+@ARGV = qw(HEAD ORIG_HEAD) unless @ARGV;
+
+for my $rev (@ARGV) {
+ chomp(my $res = qx{git rev-parse $rev^{tree}});
+ if ($?) { $BAD++ }
+ else { push @{$hash{$res}}, $rev }
+}
+
+exit 2 if $BAD;
+if (keys(%hash) == 1) {
+ my ($res) = keys %hash;
+ print "$res\n" unless $opt{"q"};
+ exit 0;
+} else {
+ unless ($opt{"q"}) {
+ for my $res (keys %hash) {
+ print $res, " ", join(" ", @{$hash{$res}}), "\n";
+ }
+ }
+ exit 1;
+}

0 comments on commit a794af7

Please sign in to comment.