git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH] diff: do not show submodule with untracked files as "-dirty"
@ 2020-10-15 17:08 Sangeeta via GitGitGadget
  2020-10-20 13:38 ` [OUTREACHY][PATCH] " Phillip Wood
                   ` (7 more replies)
  0 siblings, 8 replies; 36+ messages in thread
From: Sangeeta via GitGitGadget @ 2020-10-15 17:08 UTC (permalink / raw)
  To: git; +Cc: Sangeeta, sangu09

From: sangu09 <sangunb09@gmail.com>

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.

Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
---
    [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 --git a/diff.c b/diff.c
index 2bb2f8f57e..07d89e3e2b 100644
--- a/diff.c
+++ b/diff.c
@@ -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 = "";
diff --git a/submodule.c b/submodule.c
index b3bb59f066..762298c010 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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;
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index ca04fac417..98e46ad1ae 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -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
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index d7145ccca4..7bf2cb9c88 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -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
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index f852136585..bb368b685d 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -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:
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index fc8229c726..dc7b242697 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -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:
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
index 537787e598..200626251e 100755
--- a/t/t7064-wtstatus-pv2.sh
+++ b/t/t7064-wtstatus-pv2.sh
@@ -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 &&
diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
index 3fcb44767f..b7ff7928fb 100755
--- a/t/t7506-status-submodule.sh
+++ b/t/t7506-status-submodule.sh
@@ -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
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [OUTREACHY][PATCH] diff: do not show submodule with untracked files as "-dirty"
  2020-10-15 17:08 [PATCH] diff: do not show submodule with untracked files as "-dirty" Sangeeta via GitGitGadget
@ 2020-10-20 13:38 ` Phillip Wood
  2020-10-20 18:10   ` Sangeeta NB
  2020-10-21 13:10 ` [Outreachy] [PATCH v2] " Sangeeta Jain
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 36+ messages in thread
From: Phillip Wood @ 2020-10-20 13:38 UTC (permalink / raw)
  To: Sangeeta via GitGitGadget, git; +Cc: Sangeeta

Hi Sangeeta

On 15/10/2020 18:08, Sangeeta via GitGitGadget wrote:
> From: sangu09 <sangunb09@gmail.com>

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/xmqqpn5dd5dv.fsf@gitster.c.googlers.com)

> 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.

> 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.

> 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.

> 
> Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
> ---
>      [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 --git a/diff.c b/diff.c
> index 2bb2f8f57e..07d89e3e2b 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -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.

>   	if (diff_no_prefix) {
>   		options->a_prefix = options->b_prefix = "";
> diff --git a/submodule.c b/submodule.c
> index b3bb59f066..762298c010 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -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.

>   	prepare_submodule_repo_env(&cp.env_array);
>   	cp.git_cmd = 1;
> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index ca04fac417..98e46ad1ae 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -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
> diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
> index d7145ccca4..7bf2cb9c88 100755
> --- a/t/t4027-diff-submodule.sh
> +++ b/t/t4027-diff-submodule.sh
> @@ -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 &&

This checks the new default which is good

>   	test_must_be_empty actual3 &&
>   	git diff --ignore-submodules=dirty HEAD >actual4 &&
>   	test_must_be_empty actual4
> diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
> index f852136585..bb368b685d 100755
> --- a/t/t4041-diff-submodule-option.sh
> +++ b/t/t4041-diff-submodule-option.sh
> @@ -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:
> diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
> index fc8229c726..dc7b242697 100755
> --- a/t/t4060-diff-submodule-option-diff-format.sh
> +++ b/t/t4060-diff-submodule-option-diff-format.sh
> @@ -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:

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

> diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
> index 537787e598..200626251e 100755
> --- a/t/t7064-wtstatus-pv2.sh
> +++ b/t/t7064-wtstatus-pv2.sh
> @@ -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 ')'

>   	(	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
>

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

>   		git status --porcelain=v2 --branch --untracked-files=all >actual &&
> diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
> index 3fcb44767f..b7ff7928fb 100755
> --- a/t/t7506-status-submodule.sh
> +++ b/t/t7506-status-submodule.sh
> @@ -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
>   '

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


> base-commit: d98273ba77e1ab9ec755576bc86c716a97bf59d7
> 

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [OUTREACHY][PATCH] diff: do not show submodule with untracked files as "-dirty"
  2020-10-20 13:38 ` [OUTREACHY][PATCH] " Phillip Wood
@ 2020-10-20 18:10   ` Sangeeta NB
  2020-10-21 11:28     ` Phillip Wood
  0 siblings, 1 reply; 36+ messages in thread
From: Sangeeta NB @ 2020-10-20 18:10 UTC (permalink / raw)
  To: phillip.wood; +Cc: Sangeeta via GitGitGadget, git

Hey Phillip,

> 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/xmqqpn5dd5dv.fsf@gitster.c.googlers.com)

> 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?

> 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?


>       if (diff_no_prefix) {
>               options->a_prefix = options->b_prefix = "";
> diff --git a/submodule.c b/submodule.c
> index b3bb59f066..762298c010 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -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 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.

>
> 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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [OUTREACHY][PATCH] diff: do not show submodule with untracked files as "-dirty"
  2020-10-20 18:10   ` Sangeeta NB
@ 2020-10-21 11:28     ` Phillip Wood
  0 siblings, 0 replies; 36+ messages in thread
From: Phillip Wood @ 2020-10-21 11:28 UTC (permalink / raw)
  To: Sangeeta NB, phillip.wood; +Cc: Sangeeta via GitGitGadget, git

Hi Sangeeta

On 20/10/2020 19:10, Sangeeta NB wrote:
> Hey Phillip,
> 
>> 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/xmqqpn5dd5dv.fsf@gitster.c.googlers.com)
> 
>> 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)

>> 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

