Skip to contentSkip to conversation

diff: do not show submodule with untracked files as "-dirty"

PATCH In review Sangeeta via GitGitGadget 6 participants 36 messages Oct 15, 2020 – Dec 8, 2020 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 diff: do not show submodule with untracked files as "-dirty"

From: sangu09 <[email protected]>

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.

So this patch makes git diff HEAD consistent with git describe --dirty in case of untracked files. This can be solved by including the "--ignore-submodules=untracked" feature in git diff by default. So in order to make this as default behaviour I have added the behaviour of ignore-submodules in repo_diff_setup() function. Also, to avoid ignoreSubmodules in user config being overwritten, I have made a global variable diff_ignore_submodule_config to keep a track whether handle_ignore_submodules_arg is called before or not.

---
[Outreachy] 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.

So this patch makes git diff HEAD consistent with git describe --dirty in case of untracked files. This can be solved by including the "--ignore-submodules=untracked" feature in git diff by default. So in order to make this as default behaviour I have added the behaviour of ignore-submodules in repo_diff_setup() function. Also, to avoid ignoreSubmodules in user config being overwritten, I have made a global variable diff_ignore_submodule_config to keep a track whether handle_ignore_submodules_arg is called before or not.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-751%2Fsangu09%2Fhandle_untracked-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-751/sangu09/handle_untracked-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/751

 diff.c                                       |  1 +
 submodule.c                                  |  2 ++
 t/t3701-add-interactive.sh                   |  2 +-
 t/t4027-diff-submodule.sh                    |  6 ++--
 t/t4041-diff-submodule-option.sh             | 16 ++++-----
 t/t4060-diff-submodule-option-diff-format.sh | 16 ++++-----
 t/t7064-wtstatus-pv2.sh                      |  8 ++---
 t/t7506-status-submodule.sh                  | 38 +++++---------------
 8 files changed, 36 insertions(+), 53 deletions(-)
diff.c +1 -0
index 2bb2f8f57e..07d89e3e2b 100644
@@ -4585,6 +4585,7 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	options->orderfile = diff_order_file_cfg;
+	options->flags.ignore_untracked_in_submodules = 1;
 
 	if (diff_no_prefix) {
 		options->a_prefix = options->b_prefix = "";
submodule.c +2 -0
index b3bb59f066..762298c010 100644
@@ -1678,6 +1678,8 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 	strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
 	if (ignore_untracked)
 		strvec_push(&cp.args, "-uno");
+	else
+        strvec_push (&cp.args, "--ignore-submodules=none");
 
 	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
t/t3701-add-interactive.sh +1 -1
index ca04fac417..98e46ad1ae 100755
@@ -761,7 +761,7 @@ test_expect_success 'setup different kinds of dirty submodules' '
 		echo dirty >>initial &&
 		: >untracked
 	) &&
-	git -C for-submodules diff-files --name-only >actual &&
+	git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
 	cat >expected <<-\EOF &&
 	dirty-both-ways
 	dirty-head
t/t4027-diff-submodule.sh +3 -3
index d7145ccca4..7bf2cb9c88 100755
@@ -93,7 +93,7 @@ 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-dirty &&
+	expect_from_to >expect.body $subtip $subprev &&
 	test_cmp expect.body actual.body
 '
 
@@ -168,13 +168,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
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..bb368b685d 100755
@@ -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 --submodule=log HEAD --ignore-submodules=none >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 --submodule=log HEAD --ignore-submodules=none >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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
t/t7064-wtstatus-pv2.sh +4 -4
index 537787e598..200626251e 100755
@@ -483,7 +483,7 @@ test_expect_success 'create and add submodule, submodule appears clean (A. S...)
 	)
 '
 
-test_expect_success 'untracked changes in added submodule (AM S..U)' '
+test_expect_success 'untracked changes in added submodule (A. S...))' '
 	(	cd super_repo &&
 		## create untracked file in the submodule.
 		(	cd sub1 &&
@@ -500,7 +500,7 @@ test_expect_success 'untracked changes in added submodule (AM S..U)' '
 		# branch.upstream origin/master
 		# branch.ab +0 -0
 		1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
-		1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1
+		1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1
 		EOF
 
 		git status --porcelain=v2 --branch --untracked-files=all >actual &&
@@ -560,7 +560,7 @@ test_expect_success 'staged and unstaged changes in added (AM S.M.)' '
 	)
 '
 
-test_expect_success 'staged and untracked changes in added submodule (AM S.MU)' '
+test_expect_success 'staged and untracked changes in added submodule (AM S.M.)' '
 	(	cd super_repo &&
 		(	cd sub1 &&
 			## stage new changes in tracked file.
@@ -579,7 +579,7 @@ test_expect_success 'staged and untracked changes in added submodule (AM S.MU)'
 		# branch.upstream origin/master
 		# branch.ab +0 -0
 		1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
-		1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1
+		1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
 		EOF
 
 		git status --porcelain=v2 --branch --untracked-files=all >actual &&
t/t7506-status-submodule.sh +9 -29
index 3fcb44767f..b7ff7928fb 100755
@@ -95,7 +95,7 @@ test_expect_success 'status with untracked file in submodule' '
 	(cd sub && git reset --hard) &&
 	echo "content" >sub/new-file &&
 	git status >output &&
-	test_i18ngrep "modified:   sub (untracked content)" output
+	test_i18ngrep "^nothing to commit" output
 '
 
 test_expect_success 'status -uno with untracked file in submodule' '
@@ -105,23 +105,19 @@ test_expect_success 'status -uno with untracked file in submodule' '
 
 test_expect_success 'status with untracked file in submodule (porcelain)' '
 	git status --porcelain >output &&
-	diff output - <<-\EOF
-	 M sub
-	EOF
+	test_must_be_empty output
 '
 
 test_expect_success 'status with untracked file in submodule (short)' '
 	git status --short >output &&
-	diff output - <<-\EOF
-	 ? sub
-	EOF
+	test_must_be_empty output
 '
 
 test_expect_success 'status with added and untracked file in submodule' '
 	(cd sub && git reset --hard && echo >foo && git add foo) &&
 	echo "content" >sub/new-file &&
 	git status >output &&
-	test_i18ngrep "modified:   sub (modified content, untracked content)" output
+	test_i18ngrep "modified:   sub (modified content)" output
 '
 
 test_expect_success 'status with added and untracked file in submodule (porcelain)' '
@@ -169,7 +165,7 @@ test_expect_success 'status with untracked file in modified submodule' '
 	(cd sub && git reset --hard) &&
 	echo "content" >sub/new-file &&
 	git status >output &&
-	test_i18ngrep "modified:   sub (new commits, untracked content)" output
+	test_i18ngrep "modified:   sub (new commits)" output
 '
 
 test_expect_success 'status with untracked file in modified submodule (porcelain)' '
@@ -183,7 +179,7 @@ test_expect_success 'status with added and untracked file in modified submodule'
 	(cd sub && git reset --hard && echo >foo && git add foo) &&
 	echo "content" >sub/new-file &&
 	git status >output &&
-	test_i18ngrep "modified:   sub (new commits, modified content, untracked content)" output
+	test_i18ngrep "modified:   sub (new commits, modified content)" output
 '
 
 test_expect_success 'status with added and untracked file in modified submodule (porcelain)' '
@@ -350,30 +346,17 @@ test_expect_success 'setup superproject with untracked file in nested submodule'
 
 test_expect_success 'status with untracked file in nested submodule (porcelain)' '
 	git -C super status --porcelain >output &&
-	diff output - <<-\EOF
-	 M sub1
-	 M sub2
-	 M sub3
-	EOF
+	test_must_be_empty output
 '
 
 test_expect_success 'status with untracked file in nested submodule (porcelain=2)' '
 	git -C super status --porcelain=2 >output &&
-	sanitize_output output &&
-	diff output - <<-\EOF
-	1 .M S..U 160000 160000 160000 HASH HASH sub1
-	1 .M S..U 160000 160000 160000 HASH HASH sub2
-	1 .M S..U 160000 160000 160000 HASH HASH sub3
-	EOF
+	test_must_be_empty output
 '
 
 test_expect_success 'status with untracked file in nested submodule (short)' '
 	git -C super status --short >output &&
-	diff output - <<-\EOF
-	 ? sub1
-	 ? sub2
-	 ? sub3
-	EOF
+	test_must_be_empty output
 '
 
 test_expect_success 'setup superproject with modified file in nested submodule' '
@@ -386,7 +369,6 @@ test_expect_success 'status with added file in nested submodule (porcelain)' '
 	diff output - <<-\EOF
 	 M sub1
 	 M sub2
-	 M sub3
 	EOF
 '
 
@@ -396,7 +378,6 @@ test_expect_success 'status with added file in nested submodule (porcelain=2)' '
 	diff output - <<-\EOF
 	1 .M S.M. 160000 160000 160000 HASH HASH sub1
 	1 .M S.M. 160000 160000 160000 HASH HASH sub2
-	1 .M S..U 160000 160000 160000 HASH HASH sub3
 	EOF
 '
 
@@ -405,7 +386,6 @@ test_expect_success 'status with added file in nested submodule (short)' '
 	diff output - <<-\EOF
 	 m sub1
 	 m sub2
-	 ? sub3
 	EOF
 '
 

base-commit: d98273ba77e1ab9ec755576bc86c716a97bf59d7

Signature · 1 line
gitgitgadget
#1 lore raw

Hi Sangeeta

Quoted 1 line · Sangeeta via GitGitGadget

From: sangu09 <[email protected]>

I think we require your full name on the From line to match the Signed-off-by line below (c.f. https://lore.kernel.org/git/[email protected])

Quoted 2 lines

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.

That is a good summary of the issue that this change addresses, we normally wrap lines at 72 characters though.

Quoted 1 line

So this patch makes git diff HEAD consistent with git describe --dirty in case of untracked files. This can be solved by including the "--ignore-submodules=untracked" feature in git diff by default. So in order to make this as default behaviour I have added the behaviour of ignore-submodules in repo_diff_setup() function.

I think this could be a little more concise

This patch makes git diff HEAD consistent with git describe --dirty when a submodule contains untracked files by making --ignore-submodules=untracked the default.

Quoted 1 line

Also, to avoid ignoreSubmodules in user config being overwritten, I have made a global variable >diff_ignore_submodule_config to keep a track whether handle_ignore_submodules_arg is called before or not.

It is good that you have thought about this and it is worth mentioning in the commit message, however unfortunately that variable does not seem to exist in the patch.

Quoted 38 lines

---
[Outreachy] 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.

So this patch makes git diff HEAD consistent with git describe --dirty in case of untracked files. This can be solved by including the "--ignore-submodules=untracked" feature in git diff by default. So in order to make this as default behaviour I have added the behaviour of ignore-submodules in repo_diff_setup() function. Also, to avoid ignoreSubmodules in user config being overwritten, I have made a global variable diff_ignore_submodule_config to keep a track whether handle_ignore_submodules_arg is called before or not.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-751%2Fsangu09%2Fhandle_untracked-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-751/sangu09/handle_untracked-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/751

  diff.c                                       |  1 +
  submodule.c                                  |  2 ++
  t/t3701-add-interactive.sh                   |  2 +-
  t/t4027-diff-submodule.sh                    |  6 ++--
  t/t4041-diff-submodule-option.sh             | 16 ++++-----
  t/t4060-diff-submodule-option-diff-format.sh | 16 ++++-----
  t/t7064-wtstatus-pv2.sh                      |  8 ++---
  t/t7506-status-submodule.sh                  | 38 +++++---------------
  8 files changed, 36 insertions(+), 53 deletions(-)
diff.c +0 -0
index 2bb2f8f57e..07d89e3e2b 100644

diff.c void repo_diff_setup(struct repository *r, struct diff_options *options) · line 4588

Quoted 4 lines
diff.c +1 -0
@@ -4585,6 +4585,7 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
  		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
  	options->orderfile = diff_order_file_cfg;
+	options->flags.ignore_untracked_in_submodules = 1;

This unconditionally overrides diff.ignoreSubmodules, grepping seems to show that we don't have any tests that test a config value of "none". There are a few that check "dirty" which we should look at to consider if they still add value now we've changed the default.

submodule.c unsigned is_submodule_modified(const char *path, int ignore_untracked) · line 1682

Quoted 12 lines
diff.c +0 -0
  	if (diff_no_prefix) {
  		options->a_prefix = options->b_prefix = "";
submodule.c +2 -0
index b3bb59f066..762298c010 100644
@@ -1678,6 +1678,8 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
  	strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
  	if (ignore_untracked)
  		strvec_push(&cp.args, "-uno");
+	else
+        strvec_push (&cp.args, "--ignore-submodules=none");

We need to do this a a consequence of changing the default for '--ignore-submodules, we should think what the consequences are for other users of git status` and whether we need to do something similar there if diff.ignoreSubmodules is not set.

Quoted 31 lines
submodule.c +0 -0
  	prepare_submodule_repo_env(&cp.env_array);
  	cp.git_cmd = 1;
t/t3701-add-interactive.sh +1 -1
index ca04fac417..98e46ad1ae 100755
@@ -761,7 +761,7 @@ test_expect_success 'setup different kinds of dirty submodules' '
  		echo dirty >>initial &&
  		: >untracked
  	) &&
-	git -C for-submodules diff-files --name-only >actual &&
+	git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
  	cat >expected <<-\EOF &&
  	dirty-both-ways
  	dirty-head
t/t4027-diff-submodule.sh +1 -1
index d7145ccca4..7bf2cb9c88 100755
@@ -93,7 +93,7 @@ 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-dirty &&
+	expect_from_to >expect.body $subtip $subprev &&
  	test_cmp expect.body actual.body
  '
 
@@ -168,13 +168,13 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)'
  		git clean -qfdx &&
  		>cruft

t/t4027-diff-submodule.sh test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' · line 177

Quoted 10 lines
t/t4027-diff-submodule.sh +2 -2
  	) &&
-	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 &&

This checks the new default which is good

Quoted 147 lines
t/t4027-diff-submodule.sh +0 -0
  	test_must_be_empty actual3 &&
  	git diff --ignore-submodules=dirty HEAD >actual4 &&
  	test_must_be_empty actual4
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..bb368b685d 100755
@@ -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 --submodule=log HEAD --ignore-submodules=none >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 --submodule=log HEAD --ignore-submodules=none >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:
t/t4060-diff-submodule-option-diff-format.sh +7 -7
index fc8229c726..dc7b242697 100755
@@ -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

t/t4060-diff-submodule-option-diff-format.sh test_expect_success 'modified submodule contains untracked and modified content' · line 589

Quoted 8 lines
t/t4060-diff-submodule-option-diff-format.sh +1 -1
@@ -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:

I think all the diff tests look fine and we seem to have a good mix of testing the new default and --ignore-submodules=none

t/t7064-wtstatus-pv2.sh test_expect_success 'create and add submodule, submodule appears clean (A. S...) · line 486

Quoted 10 lines
t/t7064-wtstatus-pv2.sh +1 -1
index 537787e598..200626251e 100755
@@ -483,7 +483,7 @@ test_expect_success 'create and add submodule, submodule appears clean (A. S...)
  	)
  '
 
-test_expect_success 'untracked changes in added submodule (AM S..U)' '
+test_expect_success 'untracked changes in added submodule (A. S...))' '

typo: there's an extra ')'

