Skip to content

Commit df4e943

Browse files
author
Git for Windows Build Agent
committed
Merge branch 'show-ignored-directory'
This branch introduces an experimental option allowing `git status` to list all untracked files individually, but show ignored directories' names only instead of all ignored files. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents d6ba41a + 1e9a3c4 commit df4e943

File tree

8 files changed

+187
-2
lines changed

8 files changed

+187
-2
lines changed

Documentation/git-status.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ configuration variable documented in linkgit:git-config[1].
104104
--ignored::
105105
Show ignored files as well.
106106

107+
--show-ignored-directory::
108+
(EXPERIMENTAL) Show directories that are ignored, instead of individual files.
109+
Does not recurse into excluded directories when listing all
110+
untracked files.
111+
107112
-z::
108113
Terminate entries with NUL, instead of LF. This implies
109114
the `--porcelain=v1` output format if no other format is given.

Documentation/technical/api-directory-listing.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ The notable options are:
3333
Similar to `DIR_SHOW_IGNORED`, but return ignored files in `ignored[]`
3434
in addition to untracked files in `entries[]`.
3535

36+
`DIR_SHOW_IGNORED_DIRECTORY`:::
37+
38+
(EXPERIMENTAL) If this is set, non-empty directories that match an
39+
ignore pattern are returned. The individual files contained in ignored
40+
directories are not included.
41+
3642
`DIR_KEEP_UNTRACKED_CONTENTS`:::
3743

3844
Only has meaning if `DIR_SHOW_IGNORED_TOO` is also set; if this is set, the

builtin/commit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
13511351
int cmd_status(int argc, const char **argv, const char *prefix)
13521352
{
13531353
static int no_lock_index = 0;
1354+
static int show_ignored_directory = 0;
13541355
static struct wt_status s;
13551356
int fd;
13561357
struct object_id oid;
@@ -1384,6 +1385,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13841385
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
13851386
OPT_BOOL(0, "no-lock-index", &no_lock_index,
13861387
N_("do not lock the index")),
1388+
OPT_BOOL(0, "show-ignored-directory", &show_ignored_directory,
1389+
N_("(EXPERIMENTAL) Only show directories that match an ignore pattern name.")),
13871390
OPT_END(),
13881391
};
13891392

@@ -1425,6 +1428,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
14251428
s.ignore_submodule_arg = ignore_submodule_arg;
14261429
s.status_format = status_format;
14271430
s.verbose = verbose;
1431+
s.show_ignored_directory = show_ignored_directory;
14281432

14291433
wt_status_collect(&s);
14301434

dir.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,21 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
13901390
case index_nonexistent:
13911391
if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
13921392
break;
1393+
if (exclude &&
1394+
(dir->flags & DIR_SHOW_IGNORED_TOO) &&
1395+
(dir->flags & DIR_SHOW_IGNORED_DIRECTORY)) {
1396+
1397+
/*
1398+
* This is an excluded directory, and we are only
1399+
* showing the name of a excluded directory.
1400+
* Check to see if there are any contained files
1401+
* to determine if the directory is empty or not.
1402+
*/
1403+
if (read_directory_recursive(dir, istate, dirname, len,
1404+
untracked, 1, 1, pathspec) == path_excluded)
1405+
return path_excluded;
1406+
return path_none;
1407+
}
13931408
if (!(dir->flags & DIR_NO_GITLINKS)) {
13941409
struct object_id oid;
13951410
if (resolve_gitlink_ref(dirname, "HEAD", &oid) == 0)
@@ -1399,7 +1414,6 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
13991414
}
14001415

14011416
/* This is the "show_other_directories" case */
1402-
14031417
if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES))
14041418
return exclude ? path_excluded : path_untracked;
14051419

@@ -1414,6 +1428,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
14141428
untracked, 1, exclude, pathspec);
14151429
}
14161430

