t7004: dynamically grab expected state in tests

The tests for 'Multiple -l or --list options' and 'trying to delete tags without params', hardcodes that exactly one or two specific tags ('myhead', 'mytag') exist in the repository. If other tests are added, modified, or removed earlier in the script, this expected global state will change, resulting in these tests to fail for completely unrelated reasons. Instead of hardcoding the expected tags, dynamically grab the state of the repository before running the commands under test ('git tag -l' and 'git tag -d'), and verify that the output matches or remains unchanged afterward. This keeps the tests independent from the script's overall state. Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Siddharth Shrimali committed Apr 21, 2026 at 11:03 UTC e3253255d3e1c007e80742c304ddde9421dca9ca
1 file changed +2 -9
t/t7004-tag.sh
+2 -9
@@ -145,9 +145,7 @@ test_expect_success 'listing all tags if one exists should succeed' '
145 '
146
147 test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
148 - cat >expect <<-\EOF &&
149 - mytag
150 - EOF
148 + git tag -l >expect &&
149 git tag -l -l >actual &&
150 test_cmp expect actual &&
151 git tag --list --list >actual &&
@@ -226,12 +224,7 @@ test_expect_success 'trying to delete an unknown tag should fail' '
224 '
225
226 test_expect_success 'trying to delete tags without params should succeed and do nothing' '
229 - cat >expect <<-\EOF &&
230 - myhead
231 - mytag
232 - EOF
233 - git tag -l >actual &&
234 - test_cmp expect actual &&
227 + git tag -l >expect &&
228 git tag -d &&
229 git tag -l >actual &&
230 test_cmp expect actual