diff options
author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2017-01-05 01:56:43 +0000 |
---|---|---|
committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2017-01-05 01:56:43 +0000 |
commit | 98a027c28b54f68f33a80bf479022a63a5230f12 (patch) | |
tree | bcd8a1b7a07e76767623f799707162a9d0e1295d | |
parent | e6ef76e06de2ab76c2d25029008ac1df8872caf0 (diff) |
badcommit-fixup: seems to work
-rwxr-xr-x | badcommit-fixup | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/badcommit-fixup b/badcommit-fixup index 2eeaefe..2c28e51 100755 --- a/badcommit-fixup +++ b/badcommit-fixup @@ -1,11 +1,20 @@ #!/usr/bin/perl -w +# usage: +# .../badcommit-fixup --test +# .../badcommit-fixup --real + use strict; use POSIX; use IPC::Open2; use Data::Dumper; +die unless "@ARGV" eq "--test" or "@ARGV" eq "--real"; + +my ($modeopt) = @ARGV; +my $real = ($modeopt eq '--real'); + my $gcfpid = open2 \*GCFO, \*GCFI, 'git cat-file --batch' or die $!; our %count; @@ -117,7 +126,40 @@ foreach my $rline (split /\n/, $refs) { next; } next if $rewrite eq $obj; - push @updates, [ $refname, $rewrite ]; + push @updates, [ $refname, $obj, $rewrite ]; } -print Dumper(\@updates, \%count); +open U, "|git update-ref -m 'dgit bad commit fixup' --stdin" or die $!; + +if ($real) { + print "detaching your HEAD\n" or die $!; + system 'git checkout --detach' and die "$! $?"; +} + +for my $up (@updates) { + my ($ref, $old, $new) = @$up; + my $otherref = $ref; + $otherref =~ s{^refs/}{}; + if ($real) { + print U <<END or die $!; +create refs/dgit-badcommit/$otherref $old +update $ref $new $old +END + } else { + print U <<END or die $!; +update refs/dgit-badfixuptest/$otherref $new +END + } +} + +$?=0; $!=0; +close U or die "$? $!"; +die $? if $?; + +print Dumper(\%count); + +if ($real) { + print "old values saved in refs/dgit-badcommit/\n" or die $!; +} else { + print "testing output saved in refs/dgit-badfixuptest/\n" or die $!; +} |