Skip to content

Commit a16bf9d

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5c6933d commit a16bf9d

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Documentation/git.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ help ...`.
450450
linkgit:git-replace[1] for more information.
451451

452452
--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
455455
variable to `1`.
456456

457457

pathspec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
103103
if (literal_global)
104104
global_magic |= PATHSPEC_LITERAL;
105105

106-
if (elt[0] != ':') {
106+
if (elt[0] != ':' || literal_global) {
107107
; /* nothing to do */
108108
} else if (elt[1] == '(') {
109109
/* longhand */

t/t6130-pathspec-noglob.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ test_expect_success 'no-glob option matches literally (bracket)' '
7777
test_cmp expect actual
7878
'
7979

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+
8086
test_expect_success 'no-glob environment variable works' '
8187
echo star >expect &&
8288
GIT_LITERAL_PATHSPECS=1 git log --format=%s -- "f*" >actual &&

0 commit comments

Comments
 (0)