Quoted 22 lines
t/t7064-wtstatus-pv2.sh +2 -2
  	(	cd super_repo &&
  		## create untracked file in the submodule.
  		(	cd sub1 &&
@@ -500,7 +500,7 @@ test_expect_success 'untracked changes in added submodule (AM S..U)' '
  		# branch.upstream origin/master
  		# branch.ab +0 -0
  		1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
-		1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1
+		1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1
  		EOF
 
  		git status --porcelain=v2 --branch --untracked-files=all >actual &&
@@ -560,7 +560,7 @@ test_expect_success 'staged and unstaged changes in added (AM S.M.)' '
  	)
  '
 
-test_expect_success 'staged and untracked changes in added submodule (AM S.MU)' '
+test_expect_success 'staged and untracked changes in added submodule (AM S.M.)' '
  	(	cd super_repo &&
  		(	cd sub1 &&
  			## stage new changes in tracked file.

t/t7064-wtstatus-pv2.sh test_expect_success 'staged and untracked changes in added submodule (AM S.MU)' · line 584

Quoted 7 lines
t/t7064-wtstatus-pv2.sh +1 -1
@@ -579,7 +579,7 @@ test_expect_success 'staged and untracked changes in added submodule (AM S.MU)'
  		# branch.upstream origin/master
  		# branch.ab +0 -0
  		1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
-		1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1
+		1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
  		EOF
 

I'm not sure about the changes in this file, maybe we should be testing the new default and --ignore-submodules=none

Quoted 110 lines
t/t7064-wtstatus-pv2.sh +0 -0
  		git status --porcelain=v2 --branch --untracked-files=all >actual &&
t/t7506-status-submodule.sh +9 -28
index 3fcb44767f..b7ff7928fb 100755
@@ -95,7 +95,7 @@ test_expect_success 'status with untracked file in submodule' '
  	(cd sub && git reset --hard) &&
  	echo "content" >sub/new-file &&
  	git status >output &&
-	test_i18ngrep "modified:   sub (untracked content)" output
+	test_i18ngrep "^nothing to commit" output
  '
 
  test_expect_success 'status -uno with untracked file in submodule' '
@@ -105,23 +105,19 @@ test_expect_success 'status -uno with untracked file in submodule' '
 
  test_expect_success 'status with untracked file in submodule (porcelain)' '
  	git status --porcelain >output &&
-	diff output - <<-\EOF
-	 M sub
-	EOF
+	test_must_be_empty output
  '
 
  test_expect_success 'status with untracked file in submodule (short)' '
  	git status --short >output &&
-	diff output - <<-\EOF
-	 ? sub
-	EOF
+	test_must_be_empty output
  '
 
  test_expect_success 'status with added and untracked file in submodule' '
  	(cd sub && git reset --hard && echo >foo && git add foo) &&
  	echo "content" >sub/new-file &&
  	git status >output &&
-	test_i18ngrep "modified:   sub (modified content, untracked content)" output
+	test_i18ngrep "modified:   sub (modified content)" output
  '
 
  test_expect_success 'status with added and untracked file in submodule (porcelain)' '
@@ -169,7 +165,7 @@ test_expect_success 'status with untracked file in modified submodule' '
  	(cd sub && git reset --hard) &&
  	echo "content" >sub/new-file &&
  	git status >output &&
-	test_i18ngrep "modified:   sub (new commits, untracked content)" output
+	test_i18ngrep "modified:   sub (new commits)" output
  '
 
  test_expect_success 'status with untracked file in modified submodule (porcelain)' '
@@ -183,7 +179,7 @@ test_expect_success 'status with added and untracked file in modified submodule'
  	(cd sub && git reset --hard && echo >foo && git add foo) &&
  	echo "content" >sub/new-file &&
  	git status >output &&
-	test_i18ngrep "modified:   sub (new commits, modified content, untracked content)" output
+	test_i18ngrep "modified:   sub (new commits, modified content)" output
  '
 
  test_expect_success 'status with added and untracked file in modified submodule (porcelain)' '
@@ -350,30 +346,17 @@ test_expect_success 'setup superproject with untracked file in nested submodule'
 
  test_expect_success 'status with untracked file in nested submodule (porcelain)' '
  	git -C super status --porcelain >output &&
-	diff output - <<-\EOF
-	 M sub1
-	 M sub2
-	 M sub3
-	EOF
+	test_must_be_empty output
  '
 
  test_expect_success 'status with untracked file in nested submodule (porcelain=2)' '
  	git -C super status --porcelain=2 >output &&
-	sanitize_output output &&
-	diff output - <<-\EOF
-	1 .M S..U 160000 160000 160000 HASH HASH sub1
-	1 .M S..U 160000 160000 160000 HASH HASH sub2
-	1 .M S..U 160000 160000 160000 HASH HASH sub3
-	EOF
+	test_must_be_empty output
  '
 
  test_expect_success 'status with untracked file in nested submodule (short)' '
  	git -C super status --short >output &&
-	diff output - <<-\EOF
-	 ? sub1
-	 ? sub2
-	 ? sub3
-	EOF
+	test_must_be_empty output
  '
 
  test_expect_success 'setup superproject with modified file in nested submodule' '
@@ -386,7 +369,6 @@ test_expect_success 'status with added file in nested submodule (porcelain)' '
  	diff output - <<-\EOF
  	 M sub1
  	 M sub2
-	 M sub3
  	EOF
  '
 
@@ -396,7 +378,6 @@ test_expect_success 'status with added file in nested submodule (porcelain=2)' '
  	diff output - <<-\EOF
  	1 .M S.M. 160000 160000 160000 HASH HASH sub1
  	1 .M S.M. 160000 160000 160000 HASH HASH sub2
-	1 .M S..U 160000 160000 160000 HASH HASH sub3
  	EOF
  '
 

t/t7506-status-submodule.sh test_expect_success 'status with added file in nested submodule (short)' ' · line 390

Quoted 6 lines
t/t7506-status-submodule.sh +0 -1
@@ -405,7 +386,6 @@ test_expect_success 'status with added file in nested submodule (short)' '
  	diff output - <<-\EOF
  	 m sub1
  	 m sub2
-	 ? sub3
  	EOF
  '

I think we want to keep testing that we get the correct output when --ignore-submodules=none as well as maybe adding a couple of new tests that check the default in this file, rather than changing the expected output.

Best Wishes

Phillip

Quoted 2 lines

base-commit: d98273ba77e1ab9ec755576bc86c716a97bf59d7

#2 lore raw

Hey Phillip,

Quoted 6 lines

I think we require your full name on the From line to match the Signed-off-by line below (c.f.
https://lore.kernel.org/git/[email protected])

That is a good summary of the issue that this change addresses, we normally wrap lines at 72 characters though.

This was sent by gitgitgadget so I am unable to find how I can customize it. Can you help me with this? Or else I have set the Travis so should I send another patch using send-email?

Quoted 4 lines

This unconditionally overrides diff.ignoreSubmodules, grepping seems to show that we don't have any tests that test a config value of "none". There are a few that check "dirty" which we should look at to consider if they still add value now we've changed the default.

Yes, sorry, noticed it now. I have now added a flag in diff_flags. Also, do I have to add tests that check whether diff.ignoreSubmodules is not being overwritten?

Quoted 13 lines
      if (diff_no_prefix) {
              options->a_prefix = options->b_prefix = "";
submodule.c +2 -0
index b3bb59f066..762298c010 100644
@@ -1678,6 +1678,8 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
      strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
      if (ignore_untracked)
              strvec_push(&cp.args, "-uno");
+     else
+        strvec_push (&cp.args, "--ignore-submodules=none");
 
Quoted 5 lines

We need to do this as a consequence of changing the default for '--ignore-submodules, we should think what the consequences are for other users of git status` and whether we need to do something similar there if diff.ignoreSubmodules is not set.

Oh okay. I understood what you said. But I couldn't figure out how to do that. As all the tests of status were passing so I don't think there might be any issue with this.

Quoted 6 lines

I think we want to keep testing that we get the correct output when --ignore-submodules=none as well as maybe adding a couple of new tests that check the default in this file, rather than changing the expected output.

Thanks, I have added more tests.

Thanks and Regards,
Sangeeta

#3 lore raw

Hi Sangeeta

Quoted 6 lines · Sangeeta NB

Hey Phillip,

Quoted 3 lines

I think we require your full name on the From line to match the Signed-off-by line below (c.f.
https://lore.kernel.org/git/[email protected])

Quoted 6 lines
Quoted 2 lines

That is a good summary of the issue that this change addresses, we normally wrap lines at 72 characters though.

This was sent by gitgitgadget so I am unable to find how I can customize it. Can you help me with this? Or else I have set the Travis so should I send another patch using send-email?

When you create the commit message you need to get your editor to wrap the lines with line breaks, how you do this depends on your editor - for emacs you can use fill-paragraph, in vim 'gq' you should be able to google it for your editor.

It would be a good idea to add [Outreachy] to the beginning of the commit subject line as well so people can easily find outreachy related patches on the list (anything inside [] is removed by git am when the patch is applied)

Quoted 8 lines
Quoted 4 lines

This unconditionally overrides diff.ignoreSubmodules, grepping seems to show that we don't have any tests that test a config value of "none". There are a few that check "dirty" which we should look at to consider if they still add value now we've changed the default.

Yes, sorry, noticed it now. I have now added a flag in diff_flags. Also, do I have to add tests that check whether diff.ignoreSubmodules is not being overwritten?

I think adding a test that checks diff.ignoreSubmodules=none is respected would be a good idea

Quoted 14 lines
Quoted 14 lines
       if (diff_no_prefix) {
               options->a_prefix = options->b_prefix = "";
submodule.c +2 -0
index b3bb59f066..762298c010 100644
@@ -1678,6 +1678,8 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
       strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
       if (ignore_untracked)
               strvec_push(&cp.args, "-uno");
+     else
+        strvec_push (&cp.args, "--ignore-submodules=none");
 
Quoted 8 lines
Quoted 5 lines

We need to do this as a consequence of changing the default for '--ignore-submodules, we should think what the consequences are for other users of git status` and whether we need to do something similar there if diff.ignoreSubmodules is not set.

Oh okay. I understood what you said. But I couldn't figure out how to do that.

I'm not sure if we need to do this or not, I was hoping to get some input from the list

Quoted 2 lines

As all the tests of status were passing so I don't think there might be any issue with this.

Possibly, though I think it is more likely that we're not testing anything that gets broken by this change.

Best Wishes

Phillip

Quoted 11 lines
Quoted 5 lines

I think we want to keep testing that we get the correct output when --ignore-submodules=none as well as maybe adding a couple of new tests that check the default in this file, rather than changing the expected output.

Thanks, I have added more tests.

Thanks and Regards,
Sangeeta

#4 lore raw

PATCH v2 1/1 diff: do not show submodule with untracked files as "-dirty"

In reply to Sangeeta via GitGitGadget

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.

This patch makes git diff HEAD consistent with git describe --dirty when a submodule contains untracked files by making --ignore-submodules=untracked the default.

Also, to avoid ignoreSubmodules in user config being overwritten, I have made added a flag in diff_flags to keep a track whether handle_ignore_submodules_arg is called before or not.

---
 diff.c                                       |   3 +
 diff.h                                       |   1 +
 submodule.c                                  |   3 +
 t/t3701-add-interactive.sh                   |   2 +-
 t/t4027-diff-submodule.sh                    |  15 ++-
 t/t4041-diff-submodule-option.sh             |  16 +--
 t/t4060-diff-submodule-option-diff-format.sh |  16 +--
 t/t7064-wtstatus-pv2.sh                      |  52 ++++++++++
 t/t7506-status-submodule.sh                  | 102 ++++++++++++++++---
 9 files changed, 178 insertions(+), 32 deletions(-)
diff.c +3 -0
index 2bb2f8f57e..027462a339 100644
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	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 = "";
diff.h +1 -0
index 11de52e9e9..1e18e6b1c3 100644
@@ -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;
submodule.c +3 -0
index b3bb59f066..efaba0eff2 100644
@@ -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;
@@ -1678,6 +1679,8 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 	strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
 	if (ignore_untracked)
 		strvec_push(&cp.args, "-uno");
+	else
+        strvec_push (&cp.args, "--ignore-submodules=none");
 
 	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
t/t3701-add-interactive.sh +1 -1
index ca04fac417..98e46ad1ae 100755
@@ -761,7 +761,7 @@ test_expect_success 'setup different kinds of dirty submodules' '
 		echo dirty >>initial &&
 		: >untracked
 	) &&
-	git -C for-submodules diff-files --name-only >actual &&
+	git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
 	cat >expected <<-\EOF &&
 	dirty-both-ways
 	dirty-head
t/t4027-diff-submodule.sh +12 -3
index d7145ccca4..6432b4331f 100755
@@ -93,10 +93,19 @@ 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-dirty &&
+	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)' '
+	git 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 &&
+	git config --unset diff.ignoreSubmodules
+'
+
 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
 	git commit -m "x" sub &&
 	echo >>sub/world &&
@@ -168,13 +177,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
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..bb368b685d 100755
@@ -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 --submodule=log HEAD --ignore-submodules=none >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 --submodule=log HEAD --ignore-submodules=none >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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
t/t7064-wtstatus-pv2.sh +52 -0

64 lines not on this page · raw message

t/t7506-status-submodule.sh +90 -12

202 lines not on this page · raw message

Signature · 1 line
2.21.1 (Apple Git-122.3)
#5 lore raw

diff.c void repo_diff_setup(struct repository *r, struct diff_options *options) · line 4586

Quoted 11 lines · Sangeeta Jain

[...]
This patch makes git diff HEAD consistent with git describe --dirty when a submodule contains untracked files by making --ignore-submodules=untracked the default.

---

diff.c +2 -0
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
+       if(!options->flags.ignore_submodule_set)
+               options->flags.ignore_untracked_in_submodules = 1;

Style nit: insert a space between 'if' and the opening parenthesis

submodule.c unsigned is_submodule_modified(const char *path, int ignore_untracked) · line 1682

Quoted 6 lines
submodule.c +2 -0
@@ -1678,6 +1679,8 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
        if (ignore_untracked)
                strvec_push(&cp.args, "-uno");
+       else
+        strvec_push (&cp.args, "--ignore-submodules=none");

Style nit: use TAB for indentation, not spaces

Style nit: drop space between 'strvec_push' and open parenthesis

t/t7064-wtstatus-pv2.sh test_expect_success 'untracked changes in added submodule (AM S..U)' ' · line 508

Quoted 8 lines
t/t7064-wtstatus-pv2.sh +6 -0
@@ -503,6 +503,31 @@ test_expect_success 'untracked changes in added submodule (AM S..U)' '
+test_expect_success 'untracked changes in added submodule (A. S...) (untracked ignored)' '
+       (       cd super_repo &&
+               ## create untracked file in the submodule.
+               (       cd sub1 &&
+                       echo "xxxx" >file_in_sub
+               ) &&

I realize that you're following style of some, but not all tests, in this file, but current the way we format subshells these days is:

    (
        cd foo &&
        ...
    ) &&

Whether you should adopt modern style or use existing style is a judgment call. (If I was doing this, I might be inclined to follow modern style rather than introducing even more of the unwanted old style.)

But for really silly stuff like the 'echo', you don't need a subshell at all, so it would be cleaner to write it like this without the subshell:

    echo "xxxx" >sub1/file_in_sub &&

(But again, I see that you're just following local style.)

t/t7064-wtstatus-pv2.sh test_expect_success 'staged and untracked changes in added submodule (AM S.MU)' · line 622

Quoted 8 lines
t/t7064-wtstatus-pv2.sh +8 -0
+test_expect_success 'staged and untracked changes in added submodule (AM S.M.) (untracked ignored)' '
+       (       cd super_repo &&
+               (       cd sub1 &&
+                       ## stage new changes in tracked file.
+                       git add file_in_sub &&
+                       ## create new untracked file.
+                       echo "yyyy" >>another_file_in_sub
+               ) &&

These days, git also understands -C, so this subshell likewise is not necessary, and:

git -C sub1 add file_in_sub &&
echo "yyyy" >>sub1/another_file_in_sub

would be equivalent. (But perhaps that diverges too much from existing style in the file? It's a judgment call.)

t/t7506-status-submodule.sh test_expect_success 'status with added file in submodule (short)' ' · line 95

Quoted 4 lines
t/t7506-status-submodule.sh +2 -0
@@ -94,36 +94,60 @@ test_expect_success 'status with added file in submodule (short)' '
+test_expect_success 'status with untracked file in submodule (untracked ignored)' '
+       (cd sub && git reset --hard) &&

These one-liner subshells are super common in this particular script. These days we'd write this as:

    git -C sub reset --hard &&

Again, it's a judgment call whether to go with modern style or follow existing style of the file.

Another option is to have a preparatory patch which first modernizes the script, and then your new tests would follow modern style. But, that may be outside of scope of your submission.

To summarize: The only really actionable review comments are the minor style nits in the C code. The nits about style issues in the tests are judgement calls, and could be handled (by someone) at a later date.

#6 lore raw

Hey,

Quoted 10 lines

Again, it's a judgment call whether to go with modern style or follow existing style of the file.

Another option is to have a preparatory patch which first modernizes the script, and then your new tests would follow modern style. But, that may be outside of scope of your submission.

To summarize: The only really actionable review comments are the minor style nits in the C code. The nits about style issues in the tests are judgement calls, and could be handled (by someone) at a later date.

Thanks for the feedback, Eric. I would add the style nits in the upcoming patch.

For the style issues in the tests maybe what I can do is I can submit another patch with this patch to modernize the test scripts of these files? I am expecting some feedback from the community on how to handle this.

#7 lore raw
Quoted 4 lines · Sangeeta NB
Quoted 4 lines

Another option is to have a preparatory patch which first modernizes the script, and then your new tests would follow modern style. But, that may be outside of scope of your submission.

Quoted 8 lines
Quoted 3 lines

To summarize: The only really actionable review comments are the minor style nits in the C code. The nits about style issues in the tests are judgement calls, and could be handled (by someone) at a later date.

For the style issues in the tests maybe what I can do is I can submit another patch with this patch to modernize the test scripts of these files? I am expecting some feedback from the community on how to handle this.

If this is a microproject, then it probably makes sense just to fix the remaining style nits in the C code, and leave it at that.

Even if this is not a microproject, the answer really depends upon how much time and effort you want to devote to this. As a reviewer, I don't demand or expect you to fix all the problems in the old test scripts just to get the change accepted which prompted your submission in the first place. It's important to focus on that first rather than getting sidetracked working on stuff which may not be important to your primary goal. Also, keep in mind that fixing all the style issues in those old test scripts may require multiple preparatory patches, rather than just one, and multiple re-rolls, which could end up eating up a lot of extra time to get it all polished properly.

For these reasons, I'm inclined to suggest polishing the current submission to get it accepted. Then decide afterward if you want to devote time to working on these ancillary tasks.

#8 lore raw

PATCH v3 1/1 diff: do not show submodule with untracked files as "-dirty"

In reply to Sangeeta via GitGitGadget

From: sangu09 <[email protected]>

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.

This patch makes git diff HEAD consistent with git describe --dirty when a submodule contains untracked files by making --ignore-submodules=untracked the default.

Also, to avoid ignoreSubmodules in user config being overwritten, I have made added a flag in diff_flags to keep a track whether handle_ignore_submodules_arg is called before or not.

---
 diff.c                                       |   3 +
 diff.h                                       |   1 +
 submodule.c                                  |   5 +-
 t/t3701-add-interactive.sh                   |   2 +-
 t/t4027-diff-submodule.sh                    |  15 ++-
 t/t4041-diff-submodule-option.sh             |  16 +--
 t/t4060-diff-submodule-option-diff-format.sh |  16 +--
 t/t7064-wtstatus-pv2.sh                      |  52 ++++++++++
 t/t7506-status-submodule.sh                  | 102 ++++++++++++++++---
 9 files changed, 179 insertions(+), 33 deletions(-)
diff.c +3 -0
index 2bb2f8f57e..5a80695da8 100644
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	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 = "";
diff.h +1 -0
index 11de52e9e9..1e18e6b1c3 100644
@@ -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;
submodule.c +4 -1
index b3bb59f066..a7956e1539 100644
@@ -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;
@@ -1677,7 +1678,9 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 
 	strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
 	if (ignore_untracked)
-		strvec_push(&cp.args, "-uno");
+		strvec_push (&cp.args, "-uno");
+	else
+    	strvec_push (&cp.args, "--ignore-submodules=none");
 
 	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
t/t3701-add-interactive.sh +1 -1
index ca04fac417..98e46ad1ae 100755
@@ -761,7 +761,7 @@ test_expect_success 'setup different kinds of dirty submodules' '
 		echo dirty >>initial &&
 		: >untracked
 	) &&
-	git -C for-submodules diff-files --name-only >actual &&
+	git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
 	cat >expected <<-\EOF &&
 	dirty-both-ways
 	dirty-head
t/t4027-diff-submodule.sh +12 -3
index d7145ccca4..6432b4331f 100755
@@ -93,10 +93,19 @@ 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-dirty &&
+	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)' '
+	git 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 &&
+	git config --unset diff.ignoreSubmodules
+'
+
 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
 	git commit -m "x" sub &&
 	echo >>sub/world &&
@@ -168,13 +177,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
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..bb368b685d 100755
@@ -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 --submodule=log HEAD --ignore-submodules=none >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 --submodule=log HEAD --ignore-submodules=none >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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
t/t7064-wtstatus-pv2.sh +52 -0

64 lines not on this page · raw message

t/t7506-status-submodule.sh +90 -12

202 lines not on this page · raw message

Signature · 1 line
2.21.1 (Apple Git-122.3)
#9 lore raw
Quoted 1 line · Sangeeta Jain

From: sangu09 <[email protected]>

Oops?

Quoted 4 lines

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.

Nicely written.

Quoted 3 lines

This patch makes git diff HEAD consistent with git describe --dirty when a submodule contains untracked files by making --ignore-submodules=untracked the default.

Instead of explaining "This patch makes...", it is more common to give an order to the codebase, i.e. "Make...".

Quoted 3 lines

Also, to avoid ignoreSubmodules in user config being overwritten, I have made added a flag in diff_flags to keep a track whether handle_ignore_submodules_arg is called before or not.

Well, that is not "Also"; it is an integral part of making "--ignore-submodules=untracked" the _default_. We need to make sure that end-user configuration would be honored, and we need to make sure that the command line option would be honored, too.

I'd suggest to follow the excellent first paragraph above with something like the following.

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.

diff.c void repo_diff_setup(struct repository *r, struct diff_options *options) · line 4589

Quoted 6 lines
diff.c +2 -0
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	options->orderfile = diff_order_file_cfg;
+	
+	if (!options->flags.ignore_submodule_set)

This new boolean is meant to be set only when non-default ignore-submodules option is given either from the command line or from the configuration---when the bit is unset, we are told to do whatever it is that is the default for us.

diff.c void repo_diff_setup(struct repository *r, struct diff_options *options) · line 4590

Quoted 1 line
diff.c +1 -0
+		options->flags.ignore_untracked_in_submodules = 1;

And the default is to flip only this bit on. Do we need to turn off other bits that submodule.c::handle_ignore_submodules_arg() function touches? [*1*]

Quoted 17 lines
diff.h +1 -0
index 11de52e9e9..1e18e6b1c3 100644
@@ -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;
submodule.c +0 -0
index b3bb59f066..a7956e1539 100644

submodule.c const char *submodule_strategy_to_string(const struct submodule_update_strategy · line 423

Quoted 4 lines
submodule.c +1 -0
@@ -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;

I like the general idea of having one bit that is set if and only if the command line or configuration told us specifically what to do, so that we can dictate the default after they were taken care of.

But I am not sure if this is a good implementation of that idea.

Case in point. I was wondering if the most future-proof way to answer the question I asked (marked with [*1*] above) was to avoid flipping the bits in options->flags ourselves, but to make a call

	handle_ignore_submodules_arg(&options, "untracked");

in repo_diff_setup(). When such an improvement is made after this patch lands, the assumption that only the end-user preference will call this function no longer holds.

Even without anticipating such a change in the future, there already is a callsite of this function in wt-status.c that hands a hardcoded string "dirty" to it. That is *not* caused by an end-user request (be it a configuration variable or a command line option), so in a sense, the assumption is already broken.

I wonder, if we can do things in a more natural way (at least the natural way in this codebase). Usually we do things in this order:

- initialize the status and option variables to their default state.

- read the configuration files to allow the state of these variables to be modified from their default state.

- parse the command line arguments to further allow the state of these variables to be modified.

and then use the final state of these variables. That way, we do not even need the extra bit that is only required if we did things in an unnatural way, which is

- read the config; remember if any bits were toggled
- parse the command line; remember if any bits were toggled
- only if bits weren't toggled in the above, set the default

I dunno.

submodule.c unsigned is_submodule_modified(const char *path, int ignore_untracked) · line 1681

Quoted 6 lines
submodule.c +1 -1
@@ -1677,7 +1678,9 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 
 	strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
 	if (ignore_untracked)
-		strvec_push(&cp.args, "-uno");
+		strvec_push (&cp.args, "-uno");

Noise.

submodule.c unsigned is_submodule_modified(const char *path, int ignore_untracked) · line 1683

Quoted 2 lines
submodule.c +2 -0
+	else
+    	strvec_push (&cp.args, "--ignore-submodules=none");

Misindented.

#10 lore raw

Hey,

Sorry for sending it over and over again. I couldn't figure out why the mail is not reaching the community.

Quoted 3 lines

Oops?

Sorry about this. Would correct it in the next patch.

Quoted 9 lines

I'd suggest to follow the excellent first paragraph above with something like the following.

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.

Very well written. Would update the description to this. Thanks.

Quoted 4 lines

This new boolean is meant to be set only when non-default ignore-submodules option is given either from the command line or from the configuration---when the bit is unset, we are told to do whatever it is that is the default for us.

I fear I might not get your question clearly here. But from what I understood this boolean( flags.ignore_submodule_set ) is set only when diff.ignoreSubmodules is set in user-config.

Quoted 4 lines

And the default is to flip only this bit on. Do we need to turn off other bits that submodule.c::handle_ignore_submodules_arg() function touches? [*1*]

We are not flipping the bit, we are setting it to 1. I guess we don't have to turn off other bits because in case if submodule.c::handle_ignore_submodules_arg() is called we don't have to set the default value. So there's no point in flipping any other bits as if any of them is set, the user should have added some arguments in
ignoreSubmodules and therefore flags.ignore_submodule_set would be
set to 1 and we won't be setting the default value.

Quoted 11 lines

I like the general idea of having one bit that is set if and only if the command line or configuration told us specifically what to do, so that we can dictate the default after they were taken care of.

But I am not sure if this is a good implementation of that idea.

Case in point. I was wondering if the most future-proof way to answer the question I asked (marked with [*1*] above) was to avoid flipping the bits in options->flags ourselves, but to make a call

Quoted 5 lines
        handle_ignore_submodules_arg(&options, "untracked");

in repo_diff_setup(). When such an improvement is made after this patch lands, the assumption that only the end-user preference will call this function no longer holds.

I tried making the call directly like this:
handle_ignore_submodules_arg(&options, "untracked") without using the extra bit, but in the case when the user specifies diff.ignoreSubmodules in user-config, the handle_ignore_submodules_arg() is called even before repo_diff_setup() and therefore the default value overwrites the value mentioned in user-config.

Quoted 6 lines

Even without anticipating such a change in the future, there already is a callsite of this function in wt-status.c that hands a hardcoded string "dirty" to it. That is *not* caused by an end-user request (be it a configuration variable or a command line option), so in a sense, the assumption is already broken.

I couldn't fully understand what assumption are you talking about. I would be glad if you can explain it to me in a little more detail. Thanks!

Quoted 15 lines

I wonder, if we can do things in a more natural way (at least the natural way in this codebase). Usually we do things in this order:

- initialize the status and option variables to their default state.

- read the configuration files to allow the state of these variables to be modified from their default state.

- parse the command line arguments to further allow the state of these variables to be modified.

and then use the final state of these variables. That way, we do not even need the extra bit that is only required if we did things in an unnatural way, which is

Quoted 5 lines

- read the config; remember if any bits were toggled
- parse the command line; remember if any bits were toggled
- only if bits weren't toggled in the above, set the default

I dunno.

Ya, that makes sense. I would look into when the config values are being read and bits are set and would try to find a way so that we can get rid of the extra bit. Thanks for pointing this out.

Quoted 3 lines

Noise.

I hope this is a substitute for nice. XD. Hearing this after a long time. I used to hear this more frequently when I was in college.

Quoted 2 lines

Misindented.

Noted. Would change that in the next patch.

Thanks and regards,
Sangeeta

#11 lore raw
Quoted 2 lines · Sangeeta NB

Sorry for sending it over and over again. I couldn't figure out why the mail is not reaching the community.

FWIW, I'm seeing it for the first time, so no worries ;)

Quoted 8 lines
Quoted 4 lines

This new boolean is meant to be set only when non-default ignore-submodules option is given either from the command line or from the configuration---when the bit is unset, we are told to do whatever it is that is the default for us.

I fear I might not get your question clearly here. But from what I understood this boolean( flags.ignore_submodule_set ) is set only when diff.ignoreSubmodules is set in user-config.

The four-line paragraph I wrote above is not a question. It is normal to "think aloud" to express what the reader understood what the patch does/intends to do during the review, which gives the contributor a chance to spot misunderstanding by the reviewer.

In any case, when "git diff --ignore-submodules=<when>" command line option is parsed, diff_opt_ignore_submodules() gets called, which in turn calls handle_ignore_submodules_arg(), and you set the bit there.

So this is not limited to configuration, I think. Command line option given by the user can also affect it.

Moreover, wt-status.c:wt_status_collect_changes_index() hardcodes a call to handle_ignore_submodules_arg() with hardcoded "dirty" unless the caller specifies s->ignore_submodule_arg. This is not even user-config or any user action---it is more like a hardcoded default.

Quoted 6 lines
Quoted 4 lines

And the default is to flip only this bit on. Do we need to turn off other bits that submodule.c::handle_ignore_submodules_arg() function touches? [*1*]

We are not flipping the bit, we are setting it to 1.

Yeah, flipping it to on is setting it to 1. We are saying the same thing, aren't we?

Quoted 9 lines

I guess we don't
have to turn off other bits because in case if submodule.c::handle_ignore_submodules_arg() is called we don't have to set the default value.

So there's no point in flipping any other bits
as if any of them is set, the user should have added some arguments in
ignoreSubmodules and therefore flags.ignore_submodule_set would be
set to 1 and we won't be setting the default value.

The reason why a helper function handle_ignore_submodules_arg() exists in the first place is because the way ignore_* bits are managed in the diff_options.flags is tricky and with a helper in between the callers and the actual bits, is easier to update in the future if needed.

So even if we assume that everybody who reacted to end-user preference would have called handle_ignore_submodules_arg(), hence we do not want to force our default when the .ignore_submodule_set bit set and we do want to do so when the bit is unset, we should do

	if (!options->flags.ignore_submodule_set)
		handle_ignore_submodules_arg("untracked");

instead of only toggling the .ignore_untracked_in_submodules bit on manually.

Quoted 10 lines
Quoted 9 lines

I like the general idea of having one bit that is set if and only if the command line or configuration told us specifically what to do, so that we can dictate the default after they were taken care of.
...
Even without anticipating such a change in the future, there already is a callsite of this function in wt-status.c that hands a hardcoded string "dirty" to it. That is *not* caused by an end-user request (be it a configuration variable or a command line option), so in a sense, the assumption is already broken.

Quoted 2 lines

I couldn't fully understand what assumption are you talking about. I would be glad if you can explain it to me in a little more detail.

Have you looked for "dirty" (with double-quote around the word) in wt-status.c already? The call to handle_ignore_submodules_arg(), which would cause your new bit set, is made not as a reaction to any end-user input. Rather it is "if end-user did not say anything, use this hardcoded setting". And it overrides the "if the end user did not specify anything, we want to use this default" logic you added with this change, because it dictates "dirty" there without end-user asking.

Is that desirable? I dunno.

Quoted 4 lines
Quoted 2 lines

Noise.

I hope this is a substitute for nice. XD. Hearing this after a long time. I used to hear this more frequently when I was in college.

I found this change a "noise":

strvec_pushl(&cp.args, "status", "--porcelain=2", NULL); if (ignore_untracked)
- strvec_push(&cp.args, "-uno");
+ strvec_push (&cp.args, "-uno");

If it were going the other direction, "we fix coding style violation while at it" may be a good justification to do so, but this particular change (1) is not neeeded for the purpose of this patch, and (2) is making the code worse by deviating from the coding guideline. Please drop it.

Thanks.

#12 lore raw
Quoted 5 lines

The four-line paragraph I wrote above is not a question. It is normal to "think aloud" to express what the reader understood what the patch does/intends to do during the review, which gives the contributor a chance to spot misunderstanding by the reviewer.

Oh okay. I thought you meant to ask something. But ya "think aloud" is a nice practice. Sorry for the confusion.

Quoted 7 lines

In any case, when "git diff --ignore-submodules=<when>" command line option is parsed, diff_opt_ignore_submodules() gets called, which in turn calls handle_ignore_submodules_arg(), and you set the bit there.

So this is not limited to configuration, I think. Command line option given by the user can also affect it.

Umm, so when diff.ignoreSubmodules is set in user config, git_diff_ui_config() is called which is called(which calls handle_ignore_submodules_arg) even before repo_git_setup() and therefore it sets the bit there. But in the case of command-line options, as you mentioned, diff_opt_ignore_submodules() gets called by the prep_parse_options() which is called after we are checking for that bit. So when we are checking for the bit, prep_parse_options() is not yet called, and therefore that bit is not set.

Quoted 3 lines

Yeah, flipping it to on is setting it to 1. We are saying the same thing, aren't we?

Ya, sorry for the misunderstanding. We are saying the same thing.

Quoted 14 lines

The reason why a helper function handle_ignore_submodules_arg() exists in the first place is because the way ignore_* bits are managed in the diff_options.flags is tricky and with a helper in between the callers and the actual bits, is easier to update in the future if needed.

So even if we assume that everybody who reacted to end-user preference would have called handle_ignore_submodules_arg(), hence we do not want to force our default when the .ignore_submodule_set bit set and we do want to do so when the bit is unset, we should do

Quoted 6 lines
        if (!options->flags.ignore_submodule_set)
                handle_ignore_submodules_arg("untracked");

instead of only toggling the .ignore_untracked_in_submodules bit on manually.

Oh okay, that makes sense. Would update that in the next patch.

Quoted 11 lines

Have you looked for "dirty" (with double-quote around the word) in wt-status.c already? The call to handle_ignore_submodules_arg(), which would cause your new bit set, is made not as a reaction to any end-user input. Rather it is "if end-user did not say anything, use this hardcoded setting". And it overrides the "if the end user did not specify anything, we want to use this default" logic you added with this change, because it dictates "dirty" there without end-user asking.

Is that desirable? I dunno.

This change was added in this[1] commit and as said there the "dirty" was used because here[2] if no arguments are provided with ignoreSubmodules then it set it to all and it might be confusing for git status as then even when the user chooses to record a new commit for an ignored submodule by adding it manually this change won't show up under the to-be-committed changes.(as mentioned in [1])

[1] https://github.com/git/git/commit/1d2f393ac9bfb4c20f14d6ead7bb4c56e766ab77
[2] https://github.com/git/git/blob/master/diff.c#L5139

So I think that's desirable.

Quoted 1 line

I found this change a "noise":

Oh okay, Again sorry for the misunderstanding.

Quoted 6 lines
        strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
        if (ignore_untracked)
submodule.c +1 -1
-               strvec_push(&cp.args, "-uno");
+               strvec_push (&cp.args, "-uno");
Quoted 6 lines

If it were going the other direction, "we fix coding style violation while at it" may be a good justification to do so, but this particular change (1) is not neeeded for the purpose of this patch, and (2) is making the code worse by deviating from the coding guideline. Please drop it.

This part of the change was introduced because we had a failing test here[3]. There was some problem it getting both the flags propagated through the nested submodule and that's why this change. Maybe we can do something better to fix that. It would be great if you can have a look at it.

[3] https://github.com/git/git/blob/master/t/t3600-rm.sh#L690

Thanks and Regards,
Sangeeta

#13 lore raw
Quoted 16 lines · Sangeeta NB
Quoted 1 line

I found this change a "noise":

Oh okay, Again sorry for the misunderstanding.

Quoted 6 lines
        strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
        if (ignore_untracked)
submodule.c +1 -1
-               strvec_push(&cp.args, "-uno");
+               strvec_push (&cp.args, "-uno");
Quoted 6 lines

If it were going the other direction, "we fix coding style violation while at it" may be a good justification to do so, but this particular change (1) is not neeeded for the purpose of this patch, and (2) is making the code worse by deviating from the coding guideline. Please drop it.

Quoted 3 lines

This part of the change was introduced because we had a failing test here[3]. There was some problem it getting both the flags propagated through ...

Are you talking about the new "else" clause added to the "if" statement we see above? I am not saying it is a "noise".

But look at what you did to the existing call to strvec_push() to add "-uno" shown above in the patch, i.e. the addition of space before the parenthesis. We cannot justify that change, can we? That's noise as far as I can see.

#14 lore raw
Quoted 23 lines · Junio C Hamano
Quoted 16 lines · Sangeeta NB
Quoted 1 line

I found this change a "noise":

Oh okay, Again sorry for the misunderstanding.

Quoted 6 lines
        strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
        if (ignore_untracked)
submodule.c +1 -1
-               strvec_push(&cp.args, "-uno");
+               strvec_push (&cp.args, "-uno");
Quoted 6 lines

If it were going the other direction, "we fix coding style violation while at it" may be a good justification to do so, but this particular change (1) is not neeeded for the purpose of this patch, and (2) is making the code worse by deviating from the coding guideline. Please drop it.

Quoted 3 lines

This part of the change was introduced because we had a failing test here[3]. There was some problem it getting both the flags propagated through ...

Quoted 7 lines

Are you talking about the new "else" clause added to the "if" statement we see above? I am not saying it is a "noise".

But look at what you did to the existing call to strvec_push() to add "-uno" shown above in the patch, i.e. the addition of space before the parenthesis. We cannot justify that change, can we? That's noise as far as I can see.

Oh okay. Now I understand. Ya, that doesn't make sense. I thought that Eric above suggested adding it but looking at it again, Eric was saying to drop the space in the else statement below and I misunderstood that to this. I am really very sorry about this. Would change it in the next patch.

Thanks again.

#15 lore raw

PATCH v4 1/1 diff: do not show submodule with untracked files as "-dirty"

In reply to Sangeeta via GitGitGadget

From: sangu09 <[email protected]>

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.

---
 diff.c                                       |   3 +
 diff.h                                       |   1 +
 submodule.c                                  |   5 +-
 t/t3701-add-interactive.sh                   |   2 +-
 t/t4027-diff-submodule.sh                    |  15 ++-
 t/t4041-diff-submodule-option.sh             |  16 +--
 t/t4060-diff-submodule-option-diff-format.sh |  16 +--
 t/t7064-wtstatus-pv2.sh                      |  52 ++++++++++
 t/t7506-status-submodule.sh                  | 102 ++++++++++++++++---
 9 files changed, 179 insertions(+), 33 deletions(-)
diff.c +3 -0
index 2bb2f8f57e..5a80695da8 100644
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	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 = "";
diff.h +1 -0
index 11de52e9e9..1e18e6b1c3 100644
@@ -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;
submodule.c +4 -1
index b3bb59f066..30c42cbffe 100644
@@ -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;
@@ -1677,7 +1678,9 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 
 	strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
 	if (ignore_untracked)
-		strvec_push(&cp.args, "-uno");
+		strvec_push (&cp.args, "-uno");
+	else
+		strvec_push (&cp.args, "--ignore-submodules=none");
 
 	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
t/t3701-add-interactive.sh +1 -1
index ca04fac417..98e46ad1ae 100755
@@ -761,7 +761,7 @@ test_expect_success 'setup different kinds of dirty submodules' '
 		echo dirty >>initial &&
 		: >untracked
 	) &&
-	git -C for-submodules diff-files --name-only >actual &&
+	git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
 	cat >expected <<-\EOF &&
 	dirty-both-ways
 	dirty-head
t/t4027-diff-submodule.sh +12 -3
index d7145ccca4..6432b4331f 100755
@@ -93,10 +93,19 @@ 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-dirty &&
+	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)' '
+	git 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 &&
+	git config --unset diff.ignoreSubmodules
+'
+
 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
 	git commit -m "x" sub &&
 	echo >>sub/world &&
@@ -168,13 +177,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
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..bb368b685d 100755
@@ -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 --submodule=log HEAD --ignore-submodules=none >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 --submodule=log HEAD --ignore-submodules=none >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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
t/t7064-wtstatus-pv2.sh +52 -0

64 lines not on this page · raw message

t/t7506-status-submodule.sh +90 -12

202 lines not on this page · raw message

Signature · 1 line
2.21.1 (Apple Git-122.3)
#16 lore raw
Quoted 7 lines · Sangeeta Jain

From: sangu09 <[email protected]>

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.

What happened to the first/introductory paragraph that was excellently written in the previous round?

The usaul way to compose a log message is to

- Give an observation on how the current system work in the present tense (so no need to say "Currently X is Y", just "X is Y"), and discuss what you perceive as a problem in it.

- Propose a solution (optional---often, problem description trivially leads to an obvious solution in reader's minds).

- Give commands to the codebase to "become like so".

The first paragraph you had in the previous round was a good example of the "observation". What we see above is only the "commands" part. To those who have been intimately following the discussion, it often is understandable without both, but we are not writing for those who review the patches. We are writing for future readers who are not aware of these exchanges we are having, so we should give something to prepare them by setting the stage and stating the objective.

diff.c void repo_diff_setup(struct repository *r, struct diff_options *options) · line 4590

Quoted 11 lines
diff.c +3 -0
index 2bb2f8f57e..5a80695da8 100644
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	options->orderfile = diff_order_file_cfg;
+	
+	if (!options->flags.ignore_submodule_set)
+		options->flags.ignore_untracked_in_submodules = 1;

I think I already touched about this one in the previous review.

diff.c void repo_diff_setup(struct repository *r, struct diff_options *options) · line 4593

Quoted 4 lines
diff.c +1 -1
 	strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
 	if (ignore_untracked)
-		strvec_push(&cp.args, "-uno");
+		strvec_push (&cp.args, "-uno");

Noise.

t/t3701-add-interactive.sh test_expect_success 'setup different kinds of dirty submodules' ' · line 767

Quoted 13 lines
t/t3701-add-interactive.sh +1 -1
index ca04fac417..98e46ad1ae 100755
@@ -761,7 +761,7 @@ test_expect_success 'setup different kinds of dirty submodules' '
 		echo dirty >>initial &&
 		: >untracked
 	) &&
-	git -C for-submodules diff-files --name-only >actual &&
+	git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
 	cat >expected <<-\EOF &&
 	dirty-both-ways
 	dirty-head

Hmph, it seems that you chose to give options that are no longer the default to command invocations, so that the expected output from the previous world order before this patch can be reused, but is that a sensible way to go? If we are changing the default behaviour, shouldn't we rather be testing that new behaviour, I wonder?

Quoted 60 lines
t/t7064-wtstatus-pv2.sh +45 -0
index 537787e598..78cd86be3a 100755
@@ -503,6 +503,31 @@ test_expect_success 'untracked changes in added submodule (AM S..U)' '
 		1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1
 		EOF
 
+		git status --porcelain=v2 --branch --untracked-files=all --ignore-submodules=none >actual &&
+		test_cmp expect actual
+	)
+'
+
+test_expect_success 'untracked changes in added submodule (A. S...) (untracked ignored)' '
+	(	cd super_repo &&
+		## create untracked file in the submodule.
+		(	cd sub1 &&
+			echo "xxxx" >file_in_sub
+		) &&
+
+		HMOD=$(git hash-object -t blob -- .gitmodules) &&
+		HSUP=$(git rev-parse HEAD) &&
+		HSUB=$HSUP &&
+
+		cat >expect <<-EOF &&
+		# branch.oid $HSUP
+		# branch.head master
+		# branch.upstream origin/master
+		# branch.ab +0 -0
+		1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
+		1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1
+		EOF
+
 		git status --porcelain=v2 --branch --untracked-files=all >actual &&
 		test_cmp expect actual
 	)
@@ -582,6 +607,33 @@ test_expect_success 'staged and untracked changes in added submodule (AM S.MU)'
 		1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1
 		EOF
 
+		git status --porcelain=v2 --branch --untracked-files=all --ignore-submodules=none >actual &&
+		test_cmp expect actual
+	)
+'
+
+test_expect_success 'staged and untracked changes in added submodule (AM S.M.) (untracked ignored)' '
+	(	cd super_repo &&
+		(	cd sub1 &&
+			## stage new changes in tracked file.
+			git add file_in_sub &&
+			## create new untracked file.
+			echo "yyyy" >>another_file_in_sub
+		) &&
+
+		HMOD=$(git hash-object -t blob -- .gitmodules) &&
+		HSUP=$(git rev-parse HEAD) &&
+		HSUB=$HSUP &&
+
+		cat >expect <<-EOF &&
+		# branch.oid $HSUP

t/t7064-wtstatus-pv2.sh test_expect_success 'staged and untracked changes in added submodule (AM S.MU)' · line 639

Quoted 10 lines
t/t7064-wtstatus-pv2.sh +7 -0
+		# branch.head master
+		# branch.upstream origin/master
+		# branch.ab +0 -0
+		1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
+		1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
+		EOF
+
 		git status --porcelain=v2 --branch --untracked-files=all >actual &&
 		test_cmp expect actual
 	)

OK.

By the way, in builtin/describe.c there is an invocation of "diff-index" without any --ignore-submodules=<what> option.

        /* diff-index command arguments to check if working tree is dirty. */
        static const char *diff_index_args[] = {
                "diff-index", "--quiet", "HEAD", "--", NULL
        };

Would the behaviour of diff-index invocation in "git describe --dirty" affected by the change of the default in any way?

Thanks.

#17 lore raw
Quoted 15 lines

What happened to the first/introductory paragraph that was excellently written in the previous round?

The usaul way to compose a log message is to

- Give an observation on how the current system work in the present tense (so no need to say "Currently X is Y", just "X is Y"), and discuss what you perceive as a problem in it.

- Propose a solution (optional---often, problem description trivially leads to an obvious solution in reader's minds).

- Give commands to the codebase to "become like so".

Quoted 8 lines

The first paragraph you had in the previous round was a good example of the "observation". What we see above is only the "commands" part. To those who have been intimately following the discussion, it often is understandable without both, but we are not writing for those who review the patches. We are writing for future readers who are not aware of these exchanges we are having, so we should give something to prepare them by setting the stage and stating the objective.

Oh okay, it makes sense. I thought you told to replace that all with this. Would change it in the next patch.

Quoted 12 lines
Quoted 12 lines
t/t3701-add-interactive.sh +1 -1
index ca04fac417..98e46ad1ae 100755
@@ -761,7 +761,7 @@ test_expect_success 'setup different kinds of dirty submodules' '
              echo dirty >>initial &&
              : >untracked
      ) &&
-     git -C for-submodules diff-files --name-only >actual &&
+     git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
      cat >expected <<-\EOF &&
Quoted 9 lines

t/t3701-add-interactive.sh test_expect_success 'setup different kinds of dirty submodules' ' · line 767

Quoted 2 lines
t/t3701-add-interactive.sh +0 -0
      dirty-both-ways
      dirty-head

Hmph, it seems that you chose to give options that are no longer the default to command invocations, so that the expected output from the previous world order before this patch can be reused, but is that a sensible way to go? If we are changing the default behaviour, shouldn't we rather be testing that new behaviour, I wonder?

I have tested the new behavior too. I have added tests for both the behavior, when ignore-submodules is none and when no argument is being passed.

Quoted 11 lines

By the way, in builtin/describe.c there is an invocation of "diff-index" without any --ignore-submodules=<what> option.

        /* diff-index command arguments to check if working tree is dirty. */
        static const char *diff_index_args[] = {
                "diff-index", "--quiet", "HEAD", "--", NULL
        };

Would the behaviour of diff-index invocation in "git describe --dirty" affected by the change of the default in any way?

I don't think so because describe was already behaving in the way that we won't. We changed the behavior of git diff to match it with that. So it doesn't make sense to add anything to that. Tell me if I am missing something.

Thanks for reviewing.

#18 lore raw
Quoted 8 lines · Sangeeta NB
Quoted 8 lines

By the way, in builtin/describe.c there is an invocation of "diff-index" without any --ignore-submodules=<what> option.

        /* diff-index command arguments to check if working tree is dirty. */
        static const char *diff_index_args[] = {
                "diff-index", "--quiet", "HEAD", "--", NULL
        };
Quoted 7 lines
Quoted 2 lines

Would the behaviour of diff-index invocation in "git describe --dirty" affected by the change of the default in any way?

I don't think so because describe was already behaving in the way that we won't. We changed the behavior of git diff to match it with that. So it doesn't make sense to add anything to that. Tell me if I am missing something.

How does "describe" see if the working tree is dirty? What mechanism does it use? Doesn't it run the "diff-index" command internally?

And with this patch, aren't you changing the default behaviour of "diff" family of commands by touching repo_diff_setup() function? How does it not affect the behaviour of the "diff-index" command, hence the input "git describe" uses to formulate its output?

#19 lore raw

PATCH v4 1/1 diff: do not show submodule with untracked files as "-dirty"

In reply to Sangeeta via GitGitGadget

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.

---
 diff.c                                       |   3 +
 diff.h                                       |   1 +
 submodule.c                                  |   5 +-
 t/t3701-add-interactive.sh                   |   2 +-
 t/t4027-diff-submodule.sh                    |  15 ++-
 t/t4041-diff-submodule-option.sh             |  16 +--
 t/t4060-diff-submodule-option-diff-format.sh |  16 +--
 t/t7064-wtstatus-pv2.sh                      |  52 ++++++++++
 t/t7506-status-submodule.sh                  | 102 ++++++++++++++++---
 9 files changed, 179 insertions(+), 33 deletions(-)
diff.c +3 -0
index 2bb2f8f57e..5a80695da8 100644
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	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 = "";
diff.h +1 -0
index 11de52e9e9..1e18e6b1c3 100644
@@ -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;
submodule.c +4 -1
index b3bb59f066..30c42cbffe 100644
@@ -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;
@@ -1677,7 +1678,9 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 
 	strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
 	if (ignore_untracked)
-		strvec_push(&cp.args, "-uno");
+		strvec_push (&cp.args, "-uno");
+	else
+		strvec_push (&cp.args, "--ignore-submodules=none");
 
 	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
t/t3701-add-interactive.sh +1 -1
index ca04fac417..98e46ad1ae 100755
@@ -761,7 +761,7 @@ test_expect_success 'setup different kinds of dirty submodules' '
 		echo dirty >>initial &&
 		: >untracked
 	) &&
-	git -C for-submodules diff-files --name-only >actual &&
+	git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
 	cat >expected <<-\EOF &&
 	dirty-both-ways
 	dirty-head
t/t4027-diff-submodule.sh +12 -3
index d7145ccca4..6432b4331f 100755
@@ -93,10 +93,19 @@ 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-dirty &&
+	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)' '
+	git 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 &&
+	git config --unset diff.ignoreSubmodules
+'
+
 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
 	git commit -m "x" sub &&
 	echo >>sub/world &&
@@ -168,13 +177,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
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..bb368b685d 100755
@@ -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 --submodule=log HEAD --ignore-submodules=none >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 --submodule=log HEAD --ignore-submodules=none >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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
t/t7064-wtstatus-pv2.sh +52 -0

64 lines not on this page · raw message

t/t7506-status-submodule.sh +90 -12

202 lines not on this page · raw message

Signature · 1 line
2.21.1 (Apple Git-122.3)
#20 lore raw

t/t4027-diff-submodule.sh test_expect_success 'git diff HEAD with dirty submodule (untracked)' ' · line 107

Quoted 10 lines · Sangeeta Jain
t/t4027-diff-submodule.sh +8 -0
...
+test_expect_success 'git diff HEAD with dirty submodule (untracked) (none ignored)' '
+	git 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 &&
+	git config --unset diff.ignoreSubmodules
+'

If any step concatenated by && in the above sequence fails, the test repository will have diff.ignoreSubmodules set to none (without getting it reset, since &&-chain prevents the last "config --unset" step from running). Unless the test is run under the --immediate option, that would affect the environment in which subsequent tests are run.

Instead, our test usually do this:

	test_expect_success 'test title' '
                test_config diff.ignoresubmodules none &&
                git diff HEAD >actual &&
                ...
                test_cmp expect.body actual.body
	'

"test_config" sets up a trigger, which will _always_ fire, whether the test fails at any intermediate steps or runs to the end and succeeds, to remove the configuration it just added. It is a short-hand for writing

	test_when_finished test_unconfig diff.ignoresubmodules &&
	git config diff.ignoresubmodules none

i.e. to use test_when_finished to set up the trigger.

t/t4027-diff-submodule.sh test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' · line 186

Quoted 9 lines
t/t4027-diff-submodule.sh +2 -2
-	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 &&

This line can be left as-is, no?

Quoted 14 lines
t/t4041-diff-submodule-option.sh +1 -1
index f852136585..bb368b685d 100755
@@ -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 --submodule=log HEAD --ignore-submodules=none >actual &&
 	cat >expected <<-EOF &&
 	Submodule sm1 contains untracked content
 	EOF

t/t4041-diff-submodule-option.sh test_expect_success 'submodule contains untracked content' ' · line 273

Quoted 5 lines
t/t4041-diff-submodule-option.sh +1 -1
@@ -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 &&

Likewise.

#21 lore raw
Quoted 35 lines · Junio C Hamano

t/t4027-diff-submodule.sh test_expect_success 'git diff HEAD with dirty submodule (untracked)' ' · line 107

Quoted 10 lines · Sangeeta Jain
t/t4027-diff-submodule.sh +8 -0
...
+test_expect_success 'git diff HEAD with dirty submodule (untracked) (none ignored)' '
+     git 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 &&
+     git config --unset diff.ignoreSubmodules
+'

If any step concatenated by && in the above sequence fails, the test repository will have diff.ignoreSubmodules set to none (without getting it reset, since &&-chain prevents the last "config --unset" step from running). Unless the test is run under the --immediate option, that would affect the environment in which subsequent tests are run.

Instead, our test usually do this:

        test_expect_success 'test title' '
                test_config diff.ignoresubmodules none &&
                git diff HEAD >actual &&
                ...
                test_cmp expect.body actual.body
        '

"test_config" sets up a trigger, which will _always_ fire, whether the test fails at any intermediate steps or runs to the end and succeeds, to remove the configuration it just added. It is a short-hand for writing

Quoted 5 lines

test_when_finished test_unconfig diff.ignoresubmodules && git config diff.ignoresubmodules none

i.e. to use test_when_finished to set up the trigger.

Oh, okay! I would make these changes. Thanks for the explanation. There are also other places where git config is used in test scripts. Should I change that too? Or maybe as they are not relevant to this patch, we can create an issue or even a microproject for other first-timer contributors?

Quoted 11 lines

t/t4027-diff-submodule.sh test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' · line 186

Quoted 9 lines
t/t4027-diff-submodule.sh +2 -2
-     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 &&

This line can be left as-is, no?

Ya, they can be left as it is but I removed the --ignore-submodules=untracked because we also have to check the default git behavior and adding that doesn't change anything in the code so I removed that.
In general, in all the tests I followed this practice:
1. I added --ignore-submodules=none where there were no options specified(as this was the earlier default)
2. I removed --ignore-submodules=untracked(as this should even work if no options are specified)

I would put that back if you still want it?

Thanks and Regards,

#22 lore raw
Quoted 22 lines · Sangeeta NB
Quoted 11 lines

t/t4027-diff-submodule.sh test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' · line 186

Quoted 9 lines
t/t4027-diff-submodule.sh +2 -2
-     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 &&

This line can be left as-is, no?

Ya, they can be left as it is but I removed the --ignore-submodules=untracked because we also have to check the default git behavior and adding that doesn't change anything in the code so I removed that.
In general, in all the tests I followed this practice:
1. I added --ignore-submodules=none where there were no options specified(as this was the earlier default)
2. I removed --ignore-submodules=untracked(as this should even work if no options are specified)

Quoted 1 line

I would put that back if you still want it?

OK, I re-read the changes to the tests in v5 (an excerpt at the end of this message), and I think this one makes sort-of sense.

We want to see that a plain-vanilla invocation of "git diff" without custom "--ignore-submodules" option would stop saying -dirty when untracked cruft is in the submodule's working tree, and this test, as it says in its title, is exactly testing that case (i.e. "how is a submodule without change relative to the gitlink in the superproject shown when there is untracked cruft there?"). It is a perfect opportunity to give the answer to the question and how that answer will be different from the current system if we took this patch. We used to expect to see that submodule has changed from the commit subprev to the same commit subprev with dirty indicator. What should we expect under the new world order? We should stop claiming that submodule has any change.

So I would have expected that would be shown by the first step in first "what happens without custom --ignore-submodules invocation?" test by changing the expect_from_to that corresponds to it, and then a *new* test added to show that with "--ignore-submodules=none" it is still possible to get "changed from the same commit to the same commit with the -dirty indicator" as a second test.

As long as all cases (i.e. all possible values to --ignore-submodules=<what>, plus the case where --ignore-submodules=<what> is not given at all) are covered, it is OK, but I think it is the best to show the case without an option, especially when the original does so.

Thanks.

@@ -168,13 +177,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

#23 lore raw

PATCH v5 1/1 diff: do not show submodule with untracked files as "-dirty"

In reply to Sangeeta via GitGitGadget

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.

---
 diff.c                                       |   3 +
 diff.h                                       |   1 +
 submodule.c                                  |   3 +
 t/t3701-add-interactive.sh                   |   5 +
 t/t4027-diff-submodule.sh                    |  15 ++-
 t/t4041-diff-submodule-option.sh             |  16 +--
 t/t4060-diff-submodule-option-diff-format.sh |  16 +--
 t/t7064-wtstatus-pv2.sh                      |  52 ++++++++++
 t/t7506-status-submodule.sh                  | 102 ++++++++++++++++---
 9 files changed, 182 insertions(+), 31 deletions(-)
diff.c +3 -0
index 2bb2f8f57e..5d69c2bb1c 100644
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	options->orderfile = diff_order_file_cfg;
+	
+	if (!options->flags.ignore_submodule_set)
+		handle_ignore_submodules_arg(options, "untracked");
 
 	if (diff_no_prefix) {
 		options->a_prefix = options->b_prefix = "";
diff.h +1 -0
index 11de52e9e9..1e18e6b1c3 100644
@@ -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;
submodule.c +3 -0
index b3bb59f066..afeb754079 100644
@@ -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;
@@ -1678,6 +1679,8 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 	strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
 	if (ignore_untracked)
 		strvec_push(&cp.args, "-uno");
+	else
+		strvec_push(&cp.args, "--ignore-submodules=none");
 
 	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
t/t3701-add-interactive.sh +5 -0
index ca04fac417..9104d1946d 100755
@@ -765,6 +765,11 @@ test_expect_success 'setup different kinds of dirty submodules' '
 	cat >expected <<-\EOF &&
 	dirty-both-ways
 	dirty-head
+	EOF
+	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 &&
t/t4027-diff-submodule.sh +12 -3
index d7145ccca4..6432b4331f 100755
@@ -93,10 +93,19 @@ 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-dirty &&
+	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)' '
+	git 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 &&
+	git config --unset diff.ignoreSubmodules
+'
+
 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
 	git commit -m "x" sub &&
 	echo >>sub/world &&
@@ -168,13 +177,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
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..bb368b685d 100755
@@ -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 --submodule=log HEAD --ignore-submodules=none >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 --submodule=log HEAD --ignore-submodules=none >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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
t/t7064-wtstatus-pv2.sh +52 -0

64 lines not on this page · raw message

t/t7506-status-submodule.sh +90 -12

202 lines not on this page · raw message

Signature · 1 line
2.21.1 (Apple Git-122.3)
#24 lore raw

PATCH v6 1/1 diff: do not show submodule with untracked files as "-dirty"

In reply to Sangeeta via GitGitGadget

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.

---
 diff.c                                       |   3 +
 diff.h                                       |   1 +
 submodule.c                                  |   3 +
 t/t3701-add-interactive.sh                   |   5 +
 t/t4027-diff-submodule.sh                    |  12 ++-
 t/t4041-diff-submodule-option.sh             |  16 +--
 t/t4060-diff-submodule-option-diff-format.sh |  16 +--
 t/t7064-wtstatus-pv2.sh                      |  52 ++++++++++
 t/t7506-status-submodule.sh                  | 102 ++++++++++++++++---
 9 files changed, 180 insertions(+), 30 deletions(-)
diff.c +3 -0
index 2bb2f8f57e..5d69c2bb1c 100644
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	options->orderfile = diff_order_file_cfg;
+	
+	if (!options->flags.ignore_submodule_set)
+		handle_ignore_submodules_arg(options, "untracked");
 
 	if (diff_no_prefix) {
 		options->a_prefix = options->b_prefix = "";
diff.h +1 -0
index 11de52e9e9..1e18e6b1c3 100644
@@ -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;
submodule.c +3 -0
index b3bb59f066..afeb754079 100644
@@ -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;
@@ -1678,6 +1679,8 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 	strvec_pushl(&cp.args, "status", "--porcelain=2", NULL);
 	if (ignore_untracked)
 		strvec_push(&cp.args, "-uno");
+	else
+		strvec_push(&cp.args, "--ignore-submodules=none");
 
 	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
t/t3701-add-interactive.sh +5 -0
index ca04fac417..9104d1946d 100755
@@ -765,6 +765,11 @@ test_expect_success 'setup different kinds of dirty submodules' '
 	cat >expected <<-\EOF &&
 	dirty-both-ways
 	dirty-head
+	EOF
+	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 &&
t/t4027-diff-submodule.sh +10 -2
index d7145ccca4..894a11b224 100755
@@ -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
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..bb368b685d 100755
@@ -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 --submodule=log HEAD --ignore-submodules=none >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 --submodule=log HEAD --ignore-submodules=none >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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
t/t7064-wtstatus-pv2.sh +52 -0

64 lines not on this page · raw message

t/t7506-status-submodule.sh +90 -12

202 lines not on this page · raw message

Signature · 1 line
2.21.1 (Apple Git-122.3)
#25 lore raw

Hey Johannes and Junio,

In continuation of the discussion from here[1]

[1] https://lore.kernel.org/git/[email protected]/

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

* sj/untracked-files-in-submodule-directory-is-not-dirty (2020-10-26) 1 commit
- diff: do not show submodule with untracked files as "-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.

Needs doc update.

Do I need to add the doc update in the same patch?

Quoted 6 lines
Quoted 3 lines

I *think* the original rationale for marking submodules with untracked (_un-ignored_) files was to avoid deleting a submodule that has uncommitted (because untracked) files.

I agree with you that that the motivation was exactly that, but I have a suspicion that its execution was misguided.

I am really very sorry if I ended up adding some unwanted code.

Quoted 26 lines

When one has a subdirectory D where one might or might not have an untracked new file that one does not want to lose, but one otherwise would want to clean up (perhaps an errant process created tons of garbage files in the directory), one would not

git diff D

to see if there are important changes in that directory before doing

        rm -rf D && git checkout D

to bring it back to pristine state, exactly because one would not want to lose newly-created but not added files. One would instead use

git status D

for checking. Why would a user change the habit when D happens to be a submodule?

So I would say that "git status [D]", if it does not let the user notice that there is untracked contents in the submodule working tree, would be a bad idea. "git diff" that ignores untracked paths in the submodule working tree, on the other hand, is a good thing.

Quoted 8 lines

Now, the patch as-is may change the behaviour of "git status D" in this case, and the internal invocation of diff-files made somewhere in wt-status.c may have to be adjusted to keep such a submodule with forgotten newly created files shown as modified.

Further discussion on this should be done on the original review thread for continuity, not here, in any case.

So we want that git status should behave in the same way as it was behaving before? Can we do this by passing --ignore-submodules=none as the default args for status? Another approach might be to figure out how the diff is being called(like is this being called from git status or git diff) and then add the --ignore-submodules=untracked behavior to it accordingly. Though I have no idea how to do that now.

Please correct me if I am completely going in the wrong direction. As it is my first time contributing to git, so any help would be greatly beneficial for me.

Thanks and regards,
Sangeeta

#26 lore raw
Quoted 15 lines · Sangeeta

Hey Johannes and Junio,

In continuation of the discussion from here[1]

[1] https://lore.kernel.org/git/[email protected]/

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

* sj/untracked-files-in-submodule-directory-is-not-dirty (2020-10-26) 1 commit
- diff: do not show submodule with untracked files as "-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.

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Needs doc update.

Do I need to add the doc update in the same patch?

It is ideal if code change, tests and documentation are done atomically. For a large series the story may be different, but I thought a single commit would be sufficient for this topic?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I *think* the original rationale for marking submodules with untracked (_un-ignored_) files was to avoid deleting a submodule that has uncommitted (because untracked) files.

I agree with you that that the motivation was exactly that, but I have a suspicion that its execution was misguided.

I am really very sorry if I ended up adding some unwanted code.

But you did not. The "motivation" and "execution" are both from long time ago, back when submodule support was invented and "git diff" in the superproject was taught to pay attention to submodules.

Dscho suspects that "git diff" were taught to add "-dirty" to submodules with untracked files in their working tree in order to protect them from those who are about to delete them as a way to check if it is safe. I agreed that the motivation may have been so, i.e. they wanted to protect users from losing untracked files that they forgot to add and commit in the submodule, but the execution was wrong, i.e. "git diff" is not the right tool to achieve that protection.

See that you didn't add any unwanted code---it all happened long time ago ;-)

Quoted 3 lines

So we want that git status should behave in the same way as it was behaving before? Can we do this by passing --ignore-submodules=none as the default args for status?

Yes, I do not recall offhand where in wt-status.c "git status" does so, but there should be an internal invocation of diff-files somewhere, and I suspect it is not passing any --ignore-submodules bit. Just like wt_status_collect_changes_index() calls handle_ignore_submodules_arg() with hardcoded "dirty", we may have to unignore untracked files in submodule working trees when checking the working tree changes.

Quoted 4 lines

Another approach might be to figure out
how the diff is being called(like is this being called from git status or git diff) and then add the --ignore-submodules=untracked behavior to it accordingly. Though I have no idea how to do that now.

No, callee shouldn't have knowledge of its caller to perform a special case action. The caller should say how it wants its callees to behave.

Thanks.

#27 lore raw

Hey,

I worked on passing --ignore-submodules=none as the default behavior of git status so that the user doesn't end up deleting a submodule that has uncommitted (untracked) files.

The following changes make git status pass the ignoreSubmodules none argument as default.

@@ -4587,7 +4587,7 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)

        options->orderfile = diff_order_file_cfg;

        if (!options->flags.ignore_submodule_set)

- handle_ignore_submodules_arg(options, "untracked");
+ options->flags.ignore_untracked_in_submodules = 1;

        if (diff_no_prefix) {
                options->a_prefix = options->b_prefix = "";

@@ -607,6 +607,9 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)

                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){
+ handle_ignore_submodules_arg(&rev.diffopt, "none");
+ }

I have had to set the flag manually in diff.c because when we call handle_ignore_submodules_arg() with "untracked" arg, options->flags.ignore_submodule_set is set to 1 and therefore when we check for it in wt-status.c it appears that user has already set some config and therefore we shouldn't add "none" as ignoreSubmodules arg.

Another way to do that is to have one more flag in diff_options that can let us know whether options->flags.ignore_submodule_set was set by the user or by diff passing untracked as the default argument.

Can someone please help me with what might be the right way to proceed?

Thanks!

#28 lore raw
Quoted 37 lines · Sangeeta

Hey,

I worked on passing --ignore-submodules=none as the default behavior of git status so that the user doesn't end up deleting a submodule that has uncommitted (untracked) files.

The following changes make git status pass the ignoreSubmodules none argument as default.

(quoted diff) +1 -1
@@ -4587,7 +4587,7 @@ void repo_diff_setup(struct repository *r,
 struct diff_options *options)
        options->orderfile = diff_order_file_cfg;
 
        if (!options->flags.ignore_submodule_set)
-               handle_ignore_submodules_arg(options, "untracked");
+               options->flags.ignore_untracked_in_submodules = 1;
 
        if (diff_no_prefix) {
                options->a_prefix = options->b_prefix = "";
(quoted diff) +3 -0
@@ -607,6 +607,9 @@ static void
 wt_status_collect_changes_worktree(struct wt_status *s)
                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){
+               handle_ignore_submodules_arg(&rev.diffopt, "none");
+       }
 

I have had to set the flag manually in diff.c because when we call handle_ignore_submodules_arg() with "untracked" arg, options->flags.ignore_submodule_set is set to 1 and therefore when we check for it in wt-status.c it appears that user has already set some config and therefore we shouldn't add "none" as ignoreSubmodules arg.

Quoted 5 lines

Another way to do that is to have one more flag in diff_options that can let us know whether options->flags.ignore_submodule_set was set by the user or by diff passing untracked as the default argument.

Can someone please help me with what might be the right way to proceed?

Hmph, neither sounds "right"---having to circumvent the assignment to _set flag made in the handle_ helper by either manually setting the underlying flag, or by introducing another flag that stops from the _set flag getting updated, sounds like working around a flaw of the approach to use _set flag and set it in the handle_ helper in the first place...

#29 lore raw
In reply to Sangeeta Jain

Hi Sangeeta,

t/t3701-add-interactive.sh test_expect_success 'setup different kinds of dirty submodules' ' · line 772

Quoted 13 lines · Sangeeta Jain
t/t3701-add-interactive.sh +5 -0
index ca04fac417..9104d1946d 100755
@@ -765,6 +765,11 @@ test_expect_success 'setup different kinds of dirty submodules' '
 	cat >expected <<-\EOF &&
 	dirty-both-ways
 	dirty-head
+	EOF
+	git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
+	cat >expected <<-\EOF &&
+	dirty-both-ways
+	dirty-head

This will throw-away above change to "expected", I think this is not what you expected to write!

Quoted 43 lines
t/t3701-add-interactive.sh +0 -0
 	dirty-otherwise
 	EOF
 	test_cmp expected actual &&
t/t4027-diff-submodule.sh +10 -2
index d7145ccca4..894a11b224 100755
@@ -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
t/t4041-diff-submodule-option.sh +0 -0
index f852136585..bb368b685d 100755

t/t4041-diff-submodule-option.sh test_expect_success 'submodule is up to date' ' · line 265

Quoted 5 lines
t/t4041-diff-submodule-option.sh +1 -1
@@ -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 --submodule=log HEAD --ignore-submodules=none >actual &&

Nit:

I suspect that we're in favour of writing all optional argument before all committish here.

IOW, I think we're better move HEAD after --ignore-submodules=none

Quoted 151 lines
t/t4041-diff-submodule-option.sh +7 -7
 	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 --submodule=log HEAD --ignore-submodules=none >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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
t/t7064-wtstatus-pv2.sh +1 -0
index 537787e598..78cd86be3a 100755
@@ -503,6 +503,31 @@ test_expect_success 'untracked changes in added submodule (AM S..U)' '
 		1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1
 		EOF
 
+		git status --porcelain=v2 --branch --untracked-files=all --ignore-submodules=none >actual &&

t/t7064-wtstatus-pv2.sh test_expect_success 'untracked changes in added submodule (AM S..U)' ' · line 516

Quoted 10 lines
t/t7064-wtstatus-pv2.sh +10 -0
+		test_cmp expect actual
+	)
+'
+
+test_expect_success 'untracked changes in added submodule (A. S...) (untracked ignored)' '
+	(	cd super_repo &&
+		## create untracked file in the submodule.
+		(	cd sub1 &&
+			echo "xxxx" >file_in_sub
+		) &&

Another nit: I think we can avoid subshell by:

echo "xxxx" >sub1/file_in_sub

In general, I think other usages of subshell in this patch could be replaced by above syntax for echo and "git -C subdir" for git.

Quoted 270 lines
t/t7064-wtstatus-pv2.sh +41 -0
+
+		HMOD=$(git hash-object -t blob -- .gitmodules) &&
+		HSUP=$(git rev-parse HEAD) &&
+		HSUB=$HSUP &&
+
+		cat >expect <<-EOF &&
+		# branch.oid $HSUP
+		# branch.head master
+		# branch.upstream origin/master
+		# branch.ab +0 -0
+		1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
+		1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1
+		EOF
+
 		git status --porcelain=v2 --branch --untracked-files=all >actual &&
 		test_cmp expect actual
 	)
