wrapper for os-independent seq command
[guilt.git] / guilt-fork
blob32649fc73b95665b8c52b40335edec3c0ad4133d
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 ! valid_patchname "$newpatch"; then
35 die "The specified patch name contains invalid characters (:)."
38 if [ -e "$GUILT_DIR/$branch/$newpatch" ]; then
39 die "Patch \"$newpatch\" already exists. Choose another name."
42 # copy the patch
43 cp "$GUILT_DIR/$branch/$patch" "$GUILT_DIR/$branch/$newpatch"
45 # replace the series & applied file references
46 series_rename_patch "$patch" "$newpatch"
47 applied_rename_patch "$patch" "$newpatch"
48 ref_rename_patch "$patch" "$newpatch"