diff mbox series

Fixing diff.ignoreSubmodules

Message ID 4489241.31r3eYUQgx@twilight (mailing list archive)
State New, archived
Headers show
Series Fixing diff.ignoreSubmodules | expand

Commit Message

Allan Jensen May 17, 2019, 12:11 p.m. UTC
Hi git team

I had trouble getting diff.ignoreSubmodules to work at all in any of my git 
projects, and googling around I found many other people who also couldn't get 
it to work. I found the source of the issue and attached a patch fixing it, 
though the old non-working behavior seems to have been almost on purpose.
(further details are in the change)

Feel free to apply or rewrite as you want.

Best regards
'Allan
diff mbox series

Patch

commit 4600b16e3a094a3b35628fc954951117d4d64a06
Author: Allan Sandfeld Jensen <allan.jensen@qt.io>
Date:   Fri May 17 14:01:55 2019 +0200

    Fix diff.ignoreSubmodules to match documentation
    
    It was not operating as the default value of --ignore-submodules,
    since unlike the command-line option it was overridden by
    module.X.ignore. And since many projects set a submobule ignore
    value by default, diff.ignoreSubmodules was in many cases not
    working at all.

diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt
index 0a1293b051..08daeca753 100644
--- a/Documentation/config/submodule.txt
+++ b/Documentation/config/submodule.txt
@@ -43,8 +43,8 @@  submodule.<name>.ignore::
 	submodules that have untracked files in their work tree as changed.
 	This setting overrides any setting made in .gitmodules for this submodule,
 	both settings can be overridden on the command line by using the
-	"--ignore-submodules" option. The 'git submodule' commands are not
-	affected by this setting.
+	"--ignore-submodules" option, or setting diff.ignoreSubmodules.
+	The 'git submodule' commands are not affected by this setting.
 
 submodule.<name>.active::
 	Boolean value indicating if the submodule is of interest to git
diff --git a/diff.c b/diff.c
index 4d3cf83a27..9b465d5f6c 100644
--- a/diff.c
+++ b/diff.c
@@ -5074,7 +5074,6 @@  static int diff_opt_ignore_submodules(const struct option *opt,
 	BUG_ON_OPT_NEG(unset);
 	if (!arg)
 		arg = "all";
-	options->flags.override_submodule_config = 1;
 	handle_ignore_submodules_arg(options, arg);
 	return 0;
 }
diff --git a/submodule.c b/submodule.c
index 2cfaba0599..4a3cfe7b36 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.override_submodule_config = 1;
 	diffopt->flags.ignore_submodules = 0;
 	diffopt->flags.ignore_untracked_in_submodules = 0;
 	diffopt->flags.ignore_dirty_submodules = 0;
diff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh
index 8f86b5f4b2..05b0c759b9 100755
--- a/t/t2013-checkout-submodule.sh
+++ b/t/t2013-checkout-submodule.sh
@@ -44,11 +44,11 @@  test_expect_success '"checkout <submodule>" honors diff.ignoreSubmodules' '
 	git config diff.ignoreSubmodules dirty &&
 	echo x> submodule/untracked &&
 	git checkout HEAD >actual 2>&1 &&
-	test_must_be_empty actual
+	test_must_be_empty actual &&
+	git config --unset diff.ignoreSubmodules
 '
 
 test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .gitmodules' '
-	git config diff.ignoreSubmodules none &&
 	git config -f .gitmodules submodule.submodule.path submodule &&
 	git config -f .gitmodules submodule.submodule.ignore untracked &&
 	git checkout HEAD >actual 2>&1 &&
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index 9aa8e2b39b..e84358ca02 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -117,6 +117,7 @@  test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)
 	git config diff.ignoreSubmodules dirty &&
 	git diff HEAD >actual &&
 	test_must_be_empty actual &&
+	git config --unset diff.ignoreSubmodules &&
 	git config --add -f .gitmodules submodule.subname.ignore none &&
 	git config --add -f .gitmodules submodule.subname.path sub &&
 	git diff HEAD >actual &&
@@ -143,7 +144,6 @@  test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)
 	test_cmp expect.body actual.body &&
 	git config --remove-section submodule.subname &&
 	git config --remove-section -f .gitmodules submodule.subname &&
-	git config --unset diff.ignoreSubmodules &&
 	rm .gitmodules
 '