@@ -582,6 +607,33 @@ test_expect_success 'staged and untracked changes in added submodule (AM S.MU)'
 		1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1
 		EOF
 
+		git status --porcelain=v2 --branch --untracked-files=all --ignore-submodules=none >actual &&
+		test_cmp expect actual
+	)
+'
+
+test_expect_success 'staged and untracked changes in added submodule (AM S.M.) (untracked ignored)' '
+	(	cd super_repo &&
+		(	cd sub1 &&
+			## stage new changes in tracked file.
+			git add file_in_sub &&
+			## create new untracked file.
+			echo "yyyy" >>another_file_in_sub
+		) &&
+
+		HMOD=$(git hash-object -t blob -- .gitmodules) &&
+		HSUP=$(git rev-parse HEAD) &&
+		HSUB=$HSUP &&
+
+		cat >expect <<-EOF &&
+		# branch.oid $HSUP
+		# branch.head master
+		# branch.upstream origin/master
+		# branch.ab +0 -0
+		1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
+		1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
+		EOF
+
 		git status --porcelain=v2 --branch --untracked-files=all >actual &&
 		test_cmp expect actual
 	)
t/t7506-status-submodule.sh +90 -12
index 3fcb44767f..72da00a962 100755
@@ -94,36 +94,60 @@ test_expect_success 'status with added file in submodule (short)' '
 test_expect_success 'status with untracked file in submodule' '
 	(cd sub && git reset --hard) &&
 	echo "content" >sub/new-file &&
