doc: git doesn't use git-foo invocations.
[guilt.git] / guilt-fork
blob6447e550e7aba5e23e26984e4e1cb787c99c0c50
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007-2013
6 USAGE="[<new_name>]"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename "$0"` directly is no longer supported." >&2
9 exit 1
12 _main() {
14 if [ $# -gt 1 ]; then
15 usage
18 patch=`get_top`
19 if [ -z "$patch" ]; then
20 die "No patches are applied."
23 # make sure that there are no unapplied changes
24 if ! must_commit_first; then
25 die "Uncommited changes detected. Refresh first."
28 # Rename patches smartly
29 if [ $# -eq 1 ]; then
30 newpatch="$1"
31 else
32 base=$(echo "$patch" \
33 | sed -r -e 's:(\.diff?|\.patch)$::')
34 num=$(echo "$base" | sed -nre 's:.*-([0-9]+)$:\1:'p)
35 [ -n "$num" ] || num=1
36 newpatch="${base%-$num}-$(($num+1))${patch#$base}"
39 if ! valid_patchname "$newpatch"; then
40 die "The specified patch name is invalid according to git-check-ref-format(1)."
43 if [ -e "$GUILT_DIR/$branch/$newpatch" ]; then
44 die "Patch \"$newpatch\" already exists. Choose another name."
47 # copy the patch
48 cp "$GUILT_DIR/$branch/$patch" "$GUILT_DIR/$branch/$newpatch"
50 # replace the series & applied file references
51 series_rename_patch "$patch" "$newpatch"
52 applied_rename_patch "$patch" "$newpatch"
53 ref_rename_patch "$patch" "$newpatch"