Merge branch 'sj/untracked-files-in-submodule-directory-is-not-dirty'

"git diff" showed a submodule working tree with untracked cruft as
"Submodule commit <objectname>-dirty", but a natural expectation is
that the "-dirty" indicator would align with "git describe --dirty",
which does not consider having untracked files in the working tree
as source of dirtiness.  The inconsistency has been fixed.

* sj/untracked-files-in-submodule-directory-is-not-dirty:
  diff: do not show submodule with untracked files as "-dirty"
This commit is contained in:
Junio C Hamano 2021-01-25 14:19:18 -08:00
commit 0806279428
9 changed files with 42 additions and 19 deletions

View File

@ -85,6 +85,8 @@ diff.ignoreSubmodules::
and 'git status' when `status.submoduleSummary` is set unless it is
overridden by using the --ignore-submodules command-line option.
The 'git submodule' commands are not affected by this setting.
By default this is set to untracked so that any untracked
submodules are ignored.
diff.mnemonicPrefix::
If set, 'git diff' uses a prefix pair that is different from the

3
diff.c
View File

@ -4593,6 +4593,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
options->orderfile = diff_order_file_cfg;
if (!options->flags.ignore_submodule_set)
options->flags.ignore_untracked_in_submodules = 1;
if (diff_no_prefix) {
options->a_prefix = options->b_prefix = "";
} else if (!diff_mnemonic_prefix) {

1
diff.h
View File

@ -178,6 +178,7 @@ struct diff_flags {
unsigned diff_from_contents;
unsigned dirty_submodules;
unsigned ignore_untracked_in_submodules;
unsigned ignore_submodule_set;
unsigned ignore_dirty_submodules;
unsigned override_submodule_config;
unsigned dirstat_by_line;

View File

@ -420,6 +420,7 @@ const char *submodule_strategy_to_string(const struct submodule_update_strategy
void handle_ignore_submodules_arg(struct diff_options *diffopt,
const char *arg)
{
diffopt->flags.ignore_submodule_set = 1;
diffopt->flags.ignore_submodules = 0;
diffopt->flags.ignore_untracked_in_submodules = 0;
diffopt->flags.ignore_dirty_submodules = 0;

View File

@ -849,6 +849,12 @@ test_expect_success 'setup different kinds of dirty submodules' '
cat >expected <<-\EOF &&
dirty-both-ways
dirty-head
EOF
test_cmp expected actual &&
git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
cat >expected <<-\EOF &&
dirty-both-ways
dirty-head
dirty-otherwise
EOF
test_cmp expected actual &&

View File

@ -93,6 +93,14 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
) &&
git diff HEAD >actual &&
sed -e "1,/^@@/d" actual >actual.body &&
expect_from_to >expect.body $subtip $subprev &&
test_cmp expect.body actual.body
'
test_expect_success 'git diff HEAD with dirty submodule (untracked) (none ignored)' '
test_config diff.ignoreSubmodules none &&
git diff HEAD >actual &&
sed -e "1,/^@@/d" actual >actual.body &&
expect_from_to >expect.body $subtip $subprev-dirty &&
test_cmp expect.body actual.body
'
@ -168,13 +176,13 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)'
git clean -qfdx &&
>cruft
) &&
git diff HEAD >actual &&
git diff --ignore-submodules=none HEAD >actual &&
sed -e "1,/^@@/d" actual >actual.body &&
expect_from_to >expect.body $subprev $subprev-dirty &&
test_cmp expect.body actual.body &&
git diff --ignore-submodules=all HEAD >actual2 &&
test_must_be_empty actual2 &&
git diff --ignore-submodules=untracked HEAD >actual3 &&
git diff HEAD >actual3 &&
test_must_be_empty actual3 &&
git diff --ignore-submodules=dirty HEAD >actual4 &&
test_must_be_empty actual4

View File

@ -262,7 +262,7 @@ test_expect_success 'submodule is up to date' '
test_expect_success 'submodule contains untracked content' '
echo new > sm1/new-file &&
git diff-index -p --submodule=log HEAD >actual &&
git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
EOF
@ -270,7 +270,7 @@ test_expect_success 'submodule contains untracked content' '
'
test_expect_success 'submodule contains untracked content (untracked ignored)' '
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
git diff-index -p --submodule=log HEAD >actual &&
test_must_be_empty actual
'
@ -286,7 +286,7 @@ test_expect_success 'submodule contains untracked content (all ignored)' '
test_expect_success 'submodule contains untracked and modified content' '
echo new > sm1/foo6 &&
git diff-index -p --submodule=log HEAD >actual &&
git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
Submodule sm1 contains modified content
@ -296,7 +296,7 @@ test_expect_success 'submodule contains untracked and modified content' '
test_expect_success 'submodule contains untracked and modified content (untracked ignored)' '
echo new > sm1/foo6 &&
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
git diff-index -p --submodule=log HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains modified content
EOF
@ -337,7 +337,7 @@ test_expect_success 'submodule is modified' '
test_expect_success 'modified submodule contains untracked content' '
echo new > sm1/new-file &&
git diff-index -p --submodule=log HEAD >actual &&
git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
Submodule sm1 $head6..$head8:
@ -347,7 +347,7 @@ test_expect_success 'modified submodule contains untracked content' '
'
test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
git diff-index -p --submodule=log HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 $head6..$head8:
> change
@ -371,7 +371,7 @@ test_expect_success 'modified submodule contains untracked content (all ignored)
test_expect_success 'modified submodule contains untracked and modified content' '
echo modification >> sm1/foo6 &&
git diff-index -p --submodule=log HEAD >actual &&
git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
Submodule sm1 contains modified content
@ -383,7 +383,7 @@ test_expect_success 'modified submodule contains untracked and modified content'
test_expect_success 'modified submodule contains untracked and modified content (untracked ignored)' '
echo modification >> sm1/foo6 &&
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
git diff-index -p --submodule=log HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains modified content
Submodule sm1 $head6..$head8:

View File

@ -409,7 +409,7 @@ test_expect_success 'submodule is up to date' '
test_expect_success 'submodule contains untracked content' '
echo new > sm1/new-file &&
git diff-index -p --submodule=diff HEAD >actual &&
git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
EOF
@ -417,7 +417,7 @@ test_expect_success 'submodule contains untracked content' '
'
test_expect_success 'submodule contains untracked content (untracked ignored)' '
git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
git diff-index -p --submodule=diff HEAD >actual &&
test_must_be_empty actual
'
@ -433,7 +433,7 @@ test_expect_success 'submodule contains untracked content (all ignored)' '
test_expect_success 'submodule contains untracked and modified content' '
echo new > sm1/foo6 &&
git diff-index -p --submodule=diff HEAD >actual &&
git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
Submodule sm1 contains modified content
@ -451,7 +451,7 @@ test_expect_success 'submodule contains untracked and modified content' '
# NOT OK
test_expect_success 'submodule contains untracked and modified content (untracked ignored)' '
echo new > sm1/foo6 &&
git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
git diff-index -p --submodule=diff HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains modified content
diff --git a/sm1/foo6 b/sm1/foo6
@ -512,7 +512,7 @@ test_expect_success 'submodule is modified' '
test_expect_success 'modified submodule contains untracked content' '
echo new > sm1/new-file &&
git diff-index -p --submodule=diff HEAD >actual &&
git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
Submodule sm1 $head7..$head8:
@ -528,7 +528,7 @@ test_expect_success 'modified submodule contains untracked content' '
'
test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
git diff-index -p --submodule=diff HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 $head7..$head8:
diff --git a/sm1/foo6 b/sm1/foo6
@ -564,7 +564,7 @@ test_expect_success 'modified submodule contains untracked content (all ignored)
test_expect_success 'modified submodule contains untracked and modified content' '
echo modification >> sm1/foo6 &&
git diff-index -p --submodule=diff HEAD >actual &&
git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
Submodule sm1 contains modified content
@ -583,7 +583,7 @@ test_expect_success 'modified submodule contains untracked and modified content'
test_expect_success 'modified submodule contains untracked and modified content (untracked ignored)' '
echo modification >> sm1/foo6 &&
git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
git diff-index -p --submodule=diff HEAD >actual &&
cat >expected <<-EOF &&
Submodule sm1 contains modified content
Submodule sm1 $head7..$head8:

View File

@ -606,7 +606,9 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
if (s->ignore_submodule_arg) {
rev.diffopt.flags.override_submodule_config = 1;
handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg);
}
} else if (!rev.diffopt.flags.ignore_submodule_set &&
s->show_untracked_files != SHOW_NO_UNTRACKED_FILES)
handle_ignore_submodules_arg(&rev.diffopt, "none");
rev.diffopt.format_callback = wt_status_collect_changed_cb;
rev.diffopt.format_callback_data = s;
rev.diffopt.detect_rename = s->detect_rename >= 0 ? s->detect_rename : rev.diffopt.detect_rename;