-	git status >output &&
+	git status --ignore-submodules=none >output &&
 	test_i18ngrep "modified:   sub (untracked content)" output
 '
 
+test_expect_success 'status with untracked file in submodule (untracked ignored)' '
+	(cd sub && git reset --hard) &&
+	echo "content" >sub/new-file &&
+	git status >output &&
+	test_i18ngrep "^nothing to commit" output
+'
+
 test_expect_success 'status -uno with untracked file in submodule' '
 	git status -uno >output &&
 	test_i18ngrep "^nothing to commit" output
 '
 
 test_expect_success 'status with untracked file in submodule (porcelain)' '
-	git status --porcelain >output &&
+	git status --porcelain --ignore-submodules=none >output &&
 	diff output - <<-\EOF
 	 M sub
 	EOF
 '
 
+test_expect_success 'status with untracked file in submodule (porcelain) (untracked ignored)' '
+	git status --porcelain >output &&
+	test_must_be_empty output
+'
+
 test_expect_success 'status with untracked file in submodule (short)' '
-	git status --short >output &&
+	git status --short --ignore-submodules=none >output &&
 	diff output - <<-\EOF
 	 ? sub
 	EOF
 '
 
+test_expect_success 'status with untracked file in submodule (short) (untracked ignored)' '
+	git status --short >output &&
+	test_must_be_empty output
+'
+
 test_expect_success 'status with added and untracked file in submodule' '
 	(cd sub && git reset --hard && echo >foo && git add foo) &&
 	echo "content" >sub/new-file &&
