Skip to content

Commit 7a3e381

Browse files
committed
test-reach: test get_merge_bases_many
The get_merge_bases_many method returns a list of merge bases for a single commit (A) against a list of commits (X). Some care is needed in constructing the expected behavior because the result is not the expected merge-base for an octopus merge with those parents but instead the set of maximal commits that are reachable from A and at least one of the commits in X. Add get_merge_bases_many to 'test-tool reach' and create a test that demonstrates that this output returns multiple results. Specifically, we select a list of three commits such that we output two commits that are reachable from one of the first two, respectively, and none are reachable from the third. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 074a9e0 commit 7a3e381

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

t/helper/test-reach.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ int cmd__reach(int ac, const char **av)
1010
struct object_id oid_A, oid_B;
1111
struct commit *A, *B;
1212
struct commit_list *X;
13+
struct commit **X_array;
14+
int X_nr, X_alloc;
1315
struct strbuf buf = STRBUF_INIT;
1416
struct repository *r = the_repository;
1517

@@ -20,6 +22,9 @@ int cmd__reach(int ac, const char **av)
2022

2123
A = B = NULL;
2224
X = NULL;
25+
X_nr = 0;
26+
X_alloc = 16;
27+
ALLOC_ARRAY(X_array, X_alloc);
2328

2429
while (strbuf_getline(&buf, stdin) != EOF) {
2530
struct object_id oid;
@@ -57,6 +62,8 @@ int cmd__reach(int ac, const char **av)
5762

5863
case 'X':
5964
commit_list_insert(c, &X);
65+
ALLOC_GROW(X_array, X_nr + 1, X_alloc);
66+
X_array[X_nr++] = c;
6067
break;
6168

6269
default:
@@ -71,6 +78,14 @@ int cmd__reach(int ac, const char **av)
7178
printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B));
7279
else if (!strcmp(av[1], "is_descendant_of"))
7380
printf("%s(A,X):%d\n", av[1], is_descendant_of(A, X));
81+
else if (!strcmp(av[1], "get_merge_bases_many")) {
82+
struct commit_list *list = get_merge_bases_many(A, X_nr, X_array);
83+
printf("%s(A,X):\n", av[1]);
84+
while (list) {
85+
printf("%s\n", oid_to_hex(&list->item->object.oid));
86+
list = list->next;
87+
}
88+
}
7489

7590
exit(0);
7691
}

t/t6600-test-reach.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,19 @@ test_expect_success 'is_descendant_of:miss' '
123123
test_three_modes is_descendant_of
124124
'
125125

126+
test_expect_success 'get_merge_bases_many' '
127+
cat >input <<-\EOF &&
128+
A:commit-5-7
129+
X:commit-4-8
130+
X:commit-6-6
131+
X:commit-8-3
132+
EOF
133+
{
134+
printf "get_merge_bases_many(A,X):\n" &&
135+
git rev-parse commit-5-6 &&
136+
git rev-parse commit-4-7
137+
} >expect &&
138+
test_three_modes get_merge_bases_many
139+
'
140+
126141
test_done

0 commit comments

Comments
 (0)