> 
>>        if (diff_no_prefix) {
>>                options->a_prefix = options->b_prefix = "";
>> diff --git a/submodule.c b/submodule.c
>> index b3bb59f066..762298c010 100644
>> --- a/submodule.c
>> +++ b/submodule.c
>> @@ -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 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

> 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

>> 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
> 

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [Outreachy] [PATCH v2] diff: do not show submodule with untracked files as "-dirty"
  2020-10-15 17:08 [PATCH] diff: do not show submodule with untracked files as "-dirty" Sangeeta via GitGitGadget
  2020-10-20 13:38 ` [OUTREACHY][PATCH] " Phillip Wood
@ 2020-10-21 13:10 ` Sangeeta Jain
  2020-10-21 17:43   ` Eric Sunshine
  2020-10-22 11:22 ` [Outreachy] [PATCH v3] " Sangeeta Jain
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 36+ messages in thread
From: Sangeeta Jain @ 2020-10-21 13:10 UTC (permalink / raw)
  To: git; +Cc: Sangeeta Jain, phillip.wood123, kaartic.sivaraam, gitster

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.

Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
---
 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 --git a/diff.c b/diff.c
index 2bb2f8f57e..027462a339 100644
--- a/diff.c
+++ b/diff.c
@@ -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 --git a/diff.h b/diff.h
index 11de52e9e9..1e18e6b1c3 100644
--- a/diff.h
+++ b/diff.h
@@ -178,6 +178,7 @@ struct diff_flags {
 	unsigned diff_from_contents;
 	unsigned dirty_submodules;
 	unsigned ignore_untracked_in_submodules;
+	unsigned ignore_submodule_set;
 	unsigned ignore_dirty_submodules;
 	unsigned override_submodule_config;
 	unsigned dirstat_by_line;
diff --git a/submodule.c b/submodule.c
index b3bb59f066..efaba0eff2 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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;
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index ca04fac417..98e46ad1ae 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -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
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index d7145ccca4..6432b4331f 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -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
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index f852136585..bb368b685d 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -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:
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index fc8229c726..dc7b242697 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -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:
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
index 537787e598..78cd86be3a 100755
--- a/t/t7064-wtstatus-pv2.sh
+++ b/t/t7064-wtstatus-pv2.sh
@@ -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
+		# 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
 	)
diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
index 3fcb44767f..72da00a962 100755
--- a/t/t7506-status-submodule.sh
+++ b/t/t7506-status-submodule.sh
@@ -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
-- 
2.21.1 (Apple Git-122.3)


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v2] diff: do not show submodule with untracked files as "-dirty"
  2020-10-21 13:10 ` [Outreachy] [PATCH v2] " Sangeeta Jain
@ 2020-10-21 17:43   ` Eric Sunshine
  2020-10-21 19:40     ` Sangeeta NB
  0 siblings, 1 reply; 36+ messages in thread
From: Eric Sunshine @ 2020-10-21 17:43 UTC (permalink / raw)
  To: Sangeeta Jain; +Cc: Git List, Phillip Wood, Kaartic Sivaraam, Junio C Hamano

On Wed, Oct 21, 2020 at 9:10 AM Sangeeta Jain <sangunb09@gmail.com> wrote:
> [...]
> This patch makes `git diff HEAD` consistent with `git describe --dirty`
> when a submodule contains untracked files by making
> `--ignore-submodules=untracked` the default.
> [...]
> Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
> ---
> diff --git a/diff.c b/diff.c
> @@ -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

> diff --git a/submodule.c b/submodule.c
> @@ -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

> diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
> @@ -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.)

> +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.)

> diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
> @@ -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.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v2] diff: do not show submodule with untracked files as "-dirty"
  2020-10-21 17:43   ` Eric Sunshine
@ 2020-10-21 19:40     ` Sangeeta NB
  2020-10-21 23:04       ` Eric Sunshine
  0 siblings, 1 reply; 36+ messages in thread
From: Sangeeta NB @ 2020-10-21 19:40 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List, Phillip Wood, Kaartic Sivaraam, Junio C Hamano

Hey,

> 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.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v2] diff: do not show submodule with untracked files as "-dirty"
  2020-10-21 19:40     ` Sangeeta NB
@ 2020-10-21 23:04       ` Eric Sunshine
  0 siblings, 0 replies; 36+ messages in thread
From: Eric Sunshine @ 2020-10-21 23:04 UTC (permalink / raw)
  To: Sangeeta NB; +Cc: Git List, Phillip Wood, Kaartic Sivaraam, Junio C Hamano

On Wed, Oct 21, 2020 at 3:40 PM Sangeeta NB <sangunb09@gmail.com> wrote:
> > 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.
>
> 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.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [Outreachy] [PATCH v3] diff: do not show submodule with untracked files as "-dirty"
  2020-10-15 17:08 [PATCH] diff: do not show submodule with untracked files as "-dirty" Sangeeta via GitGitGadget
  2020-10-20 13:38 ` [OUTREACHY][PATCH] " Phillip Wood
  2020-10-21 13:10 ` [Outreachy] [PATCH v2] " Sangeeta Jain
@ 2020-10-22 11:22 ` Sangeeta Jain
  2020-10-22 18:07   ` Junio C Hamano
  2020-10-23 11:17 ` [PATCH v4] " Sangeeta Jain
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 36+ messages in thread
From: Sangeeta Jain @ 2020-10-22 11:22 UTC (permalink / raw)
  To: git; +Cc: sangu09, phillip.wood123, kaartic.sivaraam, gitster, sunshine

From: sangu09 <sangunb09@gmail.com>

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.

Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
---
 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 --git a/diff.c b/diff.c
index 2bb2f8f57e..5a80695da8 100644
--- a/diff.c
+++ b/diff.c
@@ -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 --git a/diff.h b/diff.h
index 11de52e9e9..1e18e6b1c3 100644
--- a/diff.h
+++ b/diff.h
@@ -178,6 +178,7 @@ struct diff_flags {
 	unsigned diff_from_contents;
 	unsigned dirty_submodules;
 	unsigned ignore_untracked_in_submodules;
+	unsigned ignore_submodule_set;
 	unsigned ignore_dirty_submodules;
 	unsigned override_submodule_config;
 	unsigned dirstat_by_line;
diff --git a/submodule.c b/submodule.c
index b3bb59f066..a7956e1539 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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;
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index ca04fac417..98e46ad1ae 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -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
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index d7145ccca4..6432b4331f 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -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
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index f852136585..bb368b685d 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -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:
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index fc8229c726..dc7b242697 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -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:
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
index 537787e598..78cd86be3a 100755
--- a/t/t7064-wtstatus-pv2.sh
+++ b/t/t7064-wtstatus-pv2.sh
@@ -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
+		# 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
 	)
diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
index 3fcb44767f..72da00a962 100755
--- a/t/t7506-status-submodule.sh
+++ b/t/t7506-status-submodule.sh
@@ -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
-- 
2.21.1 (Apple Git-122.3)


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v3] diff: do not show submodule with untracked files as "-dirty"
  2020-10-22 11:22 ` [Outreachy] [PATCH v3] " Sangeeta Jain
@ 2020-10-22 18:07   ` Junio C Hamano
  2020-10-23  5:23     ` Sangeeta NB
  0 siblings, 1 reply; 36+ messages in thread
From: Junio C Hamano @ 2020-10-22 18:07 UTC (permalink / raw)
  To: Sangeeta Jain; +Cc: git, phillip.wood123, kaartic.sivaraam, sunshine

Sangeeta Jain <sangunb09@gmail.com> writes:

> From: sangu09 <sangunb09@gmail.com>

Oops?

> 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.

> 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...".

> 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.


> @@ -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.

> +		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*]

> diff --git a/diff.h b/diff.h
> index 11de52e9e9..1e18e6b1c3 100644
> --- a/diff.h
> +++ b/diff.h
> @@ -178,6 +178,7 @@ struct diff_flags {
>  	unsigned diff_from_contents;
>  	unsigned dirty_submodules;
>  	unsigned ignore_untracked_in_submodules;
> +	unsigned ignore_submodule_set;
>  	unsigned ignore_dirty_submodules;
>  	unsigned override_submodule_config;
>  	unsigned dirstat_by_line;
> diff --git a/submodule.c b/submodule.c
> index b3bb59f066..a7956e1539 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -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.

> @@ -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.

> +	else
> +    	strvec_push (&cp.args, "--ignore-submodules=none");

Misindented.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v3] diff: do not show submodule with untracked files as "-dirty"
  2020-10-22 18:07   ` Junio C Hamano
@ 2020-10-23  5:23     ` Sangeeta NB
  2020-10-23 15:19       ` Junio C Hamano
  0 siblings, 1 reply; 36+ messages in thread
From: Sangeeta NB @ 2020-10-23  5:23 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Phillip Wood, Kaartic Sivaraam, Eric Sunshine

Hey,

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

>
> Oops?
>

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

> 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.

> 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.

> 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.

>
> 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.

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.

> 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!

> 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.

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.

>
> 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.

>
> Misindented.

Noted. Would change that in the next patch.

Thanks and regards,
Sangeeta

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v4] diff: do not show submodule with untracked files as "-dirty"
  2020-10-15 17:08 [PATCH] diff: do not show submodule with untracked files as "-dirty" Sangeeta via GitGitGadget
                   ` (2 preceding siblings ...)
  2020-10-22 11:22 ` [Outreachy] [PATCH v3] " Sangeeta Jain
@ 2020-10-23 11:17 ` Sangeeta Jain
  2020-10-23 15:56   ` Junio C Hamano
  2020-10-23 11:18 ` [Outreachy] " Sangeeta Jain
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 36+ messages in thread
From: Sangeeta Jain @ 2020-10-23 11:17 UTC (permalink / raw)
  To: git; +Cc: sangu09

From: sangu09 <sangunb09@gmail.com>

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.

Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
---
 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 --git a/diff.c b/diff.c
index 2bb2f8f57e..5a80695da8 100644
--- a/diff.c
+++ b/diff.c
@@ -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 --git a/diff.h b/diff.h
index 11de52e9e9..1e18e6b1c3 100644
--- a/diff.h
+++ b/diff.h
@@ -178,6 +178,7 @@ struct diff_flags {
 	unsigned diff_from_contents;
 	unsigned dirty_submodules;
 	unsigned ignore_untracked_in_submodules;
+	unsigned ignore_submodule_set;
 	unsigned ignore_dirty_submodules;
 	unsigned override_submodule_config;
 	unsigned dirstat_by_line;
diff --git a/submodule.c b/submodule.c
index b3bb59f066..30c42cbffe 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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;
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index ca04fac417..98e46ad1ae 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -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
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index d7145ccca4..6432b4331f 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -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
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index f852136585..bb368b685d 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -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:
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index fc8229c726..dc7b242697 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -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:
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
index 537787e598..78cd86be3a 100755
--- a/t/t7064-wtstatus-pv2.sh
+++ b/t/t7064-wtstatus-pv2.sh
@@ -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
+		# 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
 	)
diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
index 3fcb44767f..72da00a962 100755
--- a/t/t7506-status-submodule.sh
+++ b/t/t7506-status-submodule.sh
@@ -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
-- 
2.21.1 (Apple Git-122.3)


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [Outreachy] [PATCH v4] diff: do not show submodule with untracked files as "-dirty"
  2020-10-15 17:08 [PATCH] diff: do not show submodule with untracked files as "-dirty" Sangeeta via GitGitGadget
                   ` (3 preceding siblings ...)
  2020-10-23 11:17 ` [PATCH v4] " Sangeeta Jain
@ 2020-10-23 11:18 ` Sangeeta Jain
  2020-10-23 21:28   ` Junio C Hamano
  2020-10-23 19:29 ` [Outreachy] [PATCH v5] " Sangeeta Jain
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 36+ messages in thread
From: Sangeeta Jain @ 2020-10-23 11:18 UTC (permalink / raw)
  To: git; +Cc: Sangeeta Jain

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.

Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
---
 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 --git a/diff.c b/diff.c
index 2bb2f8f57e..5a80695da8 100644
--- a/diff.c
+++ b/diff.c
@@ -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 --git a/diff.h b/diff.h
index 11de52e9e9..1e18e6b1c3 100644
--- a/diff.h
+++ b/diff.h
@@ -178,6 +178,7 @@ struct diff_flags {
 	unsigned diff_from_contents;
 	unsigned dirty_submodules;
 	unsigned ignore_untracked_in_submodules;
+	unsigned ignore_submodule_set;
 	unsigned ignore_dirty_submodules;
 	unsigned override_submodule_config;
 	unsigned dirstat_by_line;
diff --git a/submodule.c b/submodule.c
index b3bb59f066..30c42cbffe 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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;
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index ca04fac417..98e46ad1ae 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -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
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index d7145ccca4..6432b4331f 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -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
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index f852136585..bb368b685d 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -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:
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index fc8229c726..dc7b242697 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -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:
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
index 537787e598..78cd86be3a 100755
--- a/t/t7064-wtstatus-pv2.sh
+++ b/t/t7064-wtstatus-pv2.sh
@@ -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
+		# 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
 	)
diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
index 3fcb44767f..72da00a962 100755
--- a/t/t7506-status-submodule.sh
+++ b/t/t7506-status-submodule.sh
@@ -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
-- 
2.21.1 (Apple Git-122.3)


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v3] diff: do not show submodule with untracked files as "-dirty"
  2020-10-23  5:23     ` Sangeeta NB
@ 2020-10-23 15:19       ` Junio C Hamano
  2020-10-23 18:17         ` Sangeeta NB
  0 siblings, 1 reply; 36+ messages in thread
From: Junio C Hamano @ 2020-10-23 15:19 UTC (permalink / raw)
  To: Sangeeta NB; +Cc: Git List, Phillip Wood, Kaartic Sivaraam, Eric Sunshine

Sangeeta NB <sangunb09@gmail.com> writes:

> 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 ;)

>> 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.

>> 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?

> 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.

>> 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.
>
> 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.

>> 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.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4] diff: do not show submodule with untracked files as "-dirty"
  2020-10-23 11:17 ` [PATCH v4] " Sangeeta Jain
@ 2020-10-23 15:56   ` Junio C Hamano
  2020-10-23 18:32     ` Sangeeta NB
  0 siblings, 1 reply; 36+ messages in thread
From: Junio C Hamano @ 2020-10-23 15:56 UTC (permalink / raw)
  To: Sangeeta Jain; +Cc: git

Sangeeta Jain <sangunb09@gmail.com> writes:

> From: sangu09 <sangunb09@gmail.com>
>
> 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 --git a/diff.c b/diff.c
> index 2bb2f8f57e..5a80695da8 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -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.

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

Noise.

> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index ca04fac417..98e46ad1ae 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -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?

> diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
> index 537787e598..78cd86be3a 100755
> --- a/t/t7064-wtstatus-pv2.sh
> +++ b/t/t7064-wtstatus-pv2.sh
> @@ -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
> +		# 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.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v3] diff: do not show submodule with untracked files as "-dirty"
  2020-10-23 15:19       ` Junio C Hamano
@ 2020-10-23 18:17         ` Sangeeta NB
  2020-10-23 18:55           ` Junio C Hamano
  0 siblings, 1 reply; 36+ messages in thread
From: Sangeeta NB @ 2020-10-23 18:17 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Phillip Wood, Kaartic Sivaraam, Eric Sunshine

> 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.

> 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.

>
> 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.

>
>
> 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.
>

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

>
> 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.

> I found this change a "noise":

Oh okay, Again sorry for the misunderstanding.

>
>         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.
>

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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4] diff: do not show submodule with untracked files as "-dirty"
  2020-10-23 15:56   ` Junio C Hamano
@ 2020-10-23 18:32     ` Sangeeta NB
  2020-10-23 20:22       ` Junio C Hamano
  0 siblings, 1 reply; 36+ messages in thread
From: Sangeeta NB @ 2020-10-23 18:32 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List

>
> 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.

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

>
> > diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> > index ca04fac417..98e46ad1ae 100755
> > --- a/t/t3701-add-interactive.sh
> > +++ b/t/t3701-add-interactive.sh
> > @@ -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?
>

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.

>
> 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.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v3] diff: do not show submodule with untracked files as "-dirty"
  2020-10-23 18:17         ` Sangeeta NB
@ 2020-10-23 18:55           ` Junio C Hamano
  2020-10-23 19:08             ` Sangeeta NB
  0 siblings, 1 reply; 36+ messages in thread
From: Junio C Hamano @ 2020-10-23 18:55 UTC (permalink / raw)
  To: Sangeeta NB; +Cc: Git List, Phillip Wood, Kaartic Sivaraam, Eric Sunshine

Sangeeta NB <sangunb09@gmail.com> writes:

>> I found this change a "noise":
>
> Oh okay, Again sorry for the misunderstanding.
>
>>
>>         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.
>>
> 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.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v3] diff: do not show submodule with untracked files as "-dirty"
  2020-10-23 18:55           ` Junio C Hamano
@ 2020-10-23 19:08             ` Sangeeta NB
  0 siblings, 0 replies; 36+ messages in thread
From: Sangeeta NB @ 2020-10-23 19:08 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Phillip Wood, Kaartic Sivaraam, Eric Sunshine

On Sat, Oct 24, 2020 at 12:25 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Sangeeta NB <sangunb09@gmail.com> writes:
>
> >> I found this change a "noise":
> >
> > Oh okay, Again sorry for the misunderstanding.
> >
> >>
> >>         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.
> >>
> > 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.

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.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [Outreachy] [PATCH v5] diff: do not show submodule with untracked files as "-dirty"
  2020-10-15 17:08 [PATCH] diff: do not show submodule with untracked files as "-dirty" Sangeeta via GitGitGadget
                   ` (4 preceding siblings ...)
  2020-10-23 11:18 ` [Outreachy] " Sangeeta Jain
