X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=badcommit-fixup;h=44c07021f44a3fbdb947be0951345ebff4fe80b5;hb=d8ad9a1e4bdd121d59c309bd5868cf365c57c501;hp=2eeaefe1402901bbb149ff8162df59fe9efb09ed;hpb=a1378fbda47e75912ba5938cbb5cd9145bab764d;p=dgit-junk.git diff --git a/badcommit-fixup b/badcommit-fixup index 2eeaefe..44c0702 100755 --- a/badcommit-fixup +++ b/badcommit-fixup @@ -1,11 +1,29 @@ #!/usr/bin/perl -w +# usage: +# .../badcommit-fixup [-- --test +# .../badcommit-fixup --real + use strict; use POSIX; use IPC::Open2; use Data::Dumper; +my $real; + +foreach my $a (@ARGV) { + if ($a eq '--test') { + $real = 0; + } elsif ($a eq '--real') { + $real = 1; + } else { + die "$a ?"; + } +} + +die unless defined $real; + my $gcfpid = open2 \*GCFO, \*GCFI, 'git cat-file --batch' or die $!; our %count; @@ -96,7 +114,7 @@ sub rewrite_tag ($) { } $!=0; $?=0; -my $refs=`git-for-each-ref`; +my $refs=`git for-each-ref`; die "$? $!" if $?; chomp $refs; @@ -117,7 +135,46 @@ 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); +$!=0; $?=0; +my $bare = `git rev-parse --is-bare-repository`; +die "$? $!" if $?; + +open U, "|git update-ref -m 'dgit bad commit fixup' --stdin" or die $!; + +if ($real) { + if ($bare eq 'false') { + 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 <