Skip to contentSkip to conversation

tree_entry_interesting: match against all pathspecs

PATCH In review Andy Spencer 3 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tree_entry_interesting: match against all pathspecs

The current basedir compare aborts early in order to avoid futile recursive searches. However, a match may still be found by another pathspec. This can cause an error while checking out files from a branch when using multiple pathspecs:

$ git checkout master -- 'a/*.txt' 'b/*.txt'
error: pathspec 'a/*.txt' did not match any file(s) known to git.
---
 tree-walk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tree-walk.c +1 -1
index 5ece8c3..e06f240 100644
@@ -743,7 +743,7 @@ match_wildcards:
 
 		if (item->nowildcard_len &&
 		    !match_wildcard_base(item, base_str, baselen, &matched))
-			return entry_not_interesting;
+			continue;
 
 		/*
 		 * Concatenate base and entry->path into one and do
Signature · 1 line
1.8.5.3
#1 lore raw
Quoted 18 lines · Andy Spencer

The current basedir compare aborts early in order to avoid futile recursive searches. However, a match may still be found by another pathspec. This can cause an error while checking out files from a branch when using multiple pathspecs:

$ git checkout master -- 'a/*.txt' 'b/*.txt'
error: pathspec 'a/*.txt' did not match any file(s) known to git.
---
 tree-walk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tree-walk.c +0 -0
index 5ece8c3..e06f240 100644

tree-walk.c match_wildcards: · line 749

Quoted 8 lines
tree-walk.c +1 -1
@@ -743,7 +743,7 @@ match_wildcards:
 
 		if (item->nowildcard_len &&
 		    !match_wildcard_base(item, base_str, baselen, &matched))
-			return entry_not_interesting;
+			continue;
 
 		/*
 		 * Concatenate base and entry->path into one and do

Ack. Perhaps this on top to verify it

-- 8< --

t/t4010-diff-pathspec.sh +13 -0
index af5134b..d9f37c3 100755
@@ -110,4 +110,17 @@ test_expect_success 'diff-tree -r with wildcard' '
 	test_cmp expected result
 '
 
+test_expect_success 'diff multiple wildcard pathspecs' '
+	mkdir path2 &&
+	echo rezrov >path2/file1 &&
+	git update-index --add path2/file1 &&
+	tree3=`git write-tree` &&
+	git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
+	cat <<EOF >expect &&
+path1/file1
+path2/file1
+EOF
+	test_cmp expect actual
+'
+
 test_done

-- 8< --

#2 lore raw
Quoted 16 lines · Duy Nguyen

Ack. Perhaps this on top to verify it

-- 8< --

t/t4010-diff-pathspec.sh +5 -0
index af5134b..d9f37c3 100755
@@ -110,4 +110,17 @@ test_expect_success 'diff-tree -r with wildcard' '
 	test_cmp expected result
 '
 
+test_expect_success 'diff multiple wildcard pathspecs' '
+	mkdir path2 &&
+	echo rezrov >path2/file1 &&
+	git update-index --add path2/file1 &&
+	tree3=`git write-tree` &&

t/t4010-diff-pathspec.sh test_expect_success 'diff-tree -r with wildcard' '

Quoted 10 lines
t/t4010-diff-pathspec.sh +8 -1
+	git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
+	cat <<EOF >expect &&
+path1/file1
+path2/file1
+EOF
+	test_cmp expect actual
+'
+
 test_done
-- 8< --

Thanks, both. Will queue.