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.
diff --git a/gitflow-common b/gitflow-common
index c58cca0..75eb210 100644
--- a/gitflow-common
+++ b/gitflow-common
@@ -44,10 +44,14 @@
warn() { echo "$@" >&2; }
die() { warn "$@"; exit 1; }
+escape() {
+ echo "$1" | sed 's/\([\.\+\$\*]\)/\\\1/g'
+}
+
# set logic
has() {
local item=$1; shift
- echo " $@ " | grep -q " $item "
+ echo " $@ " | grep -q " $(escape $item) "
}
# basic math
@@ -211,7 +215,7 @@
return 0
fi
- matches=$(echo "$(git_local_branches)" | grep "^$prefix$name")
+ matches=$(echo "$(git_local_branches)" | grep "^$(escape "$prefix$name")")
num_matches=$(echo "$matches" | wc -l)
if [ -z "$matches" ]; then
# no prefix match, so take it literally