Skip to content

Commit 3bfc450

Browse files
jlehmanngitster
authored andcommitted
git status: ignoring untracked files must apply to submodules too
Since 1.7.0 submodules are considered dirty when they contain untracked files. But when git status is called with the "-uno" option, the user asked to ignore untracked files, so they must be ignored in submodules too. To achieve this, the new flag DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES is introduced. Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 85adbf2 commit 3bfc450

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

diff-lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt,
7171
if (S_ISGITLINK(ce->ce_mode)
7272
&& !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES)
7373
&& (!changed || DIFF_OPT_TST(diffopt, DIRTY_SUBMODULES))) {
74-
*dirty_submodule = is_submodule_modified(ce->name);
74+
*dirty_submodule = is_submodule_modified(ce->name, DIFF_OPT_TST(diffopt, IGNORE_UNTRACKED_IN_SUBMODULES));
7575
}
7676
return changed;
7777
}

diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
7070
#define DIFF_OPT_DIFF_FROM_CONTENTS (1 << 22)
7171
#define DIFF_OPT_SUBMODULE_LOG (1 << 23)
7272
#define DIFF_OPT_DIRTY_SUBMODULES (1 << 24)
73+
#define DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES (1 << 25)
7374

7475
#define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
7576
#define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag)

submodule.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void show_submodule_summary(FILE *f, const char *path,
130130
strbuf_release(&sb);
131131
}
132132

133-
unsigned is_submodule_modified(const char *path)
133+
unsigned is_submodule_modified(const char *path, int ignore_untracked)
134134
{
135135
int i;
136136
ssize_t len;
@@ -139,6 +139,7 @@ unsigned is_submodule_modified(const char *path)
139139
"status",
140140
"--porcelain",
141141
NULL,
142+
NULL,
142143
};
143144
const char *env[LOCAL_REPO_ENV_SIZE + 3];
144145
struct strbuf buf = STRBUF_INIT;
@@ -163,6 +164,9 @@ unsigned is_submodule_modified(const char *path)
163164
env[i++] = strbuf_detach(&buf, NULL);
164165
env[i] = NULL;
165166

167+
if (ignore_untracked)
168+
argv[2] = "-uno";
169+
166170
memset(&cp, 0, sizeof(cp));
167171
cp.argv = argv;
168172
cp.env = env;
@@ -181,7 +185,8 @@ unsigned is_submodule_modified(const char *path)
181185
break;
182186
} else {
183187
dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
184-
if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
188+
if (ignore_untracked ||
189+
(dirty_submodule & DIRTY_SUBMODULE_UNTRACKED))
185190
break;
186191
}
187192
next_line = strchr(line, '\n');

submodule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ void show_submodule_summary(FILE *f, const char *path,
55
unsigned char one[20], unsigned char two[20],
66
unsigned dirty_submodule,
77
const char *del, const char *add, const char *reset);
8-
unsigned is_submodule_modified(const char *path);
8+
unsigned is_submodule_modified(const char *path, int ignore_untracked);
99

1010
#endif

t/t7506-status-submodule.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ test_expect_success 'status with untracked file in submodule' '
6767
grep "modified: sub (untracked content)" output
6868
'
6969

70+
test_expect_success 'status -uno with untracked file in submodule' '
71+
git status -uno >output &&
72+
grep "^nothing to commit" output
73+
'
74+
7075
test_expect_success 'status with untracked file in submodule (porcelain)' '
7176
git status --porcelain >output &&
7277
diff output - <<-\EOF

wt-status.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
304304
setup_revisions(0, NULL, &rev, NULL);
305305
rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
306306
DIFF_OPT_SET(&rev.diffopt, DIRTY_SUBMODULES);
307+
if (!s->show_untracked_files)
308+
DIFF_OPT_SET(&rev.diffopt, IGNORE_UNTRACKED_IN_SUBMODULES);
307309
rev.diffopt.format_callback = wt_status_collect_changed_cb;
308310
rev.diffopt.format_callback_data = s;
309311
rev.prune_data = s->pathspec;

0 commit comments

Comments
 (0)