guilt: bug fix: patch names can contained commas
[guilt/mob.git] / guilt-repair
blob163ac1852886de575924733b79c4243158da242b
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2008
6 DO_NOT_CHECK_STATUS_FILE_FORMAT=1
8 USAGE="--full | --status"
9 . `dirname $0`/guilt
11 safety_abort()
13 die "Please read the man page first. (you need to specify repair mode to proceed)."
16 [ $# -ne 1 ] && safety_abort
18 case "$1" in
19 --full)
20 repair="full"
22 --status)
23 repair="status"
25 --autotag)
26 echo "Autotagging is no longer supported" >&2
29 usage
31 esac
33 oldrev=`git show-ref -s "refs/heads/$branch"`
36 # Check whether status file needs fixing/upgrading. If not, just return,
37 # otherwise proceed to rewrite the status file and set up proper refs
39 repair_status()
41 _disp "Checking status file format..."
42 if ! grep "^[0-9a-f]\{40\}:" "$applied" > /dev/null ; then
43 disp "ok; no upgrade necessary."
44 return 0
46 disp "old; about to upgrade."
48 # we got an old format status file
50 printf "" > "$applied.new"
52 cat "$applied" | while read line ; do
53 hash=`echo "$line" | cut -d: -f1`
54 pname=`echo "$line" | cut -d: -f2-`
56 npname=`echo "$pname" | sed -e 's/ /-/g'`
57 [ "$pname" != "$npname" -a -e "$npname" ] && die "Patch name collision"
59 git update-ref "refs/patches/$branch/$npname" "$hash"
60 echo "$npname" >> "$applied.new"
62 if [ "$pname" != "$npname" ]; then
63 series_rename_patch "$pname" "$npname"
65 mv "$GUILT_DIR/$branch/$pname" "$GUILT_DIR/$branch/$npname"
67 done
69 # replace the status file
70 mv "$applied" "$applied~"
71 mv "$applied.new" "$applied"
73 disp "Upgrade complete."
75 return 0
79 # Pop all patches - forcefully.
81 repair_pushed()
83 if [ -s "$applied" ]; then
84 # there were some patches applied
85 newrev=`git rev-parse refs/patches/$branch/$(head -1 < "$applied")^`
86 else
87 # no patches were applied, but let's do all the work anyway
88 newrev="$oldrev"
91 disp "Current HEAD commit $oldrev"
92 disp "New HEAD commit $newrev"
94 disp "About to forcefully pop all patches..."
95 _disp "Are you sure you want to proceed? [y/N] "
96 read n
97 if [ "$n" != "y" ] && [ "$n" != "Y" ]; then
98 die "Aborting..."
101 # blow away any commits
102 git reset --hard "$newrev" > /dev/null
104 # blow away the applied stack
105 remove_patch_refs < "$applied"
106 printf "" > "$applied"
108 disp "Patches should be popped."
109 return 0
112 case "$repair" in
113 full)
114 repair_status
115 repair_pushed
117 status)
118 repair_status
121 die "Internal error"
123 esac
125 disp "Repair complete."
126 exit 0