@@ -18,10 +18,10 @@ FLAG_FETCH=0
18
18
usage() {
19
19
echo "usage: git flow feature [list]"
20
20
echo " git flow feature start <name> [<base>]"
21
- echo " git flow feature finish <name> [<base>]"
21
+ echo " git flow feature finish <name|nameprefix > [<base>]"
22
22
echo " git flow feature publish <name>"
23
23
echo " git flow feature track <name>"
24
- echo " git flow feature diff <name>"
24
+ echo " git flow feature diff <name|nameprefix >"
25
25
# TODO
26
26
#echo ""
27
27
#echo "options:"
@@ -55,12 +55,44 @@ cmd_help() {
55
55
exit 0
56
56
}
57
57
58
- parse_args() {
58
+ resolve_name_by_prefix() {
59
+ # first, check if there is a perfect match
60
+ if has "$LOCAL_BRANCHES" "$PREFIX$1"; then
61
+ echo "$1"
62
+ return 0
63
+ fi
64
+
65
+ MATCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX$1")"
66
+ NUM_MATCHES=$(echo "$MATCHES" | wc -l)
67
+ if [ $NUM_MATCHES -eq 1 ]; then
68
+ # sed arg looks a bit weird, but $PREFIX should not contain spaces,
69
+ # so this one is safe
70
+ echo "$MATCHES" | sed "s $PREFIX g"
71
+ elif [ $NUM_MATCHES -eq 0 ]; then
72
+ # no prefix match, so take it literally
73
+ echo "$1"
74
+ else
75
+ # multiple matches, cannot decide
76
+ warn "Multiple branches match for prefix '$1':"
77
+ for match in $MATCHES; do
78
+ warn "- $match"
79
+ done
80
+ die "Aborting. Use an unambiguous prefix."
81
+ fi
82
+ }
83
+
84
+ get_name_by_prefix() {
85
+ NAME=$(resolve_name_by_prefix "$1")
86
+ if [ -z "$NAME" ]; then
87
+ exit 1
88
+ fi
89
+ }
90
+
91
+ parse_args_common() {
59
92
# TODO: When we have a nice structured way of parsing flags with getopt,
60
93
# implement the following flags:
61
94
# --fetch, to set FLAG_FETCH=1
62
95
# --no-fetch, to set FLAG_FETCH=0
63
- NAME="$1"
64
96
BASE="${2:-$DEVELOP_BRANCH}"
65
97
if [ "$NAME" = "" ]; then
66
98
echo "Missing argument <name>."
@@ -70,6 +102,16 @@ parse_args() {
70
102
BRANCH=$PREFIX$NAME
71
103
}
72
104
105
+ parse_args_with_name_prefix() {
106
+ get_name_by_prefix "$1"
107
+ parse_args_common
108
+ }
109
+
110
+ parse_args() {
111
+ NAME="$1"
112
+ parse_args_common
113
+ }
114
+
73
115
cmd_start() {
74
116
parse_args "$@"
75
117
@@ -99,7 +141,7 @@ cmd_start() {
99
141
}
100
142
101
143
cmd_finish() {
102
- parse_args "$@"
144
+ parse_args_with_name_prefix "$@"
103
145
104
146
# sanity checks
105
147
gitflow_require_branch $BRANCH
@@ -251,7 +293,7 @@ cmd_track() {
251
293
}
252
294
253
295
cmd_diff() {
254
- parse_args "$@"
296
+ parse_args_with_name_prefix "$@"
255
297
# TODO: if this feature has been based on a non-develop branch, we really
256
298
# should not be comparing to $DEVELOP. How to deal with this?
257
299
git diff $DEVELOP_BRANCH..$BRANCH
0 commit comments