@matheusbsbs / matheus-bagliano / commits / 3bfc450476
Fork 0

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 <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed Mar 13, 2010 at 23:00 UTC 3bfc45047654c7dd38b32033321228e97fc8f60e
6 files changed +17 -4
diff-lib.c
+1 -1
@@ -71,7 +71,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt,
71 if (S_ISGITLINK(ce->ce_mode)
72 && !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES)
73 && (!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));
75 }
76 return changed;
77 }
diff.h
+1
@@ -70,6 +70,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
70 #define DIFF_OPT_DIFF_FROM_CONTENTS (1 << 22)
71 #define DIFF_OPT_SUBMODULE_LOG (1 << 23)
72 #define DIFF_OPT_DIRTY_SUBMODULES (1 << 24)
73 +#define DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES (1 << 25)
74
75 #define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
76 #define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag)
submodule.c
+7 -2
@@ -130,7 +130,7 @@ void show_submodule_summary(FILE *f, const char *path,
130 strbuf_release(&sb);
131 }
132
133 -unsigned is_submodule_modified(const char *path)
133 +unsigned is_submodule_modified(const char *path, int ignore_untracked)
134 {
135 int i;
136 ssize_t len;
@@ -139,6 +139,7 @@ unsigned is_submodule_modified(const char *path)
139 "status",
140 "--porcelain",
141 NULL,
142 + NULL,
143 };
144 const char *env[LOCAL_REPO_ENV_SIZE + 3];
145 struct strbuf buf = STRBUF_INIT;
@@ -163,6 +164,9 @@ unsigned is_submodule_modified(const char *path)
164 env[i++] = strbuf_detach(&buf, NULL);
165 env[i] = NULL;
166
167 + if (ignore_untracked)
168 + argv[2] = "-uno";
169 +
170 memset(&cp, 0, sizeof(cp));
171 cp.argv = argv;
172 cp.env = env;
@@ -181,7 +185,8 @@ unsigned is_submodule_modified(const char *path)
185 break;
186 } else {
187 dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
184 - if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
188 + if (ignore_untracked ||
189 + (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED))
190 break;
191 }
192 next_line = strchr(line, '\n');
submodule.h
+1 -1
@@ -5,6 +5,6 @@ void show_submodule_summary(FILE *f, const char *path,
5 unsigned char one[20], unsigned char two[20],
6 unsigned dirty_submodule,
7 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);
9
10 #endif
t/t7506-status-submodule.sh
+5
@@ -67,6 +67,11 @@ test_expect_success 'status with untracked file in submodule' '
67 grep "modified: sub (untracked content)" output
68 '
69
70 +test_expect_success 'status -uno with untracked file in submodule' '
71 + git status -uno >output &&
72 + grep "^nothing to commit" output
73 +'
74 +
75 test_expect_success 'status with untracked file in submodule (porcelain)' '
76 git status --porcelain >output &&
77 diff output - <<-\EOF
wt-status.c
+2
@@ -304,6 +304,8 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
304 setup_revisions(0, NULL, &rev, NULL);
305 rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
306 DIFF_OPT_SET(&rev.diffopt, DIRTY_SUBMODULES);
307 + if (!s->show_untracked_files)
308 + DIFF_OPT_SET(&rev.diffopt, IGNORE_UNTRACKED_IN_SUBMODULES);
309 rev.diffopt.format_callback = wt_status_collect_changed_cb;
310 rev.diffopt.format_callback_data = s;
311 rev.prune_data = s->pathspec;