t: add --no-tag option to test_commit

One of the conveniences that test_commit offers is making a tag for each commit. This makes it easy to refer to the commits in subsequent commands. But it can also be a pain if you care about reachability, because those tags keep the commits reachable even if they are rewound from the branch they're made on. The alternative is that scripts have to call test_tick, git-add, and git-commit themselves. Let's add a --no-tag option to give them the one-liner convenience of using test_commit. This is in preparation for the next patch, which will add some more calls. But I cleaned up an existing site to show off the feature. There are probably more cleanups possible. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 9, 2021 at 05:52 UTC 3803a3a0993045605d7f3db363188ce377e917c8
2 files changed +10 -8
t/t4208-log-magic-pathspec.sh
+2 -7
@@ -31,13 +31,8 @@ test_expect_success '"git log :/a -- " should not be ambiguous' '
31 test_expect_success '"git log :/detached -- " should find a commit only in HEAD' '
32 test_when_finished "git checkout main" &&
33 git checkout --detach &&
34 - # Must manually call `test_tick` instead of using `test_commit`,
35 - # because the latter additionally creates a tag, which would make
36 - # the commit reachable not only via HEAD.
37 - test_tick &&
38 - git commit --allow-empty -m detached &&
39 - test_tick &&
40 - git commit --allow-empty -m something-else &&
34 + test_commit --no-tag detached &&
35 + test_commit --no-tag something-else &&
36 git log :/detached --
37 '
38
t/test-lib-functions.sh
+8 -1
@@ -202,6 +202,7 @@ test_commit () {
202 author= &&
203 signoff= &&
204 indir= &&
205 + no_tag= &&
206 while test $# != 0
207 do
208 case "$1" in
@@ -222,6 +223,9 @@ test_commit () {
223 indir="$2"
224 shift
225 ;;
226 + --no-tag)
227 + no_tag=yes
228 + ;;
229 *)
230 break
231 ;;
@@ -244,7 +248,10 @@ test_commit () {
248 git ${indir:+ -C "$indir"} commit \
249 ${author:+ --author "$author"} \
250 $signoff -m "$1" &&
247 - git ${indir:+ -C "$indir"} tag "${4:-$1}"
251 + if test -z "$no_tag"
252 + then
253 + git ${indir:+ -C "$indir"} tag "${4:-$1}"
254 + fi
255 }
256
257 # Call test_merge with the arguments "<message> <commit>", where <commit>