Skip to content

Commit 35a9f1e

Browse files
szedergitster
authored andcommitted
tree-walk.c: don't match submodule entries for 'submod/anything'
Submodules should be handled the same as regular directories with respect to the presence of a trailing slash, i.e. commands like: git diff rev1 rev2 -- $path git rev-list HEAD -- $path should produce the same output whether $path is 'submod' or 'submod/'. This has been fixed in commit 74b4f7f (tree-walk.c: ignore trailing slash on submodule in tree_entry_interesting(), 2014-01-23). Unfortunately, that commit had the unintended side effect to handle 'submod/anything' the same as 'submod' and 'submod/' as well, e.g.: $ git log --oneline --name-only -- sha1collisiondetection/whatever 4125f78 sha1dc: update from upstream sha1collisiondetection 07a20f5 Makefile: fix unaligned loads in sha1dc with UBSan sha1collisiondetection 23e37f8 sha1dc: update from upstream sha1collisiondetection 86cfd61 sha1dc: optionally use sha1collisiondetection as a submodule sha1collisiondetection Fix this by rejecting submodules as partial pathnames when their trailing slash is followed by anything. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f32dde8 commit 35a9f1e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

t/t4010-diff-pathspec.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ test_expect_success 'setup submodules' '
125125
test_expect_success 'diff-tree ignores trailing slash on submodule path' '
126126
git diff --name-only HEAD^ HEAD submod >expect &&
127127
git diff --name-only HEAD^ HEAD submod/ >actual &&
128-
test_cmp expect actual
128+
test_cmp expect actual &&
129+
git diff --name-only HEAD^ HEAD -- submod/whatever >actual &&
130+
test_must_be_empty actual
129131
'
130132

131133
test_expect_success 'diff multiple wildcard pathspecs' '

tree-walk.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,14 @@ static int match_entry(const struct pathspec_item *item,
851851
if (matchlen > pathlen) {
852852
if (match[pathlen] != '/')
853853
return 0;
854-
if (!S_ISDIR(entry->mode) && !S_ISGITLINK(entry->mode))
854+
/*
855+
* Reject non-directories as partial pathnames, except
856+
* when match is a submodule with a trailing slash and
857+
* nothing else (to handle 'submod/' and 'submod'
858+
* uniformly).
859+
*/
860+
if (!S_ISDIR(entry->mode) &&
861+
(!S_ISGITLINK(entry->mode) || matchlen > pathlen + 1))
855862
return 0;
856863
}
857864

0 commit comments

Comments
 (0)