git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] diff-lib: honor override_submodule_config flag bit
@ 2023-06-14  4:16 Josip Sokcevic
  2023-06-14  4:56 ` Eric Sunshine
  2023-06-14  7:06 ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Josip Sokcevic @ 2023-06-14  4:16 UTC (permalink / raw)
  To: git; +Cc: Josip Sokcevic

When `diff.ignoreSubmodules = all` is set and a submodule commit is
manually staged, `git-commit` should accept it.

`index_differs_from` is called from `prepare_to_commit` with flags set to
`override_submodule_config = 1`. `index_differs_from` then merges the
default diff flags and passed flags.

When `diff.ignoreSubmodules` is set to "all", `flags` ends up having
both `override_submodule_config` and `ignore_submodules` set to 1. This
results in `git-commit` ignoring staged commits.

This patch restores original `flags.ignore_submodule` if
`flags.override_submodule_config` is set.
---
 diff-lib.c                  |  7 ++++++-
 t/t7406-submodule-update.sh | 28 ++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/diff-lib.c b/diff-lib.c
index 60e979dc1b..75859bd159 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -669,8 +669,13 @@ int index_differs_from(struct repository *r,
 	setup_revisions(0, NULL, &rev, &opt);
 	rev.diffopt.flags.quick = 1;
 	rev.diffopt.flags.exit_with_status = 1;
-	if (flags)
+	if (flags) {
 		diff_flags_or(&rev.diffopt.flags, flags);
+		// Now that flags are merged, honor override_submodule_config
+		// and ignore_submodules from passed flags.
+		if ((*flags).override_submodule_config)
+			rev.diffopt.flags.ignore_submodules = (*flags).ignore_submodules;
+	}
 	rev.diffopt.ita_invisible_in_index = ita_invisible_in_index;
 	run_diff_index(&rev, 1);
 	has_changes = rev.diffopt.flags.has_changes;
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index f094e3d7f3..0e3fa642dd 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1179,4 +1179,32 @@ test_expect_success 'submodule update --recursive skip submodules with strategy=
 	test_cmp expect.err actual.err
 '
 
+add_submodule_commits_and_validate () {
+	HASH=$(git rev-parse HEAD) &&
+	git update-index --add --cacheinfo 160000,$HASH,sub &&
+	git commit -m "create submodule" &&
+	git ls-tree HEAD >output &&
+	test_i18ngrep "$HASH" output &&
+
+	rm output
+}
+
+
+test_expect_success 'commit with staged submodule change' '
+	add_submodule_commits_and_validate
+'
+
+
+test_expect_success 'commit with staged submodule change with ignoreSubmodules dirty' '
+	git config diff.ignoreSubmodules dirty &&
+	add_submodule_commits_and_validate &&
+	git config --unset diff.ignoreSubmodules
+'
+
+test_expect_success 'commit with staged submodule change with ignoreSubmodules all' '
+	git config diff.ignoreSubmodules all &&
+	add_submodule_commits_and_validate &&
+	git config --unset diff.ignoreSubmodules
+'
+
 test_done
-- 
2.41.0.162.gfafddb0af9-goog


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

end of thread, other threads:[~2023-06-14 18:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14  4:16 [PATCH] diff-lib: honor override_submodule_config flag bit Josip Sokcevic
2023-06-14  4:56 ` Eric Sunshine
2023-06-14  7:06 ` Junio C Hamano
2023-06-14 18:45   ` Josip Sokcevic

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 NNTP newsgroup(s).