-	git status >output &&
+	git status --ignore-submodules=none >output &&
 	test_i18ngrep "modified:   sub (modified content, untracked content)" output
 '
 
+test_expect_success 'status with added and untracked file in submodule (untracked ignored)' '
+	(cd sub && git reset --hard && echo >foo && git add foo) &&
+	echo "content" >sub/new-file &&
+	git status >output &&
+	test_i18ngrep "modified:   sub (modified content)" output
+'
+
 test_expect_success 'status with added and untracked file in submodule (porcelain)' '
 	(cd sub && git reset --hard && echo >foo && git add foo) &&
 	echo "content" >sub/new-file &&
@@ -168,10 +192,17 @@ test_expect_success 'status with added file in modified submodule (porcelain)' '
 test_expect_success 'status with untracked file in modified submodule' '
 	(cd sub && git reset --hard) &&
 	echo "content" >sub/new-file &&
-	git status >output &&
+	git status --ignore-submodules=none >output &&
 	test_i18ngrep "modified:   sub (new commits, untracked content)" output
 '
 
+test_expect_success 'status with untracked file in modified submodule (untracked ignored)' '
+	(cd sub && git reset --hard) &&
+	echo "content" >sub/new-file &&
+	git status >output &&
+	test_i18ngrep "modified:   sub (new commits)" output
+'
+
 test_expect_success 'status with untracked file in modified submodule (porcelain)' '
 	git status --porcelain >output &&
 	diff output - <<-\EOF
