Skip to content

Commit

Permalink
pathspec: make --literal-pathspecs disable pathspec magic
Browse files Browse the repository at this point in the history
--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>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Jul 15, 2013
1 parent 5c6933d commit a16bf9d
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Documentation/git.txt
Original file line number Diff line number Diff line change
@@ -450,8 +450,8 @@ help ...`.
linkgit:git-replace[1] for more information.

--literal-pathspecs::
Treat pathspecs literally, rather than as glob patterns. This is
equivalent to setting the `GIT_LITERAL_PATHSPECS` environment
Treat pathspecs literally (i.e. no globbing, no pathspec magic).
This is equivalent to setting the `GIT_LITERAL_PATHSPECS` environment
variable to `1`.


2 changes: 1 addition & 1 deletion pathspec.c
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
if (literal_global)
global_magic |= PATHSPEC_LITERAL;

if (elt[0] != ':') {
if (elt[0] != ':' || literal_global) {
; /* nothing to do */
} else if (elt[1] == '(') {
/* longhand */
6 changes: 6 additions & 0 deletions t/t6130-pathspec-noglob.sh
Original file line number Diff line number Diff line change
@@ -77,6 +77,12 @@ test_expect_success 'no-glob option matches literally (bracket)' '
test_cmp expect actual
'

test_expect_success 'no-glob option disables :(literal)' '
: >expect &&
git --literal-pathspecs log --format=%s -- ":(literal)foo" >actual &&
test_cmp expect actual
'

test_expect_success 'no-glob environment variable works' '
echo star >expect &&
GIT_LITERAL_PATHSPECS=1 git log --format=%s -- "f*" >actual &&

0 comments on commit a16bf9d

Please sign in to comment.