From 1d2f393ac9bfb4c20f14d6ead7bb4c56e766ab77 Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Sat, 5 Apr 2014 18:59:03 +0200 Subject: status/commit: show staged submodules regardless of ignore config Currently setting submodule..ignore and/or diff.ignoreSubmodules to "all" suppresses all output of submodule changes for the diff family, status and commit. For status and commit this is really confusing, as it 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. To add insult to injury, a later "git commit" will error out with "nothing to commit" when only ignored submodules are staged. Fix that by making wt_status always print staged submodule changes, no matter what ignore settings are configured. The only exception is when the user explicitly uses the "--ignore-submodules=all" command line option, in that case the submodule output is still suppressed. This also makes "git commit" work again when only modifications of ignored submodules are staged, as that command uses the "commitable" member of the wt_status struct to determine if staged changes are present. But this only happens when the commit command uses the wt_status* functions to produce status output for human consumption (when forking an editor or with --dry-run), in all other cases (e.g. when run in a script with '-m') another code path is taken which uses index_differs_from() to determine if any changes are staged which still ignores submodules according to their configuration. This will be fixed in a follow-up commit. Change t7508 to reflect this new behavior and add three new tests to show that a single staged submodule configured to be ignored will be committed when the status output is generated and won't be if not. Also update the documentation of the ignore config options accordingly. Signed-off-by: Jens Lehmann Signed-off-by: Junio C Hamano --- t/t7508-status.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) (limited to 't/t7508-status.sh') diff --git a/t/t7508-status.sh b/t/t7508-status.sh index c987b5ed65..e6483fcd42 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1380,7 +1380,32 @@ EOF test_i18ncmp expect output ' -test_expect_success '.gitmodules ignore=all suppresses submodule summary' ' +test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' ' + cat > expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD ..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git checkout -- ..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add ..." to include in what will be committed) + + .gitmodules + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF git config --add -f .gitmodules submodule.subname.ignore all && git config --add -f .gitmodules submodule.subname.path sm && git status > output && @@ -1388,7 +1413,7 @@ test_expect_success '.gitmodules ignore=all suppresses submodule summary' ' git config -f .gitmodules --remove-section submodule.subname ' -test_expect_success '.git/config ignore=all suppresses submodule summary' ' +test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' ' git config --add -f .gitmodules submodule.subname.ignore none && git config --add -f .gitmodules submodule.subname.path sm && git config --add submodule.subname.ignore all && @@ -1461,4 +1486,49 @@ test_expect_success 'Restore default test environment' ' git config --unset status.showUntrackedFiles ' +test_expect_success 'git commit will commit a staged but ignored submodule' ' + git config --add -f .gitmodules submodule.subname.ignore all && + git config --add -f .gitmodules submodule.subname.path sm && + git config --add submodule.subname.ignore all && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep "^M. sm" output && + GIT_EDITOR="echo hello >>\"\$1\"" && + export GIT_EDITOR && + git commit -uno && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep ! "^M. sm" output +' + +test_expect_success 'git commit --dry-run will show a staged but ignored submodule' ' + git reset HEAD^ && + git add sm && + cat >expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD ..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git checkout -- ..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files not listed (use -u option to show untracked files) +EOF + git commit -uno --dry-run >output && + test_i18ncmp expect output && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep "^M. sm" output +' + +test_expect_failure 'git commit -m will commit a staged but ignored submodule' ' + git commit -uno -m message && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep ! "^M. sm" output && + git config --remove-section submodule.subname && + git config -f .gitmodules --remove-section submodule.subname +' + test_done -- cgit v1.2.1 From c215d3d2826c882feb819e5743287ec74d9ff693 Mon Sep 17 00:00:00 2001 From: Jens Lehmann Date: Sat, 5 Apr 2014 18:59:36 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- t/t7508-status.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7508-status.sh') diff --git a/t/t7508-status.sh b/t/t7508-status.sh index e6483fcd42..d48006960e 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1523,7 +1523,7 @@ EOF test_i18ngrep "^M. sm" output ' -test_expect_failure 'git commit -m will commit a staged but ignored submodule' ' +test_expect_success 'git commit -m will commit a staged but ignored submodule' ' git commit -uno -m message && git status -s --ignore-submodules=dirty >output && test_i18ngrep ! "^M. sm" output && -- cgit v1.2.1