@@ -182,10 +213,17 @@ test_expect_success 'status with untracked file in modified submodule (porcelain
 test_expect_success 'status with added and untracked file in modified submodule' '
 	(cd sub && git reset --hard && echo >foo && git add foo) &&
 	echo "content" >sub/new-file &&
-	git status >output &&
+	git status --ignore-submodules=none >output &&
 	test_i18ngrep "modified:   sub (new commits, modified content, untracked content)" output
 '
 
+test_expect_success 'status with added and untracked file in modified submodule (untracked ignored)' '
+	(cd sub && git reset --hard && echo >foo && git add foo) &&
+	echo "content" >sub/new-file &&
+	git status >output &&
+	test_i18ngrep "modified:   sub (new commits, modified content)" output
+'
+
 test_expect_success 'status with added and untracked file in modified submodule (porcelain)' '
 	(cd sub && git reset --hard && echo >foo && git add foo) &&
 	echo "content" >sub/new-file &&
@@ -349,7 +387,7 @@ test_expect_success 'setup superproject with untracked file in nested submodule'
 '
 
 test_expect_success 'status with untracked file in nested submodule (porcelain)' '
-	git -C super status --porcelain >output &&
+	git -C super status --porcelain --ignore-submodules=none >output &&
 	diff output - <<-\EOF
 	 M sub1
 	 M sub2
