Skip to content

Commit fd45f2a

Browse files
committed
t: add tests for .gitlocalignore
Exercise the new discoverable, local-only ignore file: gating via core.gitLocalIgnore, self-exclusion, precedence relative to info/exclude and core.excludesFile, root-only scoping, and that ignored files stay out of git status and cannot be added without -f. Signed-off-by: Shanthosh <shanthubolt@gmail.com>
1 parent 5a74b78 commit fd45f2a

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

t/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ integration_tests = [
8484
't0008-ignores.sh',
8585
't0009-git-dir-validation.sh',
8686
't0010-racy-git.sh',
87+
't0011-gitlocalignore.sh',
8788
't0012-help.sh',
8889
't0013-sha1dc.sh',
8990
't0014-alias.sh',

t/t0011-gitlocalignore.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
3+
test_description='.gitlocalignore support (core.gitLocalIgnore)'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
6+
. ./test-lib.sh
7+
8+
# off by default: .gitlocalignore is not consulted at all
9+
test_expect_success 'off by default: .gitlocalignore is ignored' '
10+
echo content >a.txt &&
11+
printf "a.txt\n" >.gitlocalignore &&
12+
test_must_fail git check-ignore a.txt
13+
'
14+
15+
test_expect_success 'core.gitLocalIgnore enables .gitlocalignore' '
16+
test_config core.gitLocalIgnore true &&
17+
echo content >b.txt &&
18+
printf "b.txt\n" >.gitlocalignore &&
19+
git check-ignore b.txt
20+
'
21+
22+
test_expect_success '.gitlocalignore is self-excluding' '
23+
test_config core.gitLocalIgnore true &&
24+
printf "b.txt\n" >.gitlocalignore &&
25+
git check-ignore .gitlocalignore
26+
'
27+
28+
test_expect_success 'info/exclude outranks .gitlocalignore' '
29+
test_config core.gitLocalIgnore true &&
30+
mkdir -p .git/info &&
31+
echo "c.txt" >.git/info/exclude &&
32+
echo content >c.txt &&
33+
printf "c.txt\n" >.gitlocalignore &&
34+
git check-ignore -v c.txt >out &&
35+
grep "info/exclude" out
36+
'
37+
38+
test_expect_success '.gitlocalignore outranks core.excludesFile' '
39+
test_config core.gitLocalIgnore true &&
40+
echo content >d.txt &&
41+
printf "d.txt\n" >.gitlocalignore &&
42+
echo "d.txt" >.git/excludes-extra &&
43+
test_config core.excludesFile "$(pwd)/.git/excludes-extra" &&
44+
git check-ignore -v d.txt >out &&
45+
grep "\.gitlocalignore" out
46+
'
47+
48+
test_expect_success 'nested .gitlocalignore contents are not read' '
49+
test_config core.gitLocalIgnore true &&
50+
rm -f .gitlocalignore &&
51+
mkdir -p sub &&
52+
echo content >sub/e.txt &&
53+
printf "e.txt\n" >sub/.gitlocalignore &&
54+
test_must_fail git check-ignore sub/e.txt
55+
'
56+
57+
test_expect_success 'ignored files stay out of git status' '
58+
test_config core.gitLocalIgnore true &&
59+
echo content >f.txt &&
60+
printf "f.txt\n" >.gitlocalignore &&
61+
git status --porcelain >out &&
62+
! grep f.txt out
63+
'
64+
65+
test_expect_success 'git add refuses .gitlocalignore unless forced' '
66+
test_config core.gitLocalIgnore true &&
67+
printf "f.txt\n" >.gitlocalignore &&
68+
test_must_fail git add .gitlocalignore &&
69+
git add -f .gitlocalignore &&
70+
git ls-files --error-unmatch .gitlocalignore
71+
'
72+
73+
test_done

0 commit comments

Comments
 (0)