3 # Copyright (c) Josef "Jeff" Sipek, 2008-2013
6 DO_NOT_CHECK_STATUS_FILE_FORMAT
=1
8 USAGE
="--full | --status"
9 if [ -z "$GUILT_VERSION" ]; then
10 echo "Invoking `basename "$0"` directly is no longer supported." >&2
16 die
"Please read the man page first. (you need to specify repair mode to proceed)."
20 # Check whether status file needs fixing/upgrading. If not, just return,
21 # otherwise proceed to rewrite the status file and set up proper refs
25 _disp
"Checking status file format..."
26 if ! grep "^[0-9a-f]\{40\}:" "$applied" > /dev
/null
; then
27 disp
"ok; no upgrade necessary."
30 disp
"old; about to upgrade."
32 # we got an old format status file
34 printf "" > "$applied.new"
36 cat "$applied" |
while read line
; do
37 hash=`echo "$line" | cut -d: -f1`
38 pname
=`echo "$line" | cut -d: -f2-`
40 npname
=`echo "$pname" | sed -e 's/ /-/g'`
41 [ "$pname" != "$npname" -a -e "$npname" ] && die
"Patch name collision"
43 git update-ref
"refs/patches/$branch/$npname" "$hash"
44 echo "$npname" >> "$applied.new"
46 if [ "$pname" != "$npname" ]; then
47 series_rename_patch
"$pname" "$npname"
49 mv "$GUILT_DIR/$branch/$pname" "$GUILT_DIR/$branch/$npname"
53 # replace the status file
54 mv "$applied" "$applied~"
55 mv "$applied.new" "$applied"
57 disp
"Upgrade complete."
63 # Pop all patches - forcefully.
67 if [ -s "$applied" ]; then
68 # there were some patches applied
69 newrev
=`git rev-parse refs/patches/$branch/$(head_n 1 < "$applied")^`
71 # no patches were applied, but let's do all the work anyway
75 disp
"Current HEAD commit $oldrev"
76 disp
"New HEAD commit $newrev"
78 disp
"About to forcefully pop all patches..."
79 _disp
"Are you sure you want to proceed? [y/N] "
81 if [ "$n" != "y" ] && [ "$n" != "Y" ]; then
85 # blow away any commits
86 git
reset --hard "$newrev" > /dev
/null
87 if [ "`git symbolic-ref HEAD`" = "refs/heads/$GUILT_PREFIX$branch" ] && ! $old_style_prefix
89 git symbolic-ref HEAD refs
/heads
/$branch
90 git update-ref
-d refs
/heads
/$GUILT_PREFIX$branch
93 # blow away the applied stack
94 remove_patch_refs
< "$applied"
95 printf "" > "$applied"
97 disp
"Patches should be popped."
103 [ $# -ne 1 ] && safety_abort
113 echo "Autotagging is no longer supported" >&2
120 oldrev
=`git show-ref -s "refs/heads/\`git_branch\
`"`
135 disp
"Repair complete."