@@ -357,8 +395,13 @@ test_expect_success 'status with untracked file in nested submodule (porcelain)'
 	EOF
 '
 
+test_expect_success 'status with untracked file in nested submodule (porcelain) (untracked ignored)' '
+	git -C super status --porcelain >output &&
+	test_must_be_empty output
+'
+
 test_expect_success 'status with untracked file in nested submodule (porcelain=2)' '
-	git -C super status --porcelain=2 >output &&
+	git -C super status --porcelain=2 --ignore-submodules=none >output &&
 	sanitize_output output &&
 	diff output - <<-\EOF
 	1 .M S..U 160000 160000 160000 HASH HASH sub1
@@ -367,8 +410,13 @@ test_expect_success 'status with untracked file in nested submodule (porcelain=2
 	EOF
 '
 
+test_expect_success 'status with untracked file in nested submodule (porcelain=2) (untracked ignored)' '
+	git -C super status --porcelain=2 >output &&
+	test_must_be_empty output
+'
+
 test_expect_success 'status with untracked file in nested submodule (short)' '
-	git -C super status --short >output &&
+	git -C super status --short --ignore-submodules=none >output &&
 	diff output - <<-\EOF
 	 ? sub1
 	 ? sub2
@@ -376,13 +424,18 @@ test_expect_success 'status with untracked file in nested submodule (short)' '
 	EOF
 '
 
