forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Teach status to show ignored directories with all untracked files
The git status command exposes the option to report ignored and untracked files. When reporting untracked files, it can report untracked files (--untracked=all), but this results in all ignored files being reported as well. This teaches Git to optionally show all untracked files, but not show individual ignored files contained in directories that match an ignore rule. Motivation: Our application (Visual Studio) needs all untracked files listed individually, but does not need all ignored files listed individually. Reporting all ignored files can affect the time it takes for status to run. For a representative repository, here are some measurements showing a large perf improvement for this scenario: | Command | Reported ignored entries | Time (s) | | ------- | ------------------------ | -------- | | 1 | 0 | 1.3 | | 2 | 1024 | 4.2 | | 3 | 174904 | 7.5 | | 4 | 1046 | 1.6 | Commands: 1) status 2) status --ignored 3) status --ignored --untracked-files=all 4) status --ignored --untracked-files=all --show-ignored-directory This changes exposes a --show-ignored-directory flag to the git status command. This flag is utilized when running git status with the --ignored and --untracked-files options to not list ignored individual ignored files contained in directories that match an ignore pattern. Part of the perf improvement comes from the tweak to read_directory_recursive to stop scanning the file system after it encounters the first file. When a directory is ignored, all it needs to determine is if the directory is empty or not. The logic currently keeps scanning the file system until it finds an untracked file. However, as the directory is ignored, all the contained contents are also marked excluded. For ignored directories that contain a large number of files, this can take some time. Signed-off-by: Jameson Miller <[email protected]>
- Loading branch information
Showing
8 changed files
with
213 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#!/bin/sh | ||
# | ||
# | ||
|
||
test_description='git status collapse ignored' | ||
|
||
. ./test-lib.sh | ||
|
||
|
||
cat >.gitignore <<\EOF | ||
*.ign | ||
ignored_dir/ | ||
!*.unignore | ||
EOF | ||
|
||
# commit initial ignore file | ||
test_expect_success 'setup initial commit and ignore file' ' | ||
git add . && | ||
test_tick && | ||
git commit -m "Initial commit" | ||
' | ||
|
||
cat >expect <<\EOF | ||
? expect | ||
? output | ||
! dir/ignored/ignored_1.ign | ||
! dir/ignored/ignored_2.ign | ||
! ignored/ignored_1.ign | ||
! ignored/ignored_2.ign | ||
EOF | ||
|
||
# Test status behavior on folder with ignored files | ||
test_expect_success 'setup folder with ignored files' ' | ||
mkdir -p ignored dir/ignored && | ||
touch ignored/ignored_1.ign ignored/ignored_2.ign \ | ||
dir/ignored/ignored_1.ign dir/ignored/ignored_2.ign | ||
' | ||
|
||
test_expect_success 'Verify behavior of status on folders with ignored files' ' | ||
test_when_finished "git clean -fdx" && | ||
git status --porcelain=v2 --ignored --untracked-files=all --show-ignored-directory >output && | ||
test_i18ncmp expect output | ||
' | ||
|
||
# Test status bahavior on folder with tracked and ignored files | ||
cat >expect <<\EOF | ||
? expect | ||
? output | ||
! dir/tracked_ignored/ignored_1.ign | ||
! dir/tracked_ignored/ignored_2.ign | ||
! tracked_ignored/ignored_1.ign | ||
! tracked_ignored/ignored_2.ign | ||
EOF | ||
|
||
test_expect_success 'setup folder with tracked & ignored files' ' | ||
mkdir -p tracked_ignored dir/tracked_ignored && | ||
touch tracked_ignored/tracked_1 tracked_ignored/tracked_2 \ | ||
tracked_ignored/ignored_1.ign tracked_ignored/ignored_2.ign \ | ||
dir/tracked_ignored/tracked_1 dir/tracked_ignored/tracked_2 \ | ||
dir/tracked_ignored/ignored_1.ign dir/tracked_ignored/ignored_2.ign && | ||
git add tracked_ignored/tracked_1 tracked_ignored/tracked_2 \ | ||
dir/tracked_ignored/tracked_1 dir/tracked_ignored/tracked_2 && | ||
test_tick && | ||
git commit -m "commit tracked files" | ||
' | ||
|
||
test_expect_success 'Verify status on folder with tracked & ignored files' ' | ||
test_when_finished "git clean -fdx && git reset HEAD~1 --hard" && | ||
git status --porcelain=v2 --ignored --untracked-files=all --show-ignored-directory >output && | ||
test_i18ncmp expect output | ||
' | ||
|
||
|
||
# Test status behavior on folder with untracked and ignored files | ||
cat >expect <<\EOF | ||
? dir/untracked_ignored/untracked_1 | ||
? dir/untracked_ignored/untracked_2 | ||
? expect | ||
? output | ||
? untracked_ignored/untracked_1 | ||
? untracked_ignored/untracked_2 | ||
! dir/untracked_ignored/ignored_1.ign | ||
! dir/untracked_ignored/ignored_2.ign | ||
! untracked_ignored/ignored_1.ign | ||
! untracked_ignored/ignored_2.ign | ||
EOF | ||
|
||
test_expect_success 'setup folder with tracked & ignored files' ' | ||
mkdir -p untracked_ignored dir/untracked_ignored && | ||
touch untracked_ignored/untracked_1 untracked_ignored/untracked_2 \ | ||
untracked_ignored/ignored_1.ign untracked_ignored/ignored_2.ign \ | ||
dir/untracked_ignored/untracked_1 dir/untracked_ignored/untracked_2 \ | ||
dir/untracked_ignored/ignored_1.ign dir/untracked_ignored/ignored_2.ign | ||
' | ||
|
||
test_expect_success 'Verify status on folder with tracked & ignored files' ' | ||
test_when_finished "git clean -fdx" && | ||
git status --porcelain=v2 --ignored --untracked-files=all --show-ignored-directory >output && | ||
test_i18ncmp expect output | ||
' | ||
|
||
# Test status behavior on ignored folder | ||
cat >expect <<\EOF | ||
? expect | ||
? output | ||
! ignored_dir/ | ||
EOF | ||
|
||
test_expect_success 'setup folder with tracked & ignored files' ' | ||
mkdir ignored_dir && | ||
touch ignored_dir/ignored_1 ignored_dir/ignored_2 \ | ||
ignored_dir/ignored_1.ign ignored_dir/ignored_2.ign | ||
' | ||
|
||
test_expect_success 'Verify status on folder with tracked & ignored files' ' | ||
test_when_finished "git clean -fdx" && | ||
git status --porcelain=v2 --ignored --untracked-files=all --show-ignored-directory >output && | ||
test_i18ncmp expect output | ||
' | ||
|
||
# Test status behavior on ignored folder with tracked file | ||
cat >expect <<\EOF | ||
? expect | ||
? output | ||
! ignored_dir/ignored_1 | ||
! ignored_dir/ignored_1.ign | ||
! ignored_dir/ignored_2 | ||
! ignored_dir/ignored_2.ign | ||
EOF | ||
|
||
test_expect_success 'setup folder with tracked & ignored files' ' | ||
mkdir ignored_dir && | ||
touch ignored_dir/ignored_1 ignored_dir/ignored_2 \ | ||
ignored_dir/ignored_1.ign ignored_dir/ignored_2.ign \ | ||
ignored_dir/tracked && | ||
git add -f ignored_dir/tracked && | ||
test_tick && | ||
git commit -m "Force add file in ignored directory" | ||
' | ||
|
||
test_expect_success 'Verify status on folder with tracked & ignored files' ' | ||
test_when_finished "git clean -fdx && git reset HEAD~1 --hard" && | ||
git status --porcelain=v2 --ignored --untracked-files=all --show-ignored-directory >output && | ||
test_i18ncmp expect output | ||
' | ||
|
||
test_done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters