]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t6600: add tests for duplicate tips in tips_reachable_from_bases()
authorKristofer Karlsson <krka@spotify.com>
Sat, 16 May 2026 15:59:41 +0000 (15:59 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 May 2026 05:59:16 +0000 (14:59 +0900)
When multiple refs point to the same commit, the reachability check
must handle them correctly.  Add three tests:

 - duplicate tips, all reachable
 - duplicate tips, none reachable
 - duplicate tips at the minimum generation (exercises the
   early-termination advancement logic)

Suggested-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Kristofer Karlsson <krka@spotify.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t6600-test-reach.sh

index dc0421ed2f3726769a337a8f47be1e69b850983c..9486002866fb13e7aa27db92f4dd9a3362ce380b 100755 (executable)
@@ -612,6 +612,51 @@ test_expect_success 'for-each-ref merged:none' '
                --format="%(refname)" --stdin
 '
 
+test_expect_success 'for-each-ref merged:duplicate, all reachable' '
+       git branch dup-a commit-3-3 &&
+       git branch dup-b commit-3-3 &&
+       cat >input <<-\EOF &&
+       refs/heads/commit-1-1
+       refs/heads/dup-a
+       refs/heads/dup-b
+       EOF
+       cat >expect <<-\EOF &&
+       refs/heads/commit-1-1
+       refs/heads/dup-a
+       refs/heads/dup-b
+       EOF
+       run_all_modes git for-each-ref --merged=commit-5-5 \
+               --format="%(refname)" --stdin
+'
+
+test_expect_success 'for-each-ref merged:duplicate, none reachable' '
+       cat >input <<-\EOF &&
+       refs/heads/dup-a
+       refs/heads/dup-b
+       refs/heads/commit-9-9
+       EOF
+       >expect &&
+       run_all_modes git for-each-ref --merged=commit-2-2 \
+               --format="%(refname)" --stdin
+'
+
+test_expect_success 'for-each-ref merged:duplicate at min generation' '
+       git branch dup-c commit-1-1 &&
+       git branch dup-d commit-1-1 &&
+       cat >input <<-\EOF &&
+       refs/heads/dup-c
+       refs/heads/dup-d
+       refs/heads/commit-5-5
+       EOF
+       cat >expect <<-\EOF &&
+       refs/heads/commit-5-5
+       refs/heads/dup-c
+       refs/heads/dup-d
+       EOF
+       run_all_modes git for-each-ref --merged=commit-5-5 \
+               --format="%(refname)" --stdin
+'
+
 # For get_branch_base_for_tip, we only care about
 # first-parent history. Here is the test graph with
 # second parents removed: