t7502: handle systems where auto-identity is broken

Test t7502.21 checks whether we write the committer name into COMMIT_EDITMSG when it has been automatically determined. However, not all systems can produce valid automatic identities. Prior to f20f387 (commit: check committer identity more strictly), this test worked even when we did not have a valid automatic identity, since it did not run the strict test until after we had generated the template. That commit tightened the check to fail early (since we would fail later, anyway), meaning that systems without a valid GECOS name or hostname would fail the test. We cannot just work around this, because it depends on configuration outside the control of the test script. Therefore we introduce a new test_prerequisite to run this test only on systems where automatic ident works at all. As a result, we can drop the confusing test_must_fail bit from the test. The intent was that by giving "git commit" invalid input (namely, nothing to commit), that it would stop at a predictable point, whether we had a valid identity or not, from which we could view the contents of COMMIT_EDITMSG. Since that assumption no longer holds, and we can only run the test when we have a valid identity, there is no reason not to let commit run to completion. That lets us be more robust to other unforeseen failures. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 26, 2012 at 16:32 UTC 1d7dc26498b5d7b7879d579f40be63210c50400c
1 file changed +10 -3
t/t7502-commit.sh
+10 -3
@@ -243,14 +243,21 @@ test_expect_success 'message shows author when it is not equal to committer' '
243 .git/COMMIT_EDITMSG
244 '
245
246 -test_expect_success 'message shows committer when it is automatic' '
246 +test_expect_success 'setup auto-ident prerequisite' '
247 + if (sane_unset GIT_COMMITTER_EMAIL &&
248 + sane_unset GIT_COMMITTER_NAME &&
249 + git var GIT_COMMITTER_IDENT); then
250 + test_set_prereq AUTOIDENT
251 + fi
252 +'
253 +
254 +test_expect_success AUTOIDENT 'message shows committer when it is automatic' '
255
256 echo >>negative &&
257 (
258 sane_unset GIT_COMMITTER_EMAIL &&
259 sane_unset GIT_COMMITTER_NAME &&
252 - # must fail because there is no change
253 - test_must_fail git commit -e -m "sample"
260 + git commit -e -m "sample" -a
261 ) &&
262 # the ident is calculated from the system, so we cannot
263 # check the actual value, only that it is there