graph: Remove graph cache after command terminates
[guilt.git] / guilt-fork
blob426a7e7389d8a2f3a8920e928a82926a35f71071
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2007
6 USAGE="[<new_name>]"
7 . 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"