1431+
14171432
/*
14181433
* This is an inexact early pruning of any recursive directory
14191434
* reading - if the path cannot possibly be in the pathspec,

dir.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ struct dir_struct {
154154
DIR_COLLECT_IGNORED = 1<<4,
155155
DIR_SHOW_IGNORED_TOO = 1<<5,
156156
DIR_COLLECT_KILLED_ONLY = 1<<6,
157-
DIR_KEEP_UNTRACKED_CONTENTS = 1<<7
157+
DIR_KEEP_UNTRACKED_CONTENTS = 1<<7,
158+
DIR_SHOW_IGNORED_DIRECTORY = 1<<8
158159
} flags;
159160
struct dir_entry **entries;
160161
struct dir_entry **ignored;
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/sh
2+
#
3+
#
4+
5+
test_description='git status collapse ignored'
6+
7+
. ./test-lib.sh
8+
9+
10+
cat >.gitignore <<\EOF
11+
*.ign
12+
ignored_dir/
13+
!*.unignore
14+
EOF
15+
16+
# commit initial ignore file
17+
test_expect_success 'setup initial commit and ignore file' '
18+
git add . &&
19+
test_tick &&
20+
git commit -m "Initial commit"
21+
'
22+
23+
cat >expect <<\EOF
24+
? expect
25+
? output
26+
! dir/ignored/ignored_1.ign
27+
! dir/ignored/ignored_2.ign
28+
! ignored/ignored_1.ign
29+
! ignored/ignored_2.ign
30+
EOF
31+
32+
# Test status behavior on folder with ignored files
33+
test_expect_success 'setup folder with ignored files' '
34+
mkdir -p ignored dir/ignored &&
35+
touch ignored/ignored_1.ign ignored/ignored_2.ign \
36+
dir/ignored/ignored_1.ign dir/ignored/ignored_2.ign
37+
'
38+
39+
test_expect_success 'Verify behavior of status on folders with ignored files' '
40+
test_when_finished "git clean -fdx" &&
41+
git status --porcelain=v2 --ignored --untracked-files=all --show-ignored-directory >output &&
42+
test_i18ncmp expect output
43+
'
44+
45+
# Test status bahavior on folder with tracked and ignored files
46+
cat >expect <<\EOF
47+
? expect
48+
? output
49+
! dir/tracked_ignored/ignored_1.ign
50+
! dir/tracked_ignored/ignored_2.ign
51+
! tracked_ignored/ignored_1.ign
52+
! tracked_ignored/ignored_2.ign
53+
EOF
54+
55+
test_expect_success 'setup folder with tracked & ignored files' '
56+
mkdir -p tracked_ignored dir/tracked_ignored &&
57+
touch tracked_ignored/tracked_1 tracked_ignored/tracked_2 \
58+
tracked_ignored/ignored_1.ign tracked_ignored/ignored_2.ign \
59+
dir/tracked_ignored/tracked_1 dir/tracked_ignored/tracked_2 \
60+
dir/tracked_ignored/ignored_1.ign dir/tracked_ignored/ignored_2.ign &&
61+
62+
git add tracked_ignored/tracked_1 tracked_ignored/tracked_2 \
63+
dir/tracked_ignored/tracked_1 dir/tracked_ignored/tracked_2 &&
64+
test_tick &&
65+
git commit -m "commit tracked files"
66+
'
67+
68+
test_expect_success 'Verify status on folder with tracked & ignored files' '
69+
test_when_finished "git clean -fdx && git reset HEAD~1 --hard" &&
70+
git status --porcelain=v2 --ignored --untracked-files=all --show-ignored-directory >output &&
71+
test_i18ncmp expect output
72+
'
73+
74+
75+
# Test status behavior on folder with untracked and ignored files
76+
cat >expect <<\EOF
77+
? dir/untracked_ignored/untracked_1
78+
? dir/untracked_ignored/untracked_2
79+
? expect
80+
? output
81+
? untracked_ignored/untracked_1
82+
? untracked_ignored/untracked_2
83+
! dir/untracked_ignored/ignored_1.ign
84+
! dir/untracked_ignored/ignored_2.ign
85+
! untracked_ignored/ignored_1.ign
86+
! untracked_ignored/ignored_2.ign
87+
EOF
88+
89+
test_expect_success 'setup folder with tracked & ignored files' '
90+
mkdir -p untracked_ignored dir/untracked_ignored &&
91+
touch untracked_ignored/untracked_1 untracked_ignored/untracked_2 \
92+
untracked_ignored/ignored_1.ign untracked_ignored/ignored_2.ign \
93+
dir/untracked_ignored/untracked_1 dir/untracked_ignored/untracked_2 \
94+
dir/untracked_ignored/ignored_1.ign dir/untracked_ignored/ignored_2.ign
95+
'
96+
97+
test_expect_success 'Verify status on folder with tracked & ignored files' '
98+
test_when_finished "git clean -fdx" &&
99+
git status --porcelain=v2 --ignored --untracked-files=all --show-ignored-directory >output &&
100+
test_i18ncmp expect output
101+
'
102+
103+
# Test status behavior on ignored folder
104+
cat >expect <<\EOF
105+
? expect
106+
? output
107+
! ignored_dir/
108+
EOF
109+
110+
test_expect_success 'setup folder with tracked & ignored files' '
111+
mkdir ignored_dir &&
112+
touch ignored_dir/ignored_1 ignored_dir/ignored_2 \
113+
ignored_dir/ignored_1.ign ignored_dir/ignored_2.ign
114+
'
115+
116+
test_expect_success 'Verify status on folder with tracked & ignored files' '
117+
test_when_finished "git clean -fdx" &&
118+
git status --porcelain=v2 --ignored --untracked-files=all --show-ignored-directory >output &&
119+
test_i18ncmp expect output
120+
'
121+
122+
# Test status behavior on ignored folder with tracked file
123+
cat >expect <<\EOF
124+
? expect
125+
? output
126+
! ignored_dir/ignored_1
127+
! ignored_dir/ignored_1.ign
128+
! ignored_dir/ignored_2
129+
! ignored_dir/ignored_2.ign
130+
EOF
131+
132+
test_expect_success 'setup folder with tracked & ignored files' '
133+
mkdir ignored_dir &&
134+
touch ignored_dir/ignored_1 ignored_dir/ignored_2 \
135+
ignored_dir/ignored_1.ign ignored_dir/ignored_2.ign \
136+
ignored_dir/tracked &&
137+
git add -f ignored_dir/tracked &&
138+
test_tick &&
139+
git commit -m "Force add file in ignored directory"
140+
'
141+
142+
test_expect_success 'Verify status on folder with tracked & ignored files' '
143+
test_when_finished "git clean -fdx && git reset HEAD~1 --hard" &&
144+
git status --porcelain=v2 --ignored --untracked-files=all --show-ignored-directory >output &&
145+
test_i18ncmp expect output
146+
'
147+
148+
test_done
149+

wt-status.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,10 @@ static void wt_status_collect_untracked(struct wt_status *s)
662662
dir.flags |= DIR_SHOW_IGNORED_TOO;
663663
else
664664
dir.untracked = the_index.untracked;
665+
666+
if (s->show_ignored_directory)
667+
dir.flags |= DIR_SHOW_IGNORED_DIRECTORY;
668+
665669
setup_standard_excludes(&dir);
666670

667671
fill_directory(&dir, &the_index, &s->pathspec);

wt-status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct wt_status {
7272
int submodule_summary;
7373
int show_ignored_files;
7474
enum untracked_status_type show_untracked_files;
75+
int show_ignored_directory;
7576
const char *ignore_submodule_arg;
7677
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
7778
unsigned colopts;

0 commit comments

Comments
 (0)