summaryrefslogtreecommitdiff
path: root/badcommit-fixup
blob: 9cc61a9673fa9e52060a84bc774be0def321859e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash

set -e
set -o pipefail

tmp=.git/dgit-badcommit-fixup-tmp
rm -rf $tmp
mkdir $tmp

LC_MESSAGES=C git fsck --no-dangling >$tmp/gfo 2>&1 || test $? = 1

perl -ne '
	print $1, "\n" or die $! if
 m/^error in commit (\w+):.*invalid format - expected '\''committer/;
' <$tmp/gfo >$tmp/bad

case `wc -l <$tmp/bad` in
    0)
	echo >&2 'nothing bad found - is git-fsck doing as we expect?' ;
	exit 8 ;;
    1)
	read <$tmp/bad bads
	nots="^$bads^0 ^$bads^1"
	;;
    *)
	bads="cat $tmp/bad"
	;;
esac

args="$nots"

for head in HEAD `git-for-each-ref --format='%(refname)'`; do
    exec <$tmp/bad
    needed=false
    for bad in $bads; do
	if git merge-base --is-ancestor $bad $head; then
	    needed=true
	    break
	fi
    done 
    if ! $needed; then continue; fi
    args+=" $head"
done

cat >$tmp/flt <<'END'
#!/usr/bin/perl -w
use strict;
undef $/;
$_ = <STDIN>;
s/^(\w+.*\n)*commiter /$1committer /;
END

git filter-branch --original dgit-badcommit --commit-filter '
    sed -e '\''1,/^$/ s/^commiter /committer /'\''
' $args