@@ -234,6 +234,18 @@ __git_dequote ()
done
}
+# Escapes special characters in a string to pass to fnmatch(3)
+# 1: String to escape.
+__git_escape_fnmatch ()
+{
+ local s="$1"
+ s=${s//\\/\\\\}
+ s=${s//\?/\\\?}
+ s=${s//\*/\\\*}
+ s=${s//\[/\\\[}
+ printf '%s\n' "$s"
+}
+
# The following function is based on code from:
#
# bash_completion - programmable completion functions for bash 3.2+
@@ -455,6 +455,13 @@ test_expect_success '__git_dequote - open double quote' '
'
+test_expect_success '__git_escape_fnmatch' '
+ echo '\''foo\\\?\*\['\'' >expected &&
+ __git_escape_fnmatch '\''foo\?*['\'' >"$actual" &&
+ test_cmp expected "$actual"
+'
+
+
test_expect_success '__gitcomp_direct - puts everything into COMPREPLY as-is' '
sed -e "s/Z$//g" >expected <<-EOF &&
with-trailing-space Z