mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
![Elijah Newren](/assets/img/avatar_default.png)
Our optimization to avoid calling into read_directory_recursive() when all pathspecs have a common leading directory mean that we need to match the logic that read_directory_recursive() would use if we had just called it from the root. Since it does more than call treat_path() we need to copy that same logic. Alternatively, we could try to change treat_path to return path_recurse for an untracked directory under the given special circumstances that this logic checks for, but a simple switch results in many test failures such as 'git clean -d' not wiping out untracked but empty directories. To work around that, we'd need the caller of treat_path to check for path_recurse and sometimes special case it into path_untracked. In other words, we'd still have extra logic in both places. Needing to duplicate logic like this means it is guaranteed someone will eventually need to make further changes and forget to update both locations. It is tempting to just nuke the leading_directory special casing to avoid such bugs and simplify the code, but unpack_trees' verify_clean_subdirectory() also calls read_directory() and does so with a non-empty leading path, so I'm hesitant to try to restructure further. Add obnoxious warnings to treat_leading_path() and read_directory_recursive() to try to warn people of such problems. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
292 lines
6.2 KiB
Bash
Executable file
292 lines
6.2 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='git-status ignored files'
|
|
|
|
. ./test-lib.sh
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
?? untracked/
|
|
!! untracked/ignored
|
|
EOF
|
|
|
|
test_expect_success 'status untracked directory with --ignored' '
|
|
echo "ignored" >.gitignore &&
|
|
mkdir untracked &&
|
|
: >untracked/ignored &&
|
|
: >untracked/uncommitted &&
|
|
git status --porcelain --ignored >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_expect_success 'same with gitignore starting with BOM' '
|
|
printf "\357\273\277ignored\n" >.gitignore &&
|
|
mkdir -p untracked &&
|
|
: >untracked/ignored &&
|
|
: >untracked/uncommitted &&
|
|
git status --porcelain --ignored >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
?? untracked/uncommitted
|
|
!! untracked/ignored
|
|
EOF
|
|
|
|
test_expect_success 'status untracked directory with --ignored -u' '
|
|
git status --porcelain --ignored -u >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
cat >expected <<\EOF
|
|
?? untracked/
|
|
!! untracked/ignored
|
|
EOF
|
|
|
|
test_expect_success 'status of untracked directory with --ignored works with or without prefix' '
|
|
git status --porcelain --ignored >tmp &&
|
|
grep untracked/ tmp >actual &&
|
|
rm tmp &&
|
|
test_cmp expected actual &&
|
|
|
|
git status --porcelain --ignored untracked/ >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? untracked/uncommitted
|
|
!! untracked/ignored
|
|
EOF
|
|
|
|
test_expect_success 'status prefixed untracked sub-directory with --ignored -u' '
|
|
git status --porcelain --ignored -u untracked/ >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
!! ignored/
|
|
EOF
|
|
|
|
test_expect_success 'status ignored directory with --ignore' '
|
|
rm -rf untracked &&
|
|
mkdir ignored &&
|
|
: >ignored/uncommitted &&
|
|
git status --porcelain --ignored >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
!! ignored/uncommitted
|
|
EOF
|
|
|
|
test_expect_success 'status ignored directory with --ignore -u' '
|
|
git status --porcelain --ignored -u >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
EOF
|
|
|
|
test_expect_success 'status empty untracked directory with --ignore' '
|
|
rm -rf ignored &&
|
|
mkdir untracked-ignored &&
|
|
mkdir untracked-ignored/test &&
|
|
git status --porcelain --ignored >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
EOF
|
|
|
|
test_expect_success 'status empty untracked directory with --ignore -u' '
|
|
git status --porcelain --ignored -u >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
!! untracked-ignored/
|
|
EOF
|
|
|
|
test_expect_success 'status untracked directory with ignored files with --ignore' '
|
|
: >untracked-ignored/ignored &&
|
|
: >untracked-ignored/test/ignored &&
|
|
git status --porcelain --ignored >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
!! untracked-ignored/ignored
|
|
!! untracked-ignored/test/ignored
|
|
EOF
|
|
|
|
test_expect_success 'status untracked directory with ignored files with --ignore -u' '
|
|
git status --porcelain --ignored -u >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
EOF
|
|
|
|
test_expect_success 'status ignored tracked directory with --ignore' '
|
|
rm -rf untracked-ignored &&
|
|
mkdir tracked &&
|
|
: >tracked/committed &&
|
|
git add tracked/committed &&
|
|
git commit -m. &&
|
|
echo "tracked" >.gitignore &&
|
|
git status --porcelain --ignored >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
EOF
|
|
|
|
test_expect_success 'status ignored tracked directory with --ignore -u' '
|
|
git status --porcelain --ignored -u >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
EOF
|
|
|
|
test_expect_success 'status ignored tracked directory and ignored file with --ignore' '
|
|
echo "committed" >>.gitignore &&
|
|
git status --porcelain --ignored >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
EOF
|
|
|
|
test_expect_success 'status ignored tracked directory and ignored file with --ignore -u' '
|
|
git status --porcelain --ignored -u >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
!! tracked/uncommitted
|
|
EOF
|
|
|
|
test_expect_success 'status ignored tracked directory and uncommitted file with --ignore' '
|
|
echo "tracked" >.gitignore &&
|
|
: >tracked/uncommitted &&
|
|
git status --porcelain --ignored >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
!! tracked/uncommitted
|
|
EOF
|
|
|
|
test_expect_success 'status ignored tracked directory and uncommitted file with --ignore -u' '
|
|
git status --porcelain --ignored -u >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
!! tracked/ignored/
|
|
EOF
|
|
|
|
test_expect_success 'status ignored tracked directory with uncommitted file in untracked subdir with --ignore' '
|
|
rm -rf tracked/uncommitted &&
|
|
mkdir tracked/ignored &&
|
|
: >tracked/ignored/uncommitted &&
|
|
git status --porcelain --ignored >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
!! tracked/ignored/uncommitted
|
|
EOF
|
|
|
|
test_expect_success 'status ignored tracked directory with uncommitted file in untracked subdir with --ignore -u' '
|
|
git status --porcelain --ignored -u >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
!! tracked/ignored/uncommitted
|
|
EOF
|
|
|
|
test_expect_success 'status ignored tracked directory with uncommitted file in tracked subdir with --ignore' '
|
|
: >tracked/ignored/committed &&
|
|
git add -f tracked/ignored/committed &&
|
|
git commit -m. &&
|
|
git status --porcelain --ignored >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
?? .gitignore
|
|
?? actual
|
|
?? expected
|
|
!! tracked/ignored/uncommitted
|
|
EOF
|
|
|
|
test_expect_success 'status ignored tracked directory with uncommitted file in tracked subdir with --ignore -u' '
|
|
git status --porcelain --ignored -u >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
cat >expected <<\EOF
|
|
!! tracked/submodule/
|
|
EOF
|
|
|
|
test_expect_success 'status ignores submodule in excluded directory' '
|
|
git init tracked/submodule &&
|
|
test_commit -C tracked/submodule initial &&
|
|
git status --porcelain --ignored -u tracked/submodule >actual &&
|
|
test_cmp expected actual
|
|
'
|
|
|
|
test_done
|