repair: new command to repair repository state
[guilt.git] / guilt-fork
blob32b31dcd8e16b685ee65c463a125a38a3e705a90
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007
6 USAGE="[<new_name>]"
7 . `dirname $0`/guilt
9 if [ $# -gt 1 ]; then
10 usage
13 patch=`get_top`
14 if [ -z "$patch" ]; then
15 die "No patches are applied."
18 # make sure that there are no unapplied changes
19 if ! must_commit_first; then
20 die "Uncommited changes detected. Refresh first."
23 # Rename patches smartly
24 if [ $# -eq 1 ]; then
25 newpatch="$1"
26 else
27 base=$(echo "$patch" \
28 | sed -r -e 's:(\.diff?|\.patch)$::')
29 num=$(echo "$base" | sed -nre 's:.*-([0-9]+)$:\1:'p)
30 [ -n "$num" ] || num=1
31 newpatch="${base%-$num}-$(($num+1))${patch#$base}"
34 if [ -e "$GUILT_DIR/$branch/$newpatch" ]; then
35 die "Patch \"$newpatch\" already exists. Choose another name."
38 # copy the patch
39 cp "$GUILT_DIR/$branch/$patch" "$GUILT_DIR/$branch/$newpatch"
41 # replace the series & applied file references
42 series_rename_patch "$patch" "$newpatch"
43 applied_rename_patch "$patch" "$newpatch"