Skip to content

Commit 1b471a6

Browse files
committed
Escape characters from tags that have special meaning in grep.
In particular, this fixes the case where a dot in a version name (not too uncommon ;)) unintentionally matches a pre-existing tag. For example, if these tags exist: 1.0.1 1.0b2 And you try to start a new release for 1.0.2, git-flow prevented it, since the '.' matches the 'b' in 1.0b2. This resulted in the invalid error message: Tag '1.0.2' already exists. Pick another name.
1 parent 0f74cf4 commit 1b471a6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

gitflow-common

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@
4444
warn() { echo "$@" >&2; }
4545
die() { warn "$@"; exit 1; }
4646

47+
escape() {
48+
echo "$1" | sed 's/\([\.\+\$\*]\)/\\\1/g'
49+
}
50+
4751
# set logic
4852
has() {
4953
local item=$1; shift
50-
echo " $@ " | grep -q " $item "
54+
echo " $@ " | grep -q " $(escape $item) "
5155
}
5256

5357
# basic math
@@ -211,7 +215,7 @@ gitflow_resolve_nameprefix() {
211215
return 0
212216
fi
213217

214-
matches=$(echo "$(git_local_branches)" | grep "^$prefix$name")
218+
matches=$(echo "$(git_local_branches)" | grep "^$(escape "$prefix$name")")
215219
num_matches=$(echo "$matches" | wc -l)
216220
if [ -z "$matches" ]; then
217221
# no prefix match, so take it literally

0 commit comments

Comments
 (0)