forked from vitaly/guilt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguilt-fork
executable file
·48 lines (39 loc) · 1.05 KB
/
guilt-fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
#
# Copyright (c) Josef "Jeff" Sipek, 2007
#
USAGE="[<new_name>]"
. `dirname $0`/guilt
if [ $# -gt 1 ]; then
usage
fi
patch=`get_top`
if [ -z "$patch" ]; then
die "No patches are applied."
fi
# make sure that there are no unapplied changes
if ! must_commit_first; then
die "Uncommited changes detected. Refresh first."
fi
# Rename patches smartly
if [ $# -eq 1 ]; then
newpatch="$1"
else
base=$(echo "$patch" \
| sed -r -e 's:(\.diff?|\.patch)$::')
num=$(echo "$base" | sed -nre 's:.*-([0-9]+)$:\1:'p)
[ -n "$num" ] || num=1
newpatch="${base%-$num}-$(($num+1))${patch#$base}"
fi
if ! valid_patchname "$newpatch"; then
die "The specified patch name contains invalid characters (:)."
fi
if [ -e "$GUILT_DIR/$branch/$newpatch" ]; then
die "Patch \"$newpatch\" already exists. Choose another name."
fi
# copy the patch
cp "$GUILT_DIR/$branch/$patch" "$GUILT_DIR/$branch/$newpatch"
# replace the series & applied file references
series_rename_patch "$patch" "$newpatch"
applied_rename_patch "$patch" "$newpatch"
ref_rename_patch "$patch" "$newpatch"