Skip to content

Commit

Permalink
git status: ignoring untracked files must apply to submodules too
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jens Lehmann authored and Junio C Hamano committed Mar 14, 2010
1 parent 85adbf2 commit 3bfc450
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion diff-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt,
if (S_ISGITLINK(ce->ce_mode)
&& !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES)
&& (!changed || DIFF_OPT_TST(diffopt, DIRTY_SUBMODULES))) {
*dirty_submodule = is_submodule_modified(ce->name);
*dirty_submodule = is_submodule_modified(ce->name, DIFF_OPT_TST(diffopt, IGNORE_UNTRACKED_IN_SUBMODULES));
}
return changed;
}
Expand Down
1 change: 1 addition & 0 deletions diff.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
#define DIFF_OPT_DIFF_FROM_CONTENTS (1 << 22)
#define DIFF_OPT_SUBMODULE_LOG (1 << 23)
#define DIFF_OPT_DIRTY_SUBMODULES (1 << 24)
#define DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES (1 << 25)

#define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
#define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag)
Expand Down
9 changes: 7 additions & 2 deletions submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void show_submodule_summary(FILE *f, const char *path,
strbuf_release(&sb);
}

unsigned is_submodule_modified(const char *path)
unsigned is_submodule_modified(const char *path, int ignore_untracked)
{
int i;
ssize_t len;
Expand All @@ -139,6 +139,7 @@ unsigned is_submodule_modified(const char *path)
"status",
"--porcelain",
NULL,
NULL,
};
const char *env[LOCAL_REPO_ENV_SIZE + 3];
struct strbuf buf = STRBUF_INIT;
Expand All @@ -163,6 +164,9 @@ unsigned is_submodule_modified(const char *path)
env[i++] = strbuf_detach(&buf, NULL);
env[i] = NULL;

if (ignore_untracked)
argv[2] = "-uno";

memset(&cp, 0, sizeof(cp));
cp.argv = argv;
cp.env = env;
Expand All @@ -181,7 +185,8 @@ unsigned is_submodule_modified(const char *path)
break;
} else {
dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
if (ignore_untracked ||
(dirty_submodule & DIRTY_SUBMODULE_UNTRACKED))
break;
}
next_line = strchr(line, '\n');
Expand Down
2 changes: 1 addition & 1 deletion submodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ void show_submodule_summary(FILE *f, const char *path,
unsigned char one[20], unsigned char two[20],
unsigned dirty_submodule,
const char *del, const char *add, const char *reset);
unsigned is_submodule_modified(const char *path);
unsigned is_submodule_modified(const char *path, int ignore_untracked);

#endif
5 changes: 5 additions & 0 deletions t/t7506-status-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ test_expect_success 'status with untracked file in submodule' '
grep "modified: sub (untracked content)" output
'

test_expect_success 'status -uno with untracked file in submodule' '
git status -uno >output &&
grep "^nothing to commit" output
'

test_expect_success 'status with untracked file in submodule (porcelain)' '
git status --porcelain >output &&
diff output - <<-\EOF
Expand Down
2 changes: 2 additions & 0 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
setup_revisions(0, NULL, &rev, NULL);
rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
DIFF_OPT_SET(&rev.diffopt, DIRTY_SUBMODULES);
if (!s->show_untracked_files)
DIFF_OPT_SET(&rev.diffopt, IGNORE_UNTRACKED_IN_SUBMODULES);
rev.diffopt.format_callback = wt_status_collect_changed_cb;
rev.diffopt.format_callback_data = s;
rev.prune_data = s->pathspec;
Expand Down

0 comments on commit 3bfc450

Please sign in to comment.