pathspec: make --literal-pathspecs disable pathspec magic

--literal-pathspecs and its equivalent environment variable are probably used for scripting. In that setting, pathspec magic may be unwanted. Disabling globbing in individual pathspec can be done via :(literal) magic. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jul 14, 2013 at 15:36 UTC a16bf9dd745a9e43e46d745d850db49358430e46
3 files changed +9 -3
Documentation/git.txt
+2 -2
@@ -450,8 +450,8 @@ help ...`.
450 linkgit:git-replace[1] for more information.
451
452 --literal-pathspecs::
453 - Treat pathspecs literally, rather than as glob patterns. This is
454 - equivalent to setting the `GIT_LITERAL_PATHSPECS` environment
453 + Treat pathspecs literally (i.e. no globbing, no pathspec magic).
454 + This is equivalent to setting the `GIT_LITERAL_PATHSPECS` environment
455 variable to `1`.
456
457
pathspec.c
+1 -1
@@ -103,7 +103,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
103 if (literal_global)
104 global_magic |= PATHSPEC_LITERAL;
105
106 - if (elt[0] != ':') {
106 + if (elt[0] != ':' || literal_global) {
107 ; /* nothing to do */
108 } else if (elt[1] == '(') {
109 /* longhand */
t/t6130-pathspec-noglob.sh
+6
@@ -77,6 +77,12 @@ test_expect_success 'no-glob option matches literally (bracket)' '
77 test_cmp expect actual
78 '
79
80 +test_expect_success 'no-glob option disables :(literal)' '
81 + : >expect &&
82 + git --literal-pathspecs log --format=%s -- ":(literal)foo" >actual &&
83 + test_cmp expect actual
84 +'
85 +
86 test_expect_success 'no-glob environment variable works' '
87 echo star >expect &&
88 GIT_LITERAL_PATHSPECS=1 git log --format=%s -- "f*" >actual &&