doc: git doesn't use git-foo invocations.
[guilt.git] / guilt-repair
blob3a0b65abd51c645173fd38d69e0c32fa22ed067f
1 #!/bin/sh
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
11 exit 1
14 safety_abort()
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
23 repair_status()
25 _disp "Checking status file format..."
26 if ! grep "^[0-9a-f]\{40\}:" "$applied" > /dev/null ; then
27 disp "ok; no upgrade necessary."
28 return 0
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"
51 done
53 # replace the status file
54 mv "$applied" "$applied~"
55 mv "$applied.new" "$applied"
57 disp "Upgrade complete."
59 return 0
63 # Pop all patches - forcefully.
65 repair_pushed()
67 if [ -s "$applied" ]; then
68 # there were some patches applied
69 newrev=`git rev-parse refs/patches/$branch/$(head_n 1 < "$applied")^`
70 else
71 # no patches were applied, but let's do all the work anyway
72 newrev="$oldrev"
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] "
80 read n
81 if [ "$n" != "y" ] && [ "$n" != "Y" ]; then
82 die "Aborting..."
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
88 then
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."
98 return 0
101 _main() {
103 [ $# -ne 1 ] && safety_abort
105 case "$1" in
106 --full)
107 repair="full"
109 --status)
110 repair="status"
112 --autotag)
113 echo "Autotagging is no longer supported" >&2
116 usage
118 esac
120 oldrev=`git show-ref -s "refs/heads/\`git_branch\`"`
122 case "$repair" in
123 full)
124 repair_status
125 repair_pushed
127 status)
128 repair_status
131 die "Internal error"
133 esac
135 disp "Repair complete."
136 exit 0