Skip to content

Commit bcbbe4f

Browse files
committed
Merge branch 'jk/maint-add-ignored-dir' into maint
* jk/maint-add-ignored-dir: tests for "git add ignored-dir/file" without -f dir: fix COLLECT_IGNORED on excluded prefixes t0050: mark non-working test as such
2 parents 7b676b1 + b75aea8 commit bcbbe4f

File tree

3 files changed

+103
-4
lines changed

3 files changed

+103
-4
lines changed

dir.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,29 @@ static int simplify_away(const char *path, int pathlen, const struct path_simpli
594594
return 0;
595595
}
596596

597-
static int in_pathspec(const char *path, int len, const struct path_simplify *simplify)
597+
/*
598+
* This function tells us whether an excluded path matches a
599+
* list of "interesting" pathspecs. That is, whether a path matched
600+
* by any of the pathspecs could possibly be ignored by excluding
601+
* the specified path. This can happen if:
602+
*
603+
* 1. the path is mentioned explicitly in the pathspec
604+
*
605+
* 2. the path is a directory prefix of some element in the
606+
* pathspec
607+
*/
608+
static int exclude_matches_pathspec(const char *path, int len,
609+
const struct path_simplify *simplify)
598610
{
599611
if (simplify) {
600612
for (; simplify->path; simplify++) {
601613
if (len == simplify->len
602614
&& !memcmp(path, simplify->path, len))
603615
return 1;
616+
if (len < simplify->len
617+
&& simplify->path[len] == '/'
618+
&& !memcmp(path, simplify->path, len))
619+
return 1;
604620
}
605621
}
606622
return 0;
@@ -678,7 +694,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
678694
{
679695
int exclude = excluded(dir, path, &dtype);
680696
if (exclude && (dir->flags & DIR_COLLECT_IGNORED)
681-
&& in_pathspec(path, *len, simplify))
697+
&& exclude_matches_pathspec(path, *len, simplify))
682698
dir_add_ignored(dir, path, *len);
683699

684700
/*

t/t0050-filesystem.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,17 @@ $test_case 'merge (case change)' '
108108
109109
'
110110

111-
$test_case 'add (with different case)' '
111+
112+
113+
test_expect_failure 'add (with different case)' '
112114
113115
git reset --hard initial &&
114116
rm camelcase &&
115117
echo 1 >CamelCase &&
116118
git add CamelCase &&
117-
test $(git ls-files | grep -i camelcase | wc -l) = 1
119+
camel=$(git ls-files | grep -i camelcase) &&
120+
test $(echo "$camel" | wc -l) = 1 &&
121+
test "z$(git cat-file blob :$camel)" = z1
118122
119123
'
120124

t/t2204-add-ignored.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/sh
2+
3+
test_description='giving ignored paths to git add'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success setup '
8+
mkdir sub dir dir/sub &&
9+
echo sub >.gitignore &&
10+
echo ign >>.gitignore &&
11+
for p in . sub dir dir/sub
12+
do
13+
>"$p/ign" &&
14+
>"$p/file" || exit 1
15+
done
16+
'
17+
18+
for i in file dir/file dir 'd*'
19+
do
20+
test_expect_success "no complaints for unignored $i" '
21+
rm -f .git/index &&
22+
git add "$i" &&
23+
git ls-files "$i" >out &&
24+
test -s out
25+
'
26+
done
27+
28+
for i in ign dir/ign dir/sub dir/sub/*ign sub/file sub sub/*
29+
do
30+
test_expect_success "complaints for ignored $i" '
31+
rm -f .git/index &&
32+
test_must_fail git add "$i" 2>err &&
33+
git ls-files "$i" >out &&
34+
! test -s out &&
35+
grep -e "Use -f if" err &&
36+
cat err
37+
'
38+
39+
test_expect_success "complaints for ignored $i with unignored file" '
40+
rm -f .git/index &&
41+
test_must_fail git add "$i" file 2>err &&
42+
git ls-files "$i" >out &&
43+
! test -s out &&
44+
grep -e "Use -f if" err &&
45+
cat err
46+
'
47+
done
48+
49+
for i in sub sub/*
50+
do
51+
test_expect_success "complaints for ignored $i in dir" '
52+
rm -f .git/index &&
53+
(
54+
cd dir &&
55+
test_must_fail git add "$i" 2>err &&
56+
git ls-files "$i" >out &&
57+
! test -s out &&
58+
grep -e "Use -f if" err &&
59+
cat err
60+
)
61+
'
62+
done
63+
64+
for i in ign file
65+
do
66+
test_expect_success "complaints for ignored $i in sub" '
67+
rm -f .git/index &&
68+
(
69+
cd sub &&
70+
test_must_fail git add "$i" 2>err &&
71+
git ls-files "$i" >out &&
72+
! test -s out &&
73+
grep -e "Use -f if" err &&
74+
cat err
75+
)
76+
'
77+
done
78+
79+
test_done

0 commit comments

Comments
 (0)