@ 2020-10-23 19:29 ` Sangeeta Jain
  2020-10-26 17:57 ` [Outreachy][PATCH v6] " Sangeeta Jain
  2020-11-10  8:39 ` [Outreachy][PATCH v7] " Sangeeta Jain
  7 siblings, 0 replies; 36+ messages in thread
From: Sangeeta Jain @ 2020-10-23 19:29 UTC (permalink / raw)
  To: git; +Cc: Sangeeta Jain, phillip.wood123, kaartic.sivaraam, gitster, sunshine

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.

Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
---
 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 --git a/diff.c b/diff.c
index 2bb2f8f57e..5d69c2bb1c 100644
--- a/diff.c
+++ b/diff.c
@@ -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 --git a/diff.h b/diff.h
index 11de52e9e9..1e18e6b1c3 100644
--- a/diff.h
+++ b/diff.h
@@ -178,6 +178,7 @@ struct diff_flags {
 	unsigned diff_from_contents;
 	unsigned dirty_submodules;
 	unsigned ignore_untracked_in_submodules;
+	unsigned ignore_submodule_set;
 	unsigned ignore_dirty_submodules;
 	unsigned override_submodule_config;
 	unsigned dirstat_by_line;
diff --git a/submodule.c b/submodule.c
index b3bb59f066..afeb754079 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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;
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index ca04fac417..9104d1946d 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -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 &&
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index d7145ccca4..6432b4331f 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -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
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index f852136585..bb368b685d 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -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:
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index fc8229c726..dc7b242697 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -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:
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
index 537787e598..78cd86be3a 100755
--- a/t/t7064-wtstatus-pv2.sh
+++ b/t/t7064-wtstatus-pv2.sh
@@ -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
+		# 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
 	)
diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
index 3fcb44767f..72da00a962 100755
--- a/t/t7506-status-submodule.sh
+++ b/t/t7506-status-submodule.sh
@@ -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
-- 
2.21.1 (Apple Git-122.3)


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4] diff: do not show submodule with untracked files as "-dirty"
  2020-10-23 18:32     ` Sangeeta NB
@ 2020-10-23 20:22       ` Junio C Hamano
  0 siblings, 0 replies; 36+ messages in thread
From: Junio C Hamano @ 2020-10-23 20:22 UTC (permalink / raw)
  To: Sangeeta NB; +Cc: Git List

Sangeeta NB <sangunb09@gmail.com> writes:

>> 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.

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?

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v4] diff: do not show submodule with untracked files as "-dirty"
  2020-10-23 11:18 ` [Outreachy] " Sangeeta Jain
@ 2020-10-23 21:28   ` Junio C Hamano
  2020-10-25 10:23     ` Sangeeta NB
  0 siblings, 1 reply; 36+ messages in thread
From: Junio C Hamano @ 2020-10-23 21:28 UTC (permalink / raw)
  To: Sangeeta Jain; +Cc: git

Sangeeta Jain <sangunb09@gmail.com> writes:

> diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
> ...
> +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.

> -	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?

> diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
> index f852136585..bb368b685d 100755
> --- a/t/t4041-diff-submodule-option.sh
> +++ b/t/t4041-diff-submodule-option.sh
> @@ -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 &&

Likewise.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v4] diff: do not show submodule with untracked files as "-dirty"
  2020-10-23 21:28   ` Junio C Hamano
@ 2020-10-25 10:23     ` Sangeeta NB
  2020-10-26 17:36       ` Junio C Hamano
  0 siblings, 1 reply; 36+ messages in thread
From: Sangeeta NB @ 2020-10-25 10:23 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List

On Sat, Oct 24, 2020 at 2:58 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Sangeeta Jain <sangunb09@gmail.com> writes:
>
> > diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
> > ...
> > +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.
>

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?


> > -     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,

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy] [PATCH v4] diff: do not show submodule with untracked files as "-dirty"
  2020-10-25 10:23     ` Sangeeta NB
@ 2020-10-26 17:36       ` Junio C Hamano
  0 siblings, 0 replies; 36+ messages in thread
From: Junio C Hamano @ 2020-10-26 17:36 UTC (permalink / raw)
  To: Sangeeta NB; +Cc: Git List

Sangeeta NB <sangunb09@gmail.com> writes:

>> > -     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?

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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [Outreachy][PATCH v6] diff: do not show submodule with untracked files as "-dirty"
  2020-10-15 17:08 [PATCH] diff: do not show submodule with untracked files as "-dirty" Sangeeta via GitGitGadget
                   ` (5 preceding siblings ...)
  2020-10-23 19:29 ` [Outreachy] [PATCH v5] " Sangeeta Jain
@ 2020-10-26 17:57 ` Sangeeta Jain
  2020-11-03 10:46   ` Sangeeta
  2020-11-07 11:10   ` Đoàn Trần Công Danh
  2020-11-10  8:39 ` [Outreachy][PATCH v7] " Sangeeta Jain
  7 siblings, 2 replies; 36+ messages in thread
From: Sangeeta Jain @ 2020-10-26 17:57 UTC (permalink / raw)
  To: git; +Cc: Sangeeta Jain, phillip.wood123, kaartic.sivaraam, gitster, sunshine

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.

Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
---
 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 --git a/diff.c b/diff.c
index 2bb2f8f57e..5d69c2bb1c 100644
--- a/diff.c
+++ b/diff.c
@@ -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 --git a/diff.h b/diff.h
index 11de52e9e9..1e18e6b1c3 100644
--- a/diff.h
+++ b/diff.h
@@ -178,6 +178,7 @@ struct diff_flags {
 	unsigned diff_from_contents;
 	unsigned dirty_submodules;
 	unsigned ignore_untracked_in_submodules;
+	unsigned ignore_submodule_set;
 	unsigned ignore_dirty_submodules;
 	unsigned override_submodule_config;
 	unsigned dirstat_by_line;
diff --git a/submodule.c b/submodule.c
index b3bb59f066..afeb754079 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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;
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index ca04fac417..9104d1946d 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -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 &&
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index d7145ccca4..894a11b224 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -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
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index f852136585..bb368b685d 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -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:
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index fc8229c726..dc7b242697 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -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:
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
index 537787e598..78cd86be3a 100755
--- a/t/t7064-wtstatus-pv2.sh
+++ b/t/t7064-wtstatus-pv2.sh
@@ -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
+		# 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
 	)
diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
index 3fcb44767f..72da00a962 100755
--- a/t/t7506-status-submodule.sh
+++ b/t/t7506-status-submodule.sh
@@ -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
-- 
2.21.1 (Apple Git-122.3)


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy][PATCH v6] diff: do not show submodule with untracked files as "-dirty"
  2020-10-26 17:57 ` [Outreachy][PATCH v6] " Sangeeta Jain
