]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t9350: properly count annotated tags
authorChristian Couder <christian.couder@gmail.com>
Mon, 13 Oct 2025 08:48:55 +0000 (10:48 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Oct 2025 15:51:41 +0000 (08:51 -0700)
In "t9350-fast-export.sh", these existing tests:

  - 'fast-export | fast-import when main is tagged'
  - 'cope with tagger-less tags'

are checking the number of annotated tags in the test repo by comparing
it with some hardcoded values.

This could be an issue if some new tests that have some prerequisites
add new annotated tags to the repo before these existing tests. When
the prerequisites would be satisfied, the number of annotated tags
would be different from when some prerequisites would not be satisfied.

As we are going to add new tests that add new annotated tags in a
following commit, let's properly count the number of annotated tag in
the repo by incrementing a counter each time a new annotated tag is
added, and then by comparing the number of annotated tags to the value
of the counter when checking the number of annotated tags.

This is a bit ugly, but it makes it explicit that some tests are
interdependent. Alternative solutions, like moving the new tests to
the end of the script, were considered, but were rejected because they
would instead hide the technical debt and could confuse developers in
the future.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t9350-fast-export.sh

index 8f85c69d62f17a4d72c112cfbe33bd2ac2037ba0..21ff26939c6885d9117402b9cfde05d2a4ee55af 100755 (executable)
@@ -35,6 +35,7 @@ test_expect_success 'setup' '
        git commit -m sitzt file2 &&
        test_tick &&
        git tag -a -m valentin muss &&
+       ANNOTATED_TAG_COUNT=1 &&
        git merge -s ours main
 
 '
@@ -229,7 +230,8 @@ EOF
 
 test_expect_success 'set up faked signed tag' '
 
-       git fast-import <signed-tag-import
+       git fast-import <signed-tag-import &&
+       ANNOTATED_TAG_COUNT=$((ANNOTATED_TAG_COUNT + 1))
 
 '
 
@@ -491,8 +493,9 @@ test_expect_success 'fast-export -C -C | fast-import' '
 test_expect_success 'fast-export | fast-import when main is tagged' '
 
        git tag -m msg last &&
+       ANNOTATED_TAG_COUNT=$((ANNOTATED_TAG_COUNT + 1)) &&
        git fast-export -C -C --signed-tags=strip --all > output &&
-       test $(grep -c "^tag " output) = 3
+       test $(grep -c "^tag " output) = $ANNOTATED_TAG_COUNT
 
 '
 
@@ -506,12 +509,13 @@ test_expect_success 'cope with tagger-less tags' '
 
        TAG=$(git hash-object --literally -t tag -w tag-content) &&
        git update-ref refs/tags/sonnenschein $TAG &&
+       ANNOTATED_TAG_COUNT=$((ANNOTATED_TAG_COUNT + 1)) &&
        git fast-export -C -C --signed-tags=strip --all > output &&
-       test $(grep -c "^tag " output) = 4 &&
+       test $(grep -c "^tag " output) = $ANNOTATED_TAG_COUNT &&
        ! grep "Unspecified Tagger" output &&
        git fast-export -C -C --signed-tags=strip --all \
                --fake-missing-tagger > output &&
-       test $(grep -c "^tag " output) = 4 &&
+       test $(grep -c "^tag " output) = $ANNOTATED_TAG_COUNT &&
        grep "Unspecified Tagger" output
 
 '