+test_expect_success 'status with untracked file in nested submodule (short) (untracked ignored)' '
+	git -C super status --short >output &&
+	test_must_be_empty output
+'
+
 test_expect_success 'setup superproject with modified file in nested submodule' '
 	git -C super/sub1/sub2 add file &&
 	git -C super/sub2 add file
 '
 
 test_expect_success 'status with added file in nested submodule (porcelain)' '
-	git -C super status --porcelain >output &&
+	git -C super status --porcelain --ignore-submodules=none >output &&
 	diff output - <<-\EOF
 	 M sub1
 	 M sub2
@@ -390,8 +443,16 @@ test_expect_success 'status with added file in nested submodule (porcelain)' '
 	EOF
 '
 
+test_expect_success 'status with added file in nested submodule (porcelain) (untracked ignored)' '
+	git -C super status --porcelain >output &&
+	diff output - <<-\EOF
+	 M sub1
+	 M sub2
+	EOF
+'
+
 test_expect_success 'status with added file in nested submodule (porcelain=2)' '
-	git -C super status --porcelain=2 >output &&
+	git -C super status --porcelain=2 --ignore-submodules=none >output &&
 	sanitize_output output &&
 	diff output - <<-\EOF
 	1 .M S.M. 160000 160000 160000 HASH HASH sub1
@@ -400,8 +461,17 @@ test_expect_success 'status with added file in nested submodule (porcelain=2)' '
 	EOF
 '
 
+test_expect_success 'status with added file in nested submodule (porcelain=2) (untracked ignored)' '
+	git -C super status --porcelain=2 >output &&
+	sanitize_output output &&
+	diff output - <<-\EOF
+	1 .M S.M. 160000 160000 160000 HASH HASH sub1
+	1 .M S.M. 160000 160000 160000 HASH HASH sub2
+	EOF
+'
+
 test_expect_success 'status with added file in nested submodule (short)' '
-	git -C super status --short >output &&
+	git -C super status --short --ignore-submodules=none >output &&
 	diff output - <<-\EOF
 	 m sub1
 	 m sub2
@@ -409,4 +479,12 @@ test_expect_success 'status with added file in nested submodule (short)' '
 	EOF
 '
 
+test_expect_success 'status with added file in nested submodule (short) (untracked ignored)' '
+	git -C super status --short >output &&
+	diff output - <<-\EOF
+	 m sub1
+	 m sub2
+	EOF
+'
+
 test_done
Signature · 1 line
2.21.1 (Apple Git-122.3)
Signature · 1 line
Danh
#30 lore raw

Hey Danh,

Quoted 8 lines
Quoted 8 lines
t/t3701-add-interactive.sh +0 -0
index ca04fac417..9104d1946d 100755
@@ -765,6 +765,11 @@ test_expect_success 'setup different kinds of dirty submodules' '
      cat >expected <<-\EOF &&
      dirty-both-ways
      dirty-head
Quoted 8 lines

t/t3701-add-interactive.sh test_expect_success 'setup different kinds of dirty submodules' ' · line 772

Quoted 5 lines
t/t3701-add-interactive.sh +5 -0
+     EOF
+     git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
+     cat >expected <<-\EOF &&
+     dirty-both-ways
+     dirty-head

This will throw-away above change to "expected", I think this is not what you expected to write!

I am sorry I couldn't understand what you mean by that. I think that is what I expected to write. I want those changes to be in "expected".

Thanks,
Sangeeta

#31 lore raw
Quoted 17 lines · Sangeeta
Quoted 8 lines
Quoted 8 lines
t/t3701-add-interactive.sh +0 -0
index ca04fac417..9104d1946d 100755
@@ -765,6 +765,11 @@ test_expect_success 'setup different kinds of dirty submodules' '
      cat >expected <<-\EOF &&
      dirty-both-ways
      dirty-head
Quoted 8 lines

t/t3701-add-interactive.sh test_expect_success 'setup different kinds of dirty submodules' ' · line 772

Quoted 5 lines
t/t3701-add-interactive.sh +5 -0
+     EOF
+     git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
+     cat >expected <<-\EOF &&
+     dirty-both-ways
+     dirty-head

This will throw-away above change to "expected", I think this is not what you expected to write!

Quoted 2 lines

I am sorry I couldn't understand what you mean by that. I think that is what I expected to write. I want those changes to be in "expected".

Looking at the above quoted part again...

	cat >expected <<-\EOF &&
		... content 1 ...
	EOF
        git ... >actual &&
	cat >expected <<-\EOF &&
		... content 2 ...
	EOF

I think Đoàn Trần Công Danh wants to say is that expected originally has content 1, and that is discarded because you overwrite the same file with content 2. So either

- if content1 and content2 are identical, perhaps you do not have to write content2 into expected at all, or

- if content1 and content2 are different, perhaps you forgot to consume content1 before overwriting it.

THe latter is quite plausible, as the original test without your addition must be consuming content1 after the part you added.

#32 lore raw

PATCH v7 1/1 diff: do not show submodule with untracked files as "-dirty"

In reply to Sangeeta via GitGitGadget

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.

---
 Documentation/config/diff.txt                |  2 ++
 diff.c                                       |  3 +++
 diff.h                                       |  1 +
 submodule.c                                  |  1 +
 t/t3701-add-interactive.sh                   |  6 ++++++
 t/t4027-diff-submodule.sh                    | 12 ++++++++++--
 t/t4041-diff-submodule-option.sh             | 16 ++++++++--------
 t/t4060-diff-submodule-option-diff-format.sh | 16 ++++++++--------
 wt-status.c                                  |  4 +++-
 9 files changed, 42 insertions(+), 19 deletions(-)
Documentation/config/diff.txt +2 -0
index c3ae136eba..2d3331f55c 100644
@@ -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
diff.c +3 -0
index 2bb2f8f57e..5a80695da8 100644
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	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 = "";
diff.h +1 -0
index 11de52e9e9..1e18e6b1c3 100644
@@ -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;
submodule.c +1 -0
index b3bb59f066..8f6227c993 100644
@@ -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;
t/t3701-add-interactive.sh +6 -0
index ca04fac417..9a2489cde0 100755
@@ -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 &&
t/t4027-diff-submodule.sh +10 -2
index d7145ccca4..894a11b224 100755
@@ -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
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..b3a7b7acaa 100755
@@ -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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
wt-status.c +3 -1
index 7074bbdd53..83d418647d 100644
@@ -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;
Signature · 1 line
2.21.1 (Apple Git-122.3)
#33 lore raw

Hi Sangeeta,

First, thanks for correcting the test code that I've noticed in the previous mail (and thanks to Junio, who explained my words in better terms).

Documentation/config/diff.txt diff.ignoreSubmodules:: · line 89

Quoted 10 lines · Sangeeta Jain
Documentation/config/diff.txt +2 -0
index c3ae136eba..2d3331f55c 100644
@@ -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.

This rounds looks better to me.
My only question now is: Should this change applicable to diff-index, diff-files and other plumbing commands?

As of it's now, we treat the absent of diff.ignoreSubmodules as "none" but we're changing to "untracked" with this change.

Will someone's scripts break by this change?
I think it's unlikely, but who knows?

To contribute to the chaos, --ignore-submodules implies --ignore-submodules=all My first-quick-and-INCORRECT scan to the diff-options, I was puzzled by its default, and I thought (incorrectly, for a second) the absent of --ignore-submodules mean --ignore-submodules=all.

-- Danh

Quoted 263 lines
Documentation/config/diff.txt +0 -0
 diff.mnemonicPrefix::
 	If set, 'git diff' uses a prefix pair that is different from the
diff.c +3 -0
index 2bb2f8f57e..5a80695da8 100644
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
 	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 = "";
diff.h +1 -0
index 11de52e9e9..1e18e6b1c3 100644
@@ -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;
submodule.c +1 -0
index b3bb59f066..8f6227c993 100644
@@ -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;
t/t3701-add-interactive.sh +6 -0
index ca04fac417..9a2489cde0 100755
@@ -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 &&
t/t4027-diff-submodule.sh +10 -2
index d7145ccca4..894a11b224 100755
@@ -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
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..b3a7b7acaa 100755
@@ -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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
wt-status.c +3 -1
index 7074bbdd53..83d418647d 100644
@@ -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;
Signature · 1 line
2.21.1 (Apple Git-122.3)
Signature · 1 line
Danh
#34 lore raw
In reply to Sangeeta Jain

Hey Junio,

In the "What's cooking in git.git" you mentioned that this patch is left on doc update and some adjustments in "git status".

The above patch does adds the ignore-submodule=none as the default behavior for git status and also adds documentation too. Am I missing something?

Thanks and regards,
Sangeeta

Sangeeta

Quoted 302 lines · Sangeeta Jain

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.

---
 Documentation/config/diff.txt                |  2 ++
 diff.c                                       |  3 +++
 diff.h                                       |  1 +
 submodule.c                                  |  1 +
 t/t3701-add-interactive.sh                   |  6 ++++++
 t/t4027-diff-submodule.sh                    | 12 ++++++++++--
 t/t4041-diff-submodule-option.sh             | 16 ++++++++--------
 t/t4060-diff-submodule-option-diff-format.sh | 16 ++++++++--------
 wt-status.c                                  |  4 +++-
 9 files changed, 42 insertions(+), 19 deletions(-)
Documentation/config/diff.txt +2 -0
index c3ae136eba..2d3331f55c 100644
@@ -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
diff.c +3 -0
index 2bb2f8f57e..5a80695da8 100644
@@ -4585,6 +4585,9 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
                DIFF_XDL_SET(options, INDENT_HEURISTIC);
 
        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 = "";
diff.h +1 -0
index 11de52e9e9..1e18e6b1c3 100644
@@ -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;
submodule.c +1 -0
index b3bb59f066..8f6227c993 100644
@@ -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;
t/t3701-add-interactive.sh +6 -0
index ca04fac417..9a2489cde0 100755
@@ -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 &&
t/t4027-diff-submodule.sh +10 -2
index d7145ccca4..894a11b224 100755
@@ -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
t/t4041-diff-submodule-option.sh +8 -8
index f852136585..b3a7b7acaa 100755
@@ -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:
t/t4060-diff-submodule-option-diff-format.sh +8 -8
index fc8229c726..dc7b242697 100755
@@ -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:
wt-status.c +3 -2
index 7074bbdd53..83d418647d 100644
@@ -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;
--

2.21.1 (Apple Git-122.3)

#35 lore raw
Quoted 4 lines · Sangeeta

Hey Junio,

In the "What's cooking in git.git" you mentioned that this patch is left on doc update and some adjustments in "git status".

Ah, thanks for reminding. I do not think I've picked the updated one up yet.

Will find time to take a look later.