Permalink
Browse files

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.
  • Loading branch information...
nvie committed Feb 4, 2011
1 parent 0f74cf4 commit 1b471a66b43ee95067b53937c62dc42d4bc561e6
Showing with 6 additions and 2 deletions.
  1. +6 −2 gitflow-common
View
@@ -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 @@ gitflow_resolve_nameprefix() {
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

0 comments on commit 1b471a6

Please sign in to comment.