@ 2020-11-03 10:46   ` Sangeeta
  2020-11-03 17:55     ` Junio C Hamano
  2020-11-07 11:10   ` Đoàn Trần Công Danh
  1 sibling, 1 reply; 36+ messages in thread
From: Sangeeta @ 2020-11-03 10:46 UTC (permalink / raw)
  To: Git List
  Cc: Phillip Wood, Kaartic Sivaraam, Junio C Hamano, Johannes Schindelin

Hey Johannes and Junio,

In continuation of the discussion from here[1]

[1] https://lore.kernel.org/git/nycvar.QRO.7.76.6.2011020251520.18437@tvgsbejvaqbjf.bet/

> >> * 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?

> > 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.

>
> 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.
>
> 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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy][PATCH v6] diff: do not show submodule with untracked files as "-dirty"
  2020-11-03 10:46   ` Sangeeta
@ 2020-11-03 17:55     ` Junio C Hamano
  2020-11-07 10:47       ` Sangeeta
  0 siblings, 1 reply; 36+ messages in thread
From: Junio C Hamano @ 2020-11-03 17:55 UTC (permalink / raw)
  To: Sangeeta; +Cc: Git List, Phillip Wood, Kaartic Sivaraam, Johannes Schindelin

Sangeeta <sangunb09@gmail.com> writes:

> Hey Johannes and Junio,
>
> In continuation of the discussion from here[1]
>
> [1] https://lore.kernel.org/git/nycvar.QRO.7.76.6.2011020251520.18437@tvgsbejvaqbjf.bet/
>
>> >> * 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?

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?

>> > 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 ;-)

> 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.

> 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.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy][PATCH v6] diff: do not show submodule with untracked files as "-dirty"
  2020-11-03 17:55     ` Junio C Hamano
@ 2020-11-07 10:47       ` Sangeeta
  2020-12-08 21:02         ` Junio C Hamano
  0 siblings, 1 reply; 36+ messages in thread
From: Sangeeta @ 2020-11-07 10:47 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git List, Phillip Wood, Kaartic Sivaraam, Johannes Schindelin

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!

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy][PATCH v6] diff: do not show submodule with untracked files as "-dirty"
  2020-10-26 17:57 ` [Outreachy][PATCH v6] " Sangeeta Jain
  2020-11-03 10:46   ` Sangeeta
@ 2020-11-07 11:10   ` Đoàn Trần Công Danh
  2020-11-09 15:19     ` Sangeeta
  1 sibling, 1 reply; 36+ messages in thread
From: Đoàn Trần Công Danh @ 2020-11-07 11:10 UTC (permalink / raw)
  To: Sangeeta Jain; +Cc: git, phillip.wood123, kaartic.sivaraam, gitster, sunshine

Hi Sangeeta,

On 2020-10-26 23:27:42+0530, Sangeeta Jain <sangunb09@gmail.com> wrote:
> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index ca04fac417..9104d1946d 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -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!

>  	dirty-otherwise
>  	EOF
>  	test_cmp expected actual &&
> diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
> index d7145ccca4..894a11b224 100755
> --- a/t/t4027-diff-submodule.sh
> +++ b/t/t4027-diff-submodule.sh
> @@ -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
> diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
> index f852136585..bb368b685d 100755
> --- a/t/t4041-diff-submodule-option.sh
> +++ b/t/t4041-diff-submodule-option.sh
> @@ -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

>  	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:
> diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
> index fc8229c726..dc7b242697 100755
> --- a/t/t4060-diff-submodule-option-diff-format.sh
> +++ b/t/t4060-diff-submodule-option-diff-format.sh
> @@ -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:
> diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
> index 537787e598..78cd86be3a 100755
> --- a/t/t7064-wtstatus-pv2.sh
> +++ b/t/t7064-wtstatus-pv2.sh
> @@ -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
> +		) &&

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.

> +
> +		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
>  	)
> diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh
> index 3fcb44767f..72da00a962 100755
> --- a/t/t7506-status-submodule.sh
> +++ b/t/t7506-status-submodule.sh
> @@ -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
> -- 
> 2.21.1 (Apple Git-122.3)
> 

-- 
Danh

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy][PATCH v6] diff: do not show submodule with untracked files as "-dirty"
  2020-11-07 11:10   ` Đoàn Trần Công Danh
@ 2020-11-09 15:19     ` Sangeeta
  2020-11-09 17:01       ` Junio C Hamano
  0 siblings, 1 reply; 36+ messages in thread
From: Sangeeta @ 2020-11-09 15:19 UTC (permalink / raw)
  To: Đoàn Trần Công Danh
  Cc: Git List, Phillip Wood, Kaartic Sivaraam, Junio C Hamano, Eric Sunshine

Hey Danh,


> > diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> > index ca04fac417..9104d1946d 100755
> > --- a/t/t3701-add-interactive.sh
> > +++ b/t/t3701-add-interactive.sh
> > @@ -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!

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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy][PATCH v6] diff: do not show submodule with untracked files as "-dirty"
  2020-11-09 15:19     ` Sangeeta
@ 2020-11-09 17:01       ` Junio C Hamano
  0 siblings, 0 replies; 36+ messages in thread
From: Junio C Hamano @ 2020-11-09 17:01 UTC (permalink / raw)
  To: Sangeeta
  Cc: Đoàn Trần Công Danh, Git List, Phillip Wood,
	Kaartic Sivaraam, Eric Sunshine

Sangeeta <sangunb09@gmail.com> writes:

>> > diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
>> > index ca04fac417..9104d1946d 100755
>> > --- a/t/t3701-add-interactive.sh
>> > +++ b/t/t3701-add-interactive.sh
>> > @@ -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!
>
> 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.


^ permalink raw reply	[flat|nested] 36+ messages in thread

* [Outreachy][PATCH v7] diff: do not show submodule with untracked files as "-dirty"
  2020-10-15 17:08 [PATCH] diff: do not show submodule with untracked files as "-dirty" Sangeeta via GitGitGadget
                   ` (6 preceding siblings ...)
  2020-10-26 17:57 ` [Outreachy][PATCH v6] " Sangeeta Jain
@ 2020-11-10  8:39 ` Sangeeta Jain
  2020-11-10 17:09   ` Đoàn Trần Công Danh
  2020-12-08 13:36   ` Sangeeta
  7 siblings, 2 replies; 36+ messages in thread
From: Sangeeta Jain @ 2020-11-10  8:39 UTC (permalink / raw)
  To: git; +Cc: Sangeeta Jain, phillip.wood123, kaartic.sivaraam, gitster, sunshine

Git diff reports a submodule directory as -dirty even when there are
only untracked files in the submodule directory. This is inconsistent
with what `git describe --dirty` says when run in the submodule
directory in that state.

Make `--ignore-submodules=untracked` the default for `git diff` when
there is no configuration variable or command line option, so that the
command would not give '-dirty' suffix to a submodule whose working
tree has untracked files, to make it consistent with `git
describe --dirty` that is run in the submodule working tree.

And also make `--ignore-submodules=none` the default for `git status`
so that the user doesn't end up deleting a submodule that has
uncommitted (untracked) files.

Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
---
 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(-)

diff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt
index c3ae136eba..2d3331f55c 100644
--- a/Documentation/config/diff.txt
+++ b/Documentation/config/diff.txt
@@ -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 --git a/diff.c b/diff.c
index 2bb2f8f57e..5a80695da8 100644
--- a/diff.c
+++ b/diff.c
@@ -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 --git a/diff.h b/diff.h
index 11de52e9e9..1e18e6b1c3 100644
--- a/diff.h
+++ b/diff.h
@@ -178,6 +178,7 @@ struct diff_flags {
 	unsigned diff_from_contents;
 	unsigned dirty_submodules;
 	unsigned ignore_untracked_in_submodules;
+	unsigned ignore_submodule_set;
 	unsigned ignore_dirty_submodules;
 	unsigned override_submodule_config;
 	unsigned dirstat_by_line;
diff --git a/submodule.c b/submodule.c
index b3bb59f066..8f6227c993 100644
--- a/submodule.c
+++ b/submodule.c
@@ -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;
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index ca04fac417..9a2489cde0 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -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 &&
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index d7145ccca4..894a11b224 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -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
diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
index f852136585..b3a7b7acaa 100755
--- a/t/t4041-diff-submodule-option.sh
+++ b/t/t4041-diff-submodule-option.sh
@@ -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:
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index fc8229c726..dc7b242697 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -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:
diff --git a/wt-status.c b/wt-status.c
index 7074bbdd53..83d418647d 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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)


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy][PATCH v7] diff: do not show submodule with untracked files as "-dirty"
  2020-11-10  8:39 ` [Outreachy][PATCH v7] " Sangeeta Jain
@ 2020-11-10 17:09   ` Đoàn Trần Công Danh
  2020-12-08 13:36   ` Sangeeta
  1 sibling, 0 replies; 36+ messages in thread
From: Đoàn Trần Công Danh @ 2020-11-10 17:09 UTC (permalink / raw)
  To: Sangeeta Jain; +Cc: git, phillip.wood123, kaartic.sivaraam, gitster, sunshine

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).

On 2020-11-10 14:09:00+0530, Sangeeta Jain <sangunb09@gmail.com> wrote:
> diff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt
> index c3ae136eba..2d3331f55c 100644
> --- a/Documentation/config/diff.txt
> +++ b/Documentation/config/diff.txt
> @@ -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

>  
>  diff.mnemonicPrefix::
>  	If set, 'git diff' uses a prefix pair that is different from the
> diff --git a/diff.c b/diff.c
> index 2bb2f8f57e..5a80695da8 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -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 --git a/diff.h b/diff.h
> index 11de52e9e9..1e18e6b1c3 100644
> --- a/diff.h
> +++ b/diff.h
> @@ -178,6 +178,7 @@ struct diff_flags {
>  	unsigned diff_from_contents;
>  	unsigned dirty_submodules;
>  	unsigned ignore_untracked_in_submodules;
> +	unsigned ignore_submodule_set;
>  	unsigned ignore_dirty_submodules;
>  	unsigned override_submodule_config;
>  	unsigned dirstat_by_line;
> diff --git a/submodule.c b/submodule.c
> index b3bb59f066..8f6227c993 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -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;
> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index ca04fac417..9a2489cde0 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -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 &&
> diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
> index d7145ccca4..894a11b224 100755
> --- a/t/t4027-diff-submodule.sh
> +++ b/t/t4027-diff-submodule.sh
> @@ -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
> diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
> index f852136585..b3a7b7acaa 100755
> --- a/t/t4041-diff-submodule-option.sh
> +++ b/t/t4041-diff-submodule-option.sh
> @@ -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:
> diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
> index fc8229c726..dc7b242697 100755
> --- a/t/t4060-diff-submodule-option-diff-format.sh
> +++ b/t/t4060-diff-submodule-option-diff-format.sh
> @@ -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:
> diff --git a/wt-status.c b/wt-status.c
> index 7074bbdd53..83d418647d 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -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)
> 

-- 
Danh

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy][PATCH v7] diff: do not show submodule with untracked files as "-dirty"
  2020-11-10  8:39 ` [Outreachy][PATCH v7] " Sangeeta Jain
  2020-11-10 17:09   ` Đoàn Trần Công Danh
@ 2020-12-08 13:36   ` Sangeeta
  2020-12-08 22:26     ` Junio C Hamano
  1 sibling, 1 reply; 36+ messages in thread
