chiark / gitweb /
9cc61a9673fa9e52060a84bc774be0def321859e
[dgit.git] / badcommit-fixup
1 #!/bin/bash
2
3 set -e
4 set -o pipefail
5
6 tmp=.git/dgit-badcommit-fixup-tmp
7 rm -rf $tmp
8 mkdir $tmp
9
10 LC_MESSAGES=C git fsck --no-dangling >$tmp/gfo 2>&1 || test $? = 1
11
12 perl -ne '
13         print $1, "\n" or die $! if
14  m/^error in commit (\w+):.*invalid format - expected '\''committer/;
15 ' <$tmp/gfo >$tmp/bad
16
17 case `wc -l <$tmp/bad` in
18     0)
19         echo >&2 'nothing bad found - is git-fsck doing as we expect?' ;
20         exit 8 ;;
21     1)
22         read <$tmp/bad bads
23         nots="^$bads^0 ^$bads^1"
24         ;;
25     *)
26         bads="cat $tmp/bad"
27         ;;
28 esac
29
30 args="$nots"
31
32 for head in HEAD `git-for-each-ref --format='%(refname)'`; do
33     exec <$tmp/bad
34     needed=false
35     for bad in $bads; do
36         if git merge-base --is-ancestor $bad $head; then
37             needed=true
38             break
39         fi
40     done 
41     if ! $needed; then continue; fi
42     args+=" $head"
43 done
44
45 cat >$tmp/flt <<'END'
46 #!/usr/bin/perl -w
47 use strict;
48 undef $/;
49 $_ = <STDIN>;
50 s/^(\w+.*\n)*commiter /$1committer /;
51 END
52
53 git filter-branch --original dgit-badcommit --commit-filter '
54     sed -e '\''1,/^$/ s/^commiter /committer /'\''
55 ' $args