Skip to content

Commit 3803a3a

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d4f231 commit 3803a3a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

t/t4208-log-magic-pathspec.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@ test_expect_success '"git log :/a -- " should not be ambiguous' '
3131
test_expect_success '"git log :/detached -- " should find a commit only in HEAD' '
3232
test_when_finished "git checkout main" &&
3333
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 &&
4136
git log :/detached --
4237
'
4338

t/test-lib-functions.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ test_commit () {
202202
author= &&
203203
signoff= &&
204204
indir= &&
205+
no_tag= &&
205206
while test $# != 0
206207
do
207208
case "$1" in
@@ -222,6 +223,9 @@ test_commit () {
222223
indir="$2"
223224
shift
224225
;;
226+
--no-tag)
227+
no_tag=yes
228+
;;
225229
*)
226230
break
227231
;;
@@ -244,7 +248,10 @@ test_commit () {
244248
git ${indir:+ -C "$indir"} commit \
245249
${author:+ --author "$author"} \
246250
$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
248255
}
249256

250257
# Call test_merge with the arguments "<message> <commit>", where <commit>

0 commit comments

Comments
 (0)