Skip to content

Commit c215d3d

Browse files
jlehmanngitster
authored andcommitted
commit -m: commit staged submodules regardless of ignore config
The previous commit fixed the problem that the staged but that ignored submodules did not show up in the status output of the commit command and weren't committed afterwards either. But when commit doesn't generate the status output (e.g. when used in a script with '-m') the ignored submodule will still not be committed. This is because in that case a different code path is taken which calls index_differs_from() instead of calling the wt_status functions. Fix that by calling index_differs_from() from builtin/commit.c with a diff_options argument value that tells it not ignore any submodule changes unless the '--ignore-submodules' option is used. Even though this option isn't yet implemented for cmd_commit() but only for cmd_status() this prepares cmd_commit() to correctly handle the '--ignore-submodules' option later. As status and commit share the same ignore_submodule_arg variable this makes the code more robust against accidental breakage and documents how to correctly call index_differs_from(). Change the expected result of the test documenting this problem from failure to success. Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d2f393 commit c215d3d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

builtin/commit.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,22 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
826826

827827
if (get_sha1(parent, sha1))
828828
commitable = !!active_nr;
829-
else
830-
commitable = index_differs_from(parent, 0);
829+
else {
830+
/*
831+
* Unless the user did explicitly request a submodule
832+
* ignore mode by passing a command line option we do
833+
* not ignore any changed submodule SHA-1s when
834+
* comparing index and parent, no matter what is
835+
* configured. Otherwise we won't commit any
836+
* submodules which were manually staged, which would
837+
* be really confusing.
838+
*/
839+
int diff_flags = DIFF_OPT_OVERRIDE_SUBMODULE_CONFIG;
840+
if (ignore_submodule_arg &&
841+
!strcmp(ignore_submodule_arg, "all"))
842+
diff_flags |= DIFF_OPT_IGNORE_SUBMODULES;
843+
commitable = index_differs_from(parent, diff_flags);
844+
}
831845
}
832846
strbuf_release(&committer_ident);
833847

t/t7508-status.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ EOF
15231523
test_i18ngrep "^M. sm" output
15241524
'
15251525

1526-
test_expect_failure 'git commit -m will commit a staged but ignored submodule' '
1526+
test_expect_success 'git commit -m will commit a staged but ignored submodule' '
15271527
git commit -uno -m message &&
15281528
git status -s --ignore-submodules=dirty >output &&
15291529
test_i18ngrep ! "^M. sm" output &&

0 commit comments

Comments
 (0)