|
| 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