mirror of
https://github.com/git/git.git
synced 2024-11-27 03:53:55 +08:00
diff: do not show submodule with untracked files as "-dirty"
Git diff reports a submodule directory as -dirty even when there are only untracked files in the submodule directory. This is inconsistent with what `git describe --dirty` says when run in the submodule directory in that state. Make `--ignore-submodules=untracked` the default for `git diff` when there is no configuration variable or command line option, so that the command would not give '-dirty' suffix to a submodule whose working tree has untracked files, to make it consistent with `git describe --dirty` that is run in the submodule working tree. And also make `--ignore-submodules=none` the default for `git status` so that the user doesn't end up deleting a submodule that has uncommitted (untracked) files. Signed-off-by: Sangeeta Jain <sangunb09@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
2e673356ae
commit
8ef9312464
@ -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
3
diff.c
@ -4586,6 +4586,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
1
diff.h
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -765,6 +765,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 &&
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user