From: Sangeeta @ 2020-12-08 13:36 UTC (permalink / raw)
  To: Git List, Junio C Hamano

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

On Tue, Nov 10, 2020 at 2:09 PM Sangeeta Jain <sangunb09@gmail.com> wrote:
>
> Git diff reports a submodule directory as -dirty even when there are
> only untracked files in the submodule directory. This is inconsistent
> with what `git describe --dirty` says when run in the submodule
> directory in that state.
>
> Make `--ignore-submodules=untracked` the default for `git diff` when
> there is no configuration variable or command line option, so that the
> command would not give '-dirty' suffix to a submodule whose working
> tree has untracked files, to make it consistent with `git
> describe --dirty` that is run in the submodule working tree.
>
> And also make `--ignore-submodules=none` the default for `git status`
> so that the user doesn't end up deleting a submodule that has
> uncommitted (untracked) files.
>
> Signed-off-by: Sangeeta Jain <sangunb09@gmail.com>
> ---
>  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(-)
>
> diff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt
> index c3ae136eba..2d3331f55c 100644
> --- a/Documentation/config/diff.txt
> +++ b/Documentation/config/diff.txt
> @@ -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 --git a/diff.c b/diff.c
> index 2bb2f8f57e..5a80695da8 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -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 --git a/diff.h b/diff.h
> index 11de52e9e9..1e18e6b1c3 100644
> --- a/diff.h
> +++ b/diff.h
> @@ -178,6 +178,7 @@ struct diff_flags {
>         unsigned diff_from_contents;
>         unsigned dirty_submodules;
>         unsigned ignore_untracked_in_submodules;
> +       unsigned ignore_submodule_set;
>         unsigned ignore_dirty_submodules;
>         unsigned override_submodule_config;
>         unsigned dirstat_by_line;
> diff --git a/submodule.c b/submodule.c
> index b3bb59f066..8f6227c993 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -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;
> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index ca04fac417..9a2489cde0 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -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 &&
> diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
> index d7145ccca4..894a11b224 100755
> --- a/t/t4027-diff-submodule.sh
> +++ b/t/t4027-diff-submodule.sh
> @@ -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
> diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
> index f852136585..b3a7b7acaa 100755
> --- a/t/t4041-diff-submodule-option.sh
> +++ b/t/t4041-diff-submodule-option.sh
> @@ -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:
> diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
> index fc8229c726..dc7b242697 100755
> --- a/t/t4060-diff-submodule-option-diff-format.sh
> +++ b/t/t4060-diff-submodule-option-diff-format.sh
> @@ -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:
> diff --git a/wt-status.c b/wt-status.c
> index 7074bbdd53..83d418647d 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -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)
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy][PATCH v6] diff: do not show submodule with untracked files as "-dirty"
  2020-11-07 10:47       ` Sangeeta
@ 2020-12-08 21:02         ` Junio C Hamano
  0 siblings, 0 replies; 36+ messages in thread
From: Junio C Hamano @ 2020-12-08 21:02 UTC (permalink / raw)
  To: Sangeeta; +Cc: Git List, Phillip Wood, Kaartic Sivaraam, Johannes Schindelin

Sangeeta <sangunb09@gmail.com> writes:

> 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?

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...




^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Outreachy][PATCH v7] diff: do not show submodule with untracked files as "-dirty"
  2020-12-08 13:36   ` Sangeeta
@ 2020-12-08 22:26     ` Junio C Hamano
  0 siblings, 0 replies; 36+ messages in thread
From: Junio C Hamano @ 2020-12-08 22:26 UTC (permalink / raw)
  To: Sangeeta; +Cc: Git List

Sangeeta <sangunb09@gmail.com> writes:

> 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.

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2020-12-08 22:28 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 17:08 [PATCH] diff: do not show submodule with untracked files as "-dirty" Sangeeta via GitGitGadget
2020-10-20 13:38 ` [OUTREACHY][PATCH] " Phillip Wood
2020-10-20 18:10   ` Sangeeta NB
2020-10-21 11:28     ` Phillip Wood
2020-10-21 13:10 ` [Outreachy] [PATCH v2] " Sangeeta Jain
2020-10-21 17:43   ` Eric Sunshine
2020-10-21 19:40     ` Sangeeta NB
2020-10-21 23:04       ` Eric Sunshine
2020-10-22 11:22 ` [Outreachy] [PATCH v3] " Sangeeta Jain
2020-10-22 18:07   ` Junio C Hamano
2020-10-23  5:23     ` Sangeeta NB
2020-10-23 15:19       ` Junio C Hamano
2020-10-23 18:17         ` Sangeeta NB
2020-10-23 18:55           ` Junio C Hamano
2020-10-23 19:08             ` Sangeeta NB
2020-10-23 11:17 ` [PATCH v4] " Sangeeta Jain
2020-10-23 15:56   ` Junio C Hamano
2020-10-23 18:32     ` Sangeeta NB
2020-10-23 20:22       ` Junio C Hamano
2020-10-23 11:18 ` [Outreachy] " Sangeeta Jain
2020-10-23 21:28   ` Junio C Hamano
2020-10-25 10:23     ` Sangeeta NB
2020-10-26 17:36       ` Junio C Hamano
2020-10-23 19:29 ` [Outreachy] [PATCH v5] " Sangeeta Jain
2020-10-26 17:57 ` [Outreachy][PATCH v6] " Sangeeta Jain
2020-11-03 10:46   ` Sangeeta
2020-11-03 17:55     ` Junio C Hamano
2020-11-07 10:47       ` Sangeeta
2020-12-08 21:02         ` Junio C Hamano
2020-11-07 11:10   ` Đoàn Trần Công Danh
2020-11-09 15:19     ` Sangeeta
2020-11-09 17:01       ` Junio C Hamano
2020-11-10  8:39 ` [Outreachy][PATCH v7] " Sangeeta Jain
2020-11-10 17:09   ` Đoàn Trần Công Danh
2020-12-08 13:36   ` Sangeeta
2020-12-08 22:26     ` Junio C Hamano

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).