From: Siddharth Shrimali Date: Tue, 21 Apr 2026 05:33:32 +0000 (+0530) Subject: t7004: drop hardcoded tag count for state verification X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=7002d6cd16047c0ed0b6befc22b5a7d54d4d6fde;p=thirdparty%2Fgit.git t7004: drop hardcoded tag count for state verification The test 'trying to create a tag with a non-valid name should fail', checked that exactly one tag existed in the repository before and after attempting to create invalid tags. As pointed out by Junio, this makes the test brittle by relying on a specific global tag count. If future tests are added or removed before this test, the expected state changes and this test would break for completely unrelated reasons. Modernize the test by taking a snapshot of the existing tags before the failure attempts and comparing it to a snapshot taken after. This provides a "belt-and-suspenders" approach: we verify that 'git tag' both exits with the expected error code and leaves the repository state untouched, without being brittle to the specific number of tags present. This replaces the hardcoded 'test_line_count = 1' checks with 'test_cmp' to ensure the tag list remains identical. Suggested-by: Junio C Hamano Signed-off-by: Siddharth Shrimali Signed-off-by: Junio C Hamano --- diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index faf7d97fc4..77a7a9777d 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -191,15 +191,14 @@ test_expect_success 'trying to create a tag with the name of one existing should ' test_expect_success 'trying to create a tag with a non-valid name should fail' ' - git tag -l >actual && - test_line_count = 1 actual && + git tag -l >tags-before && test_must_fail git tag "" && test_must_fail git tag .othertag && test_must_fail git tag "other tag" && test_must_fail git tag "othertag^" && test_must_fail git tag "other~tag" && - git tag -l >actual && - test_line_count = 1 actual + git tag -l >tags-after && + test_cmp tags-before tags-after ' test_expect_success 'creating a tag using HEAD directly should succeed' '