Skip to content

Commit 4adceb5

Browse files
alyssaisgitster
authored andcommitted
diff: fix --merge-base with annotated tags
Checking early for OBJ_COMMIT excludes other objects that can be resolved to commits, like annotated tags. If we remove it, annotated tags will be resolved and handled just fine by lookup_commit_reference(), and if we are given something that can't be resolved to a commit, we'll still get a useful error message, e.g.: > error: object 21ab162211ac3ef13c37603ca88b27e9c7e0d40b is a tree, not a commit > fatal: no merge base found Signed-off-by: Alyssa Ross <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 43c8a30 commit 4adceb5

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

diff-lib.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,6 @@ void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb)
572572
struct object *obj = revs->pending.objects[i].item;
573573
if (obj->flags)
574574
die(_("--merge-base does not work with ranges"));
575-
if (obj->type != OBJ_COMMIT)
576-
die(_("--merge-base only works with commits"));
577575
}
578576

579577
/*

t/t4068-diff-symmetric-merge-base.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test_expect_success setup '
3434
echo c >c &&
3535
git add c &&
3636
git commit -m C &&
37-
git tag commit-C &&
37+
git tag -m commit-C commit-C &&
3838
git merge -m D main &&
3939
git tag commit-D &&
4040
git checkout main &&
@@ -109,6 +109,13 @@ do
109109
test_cmp expect actual
110110
'
111111

112+
test_expect_success "$cmd --merge-base with annotated tag" '
113+
git checkout main &&
114+
git $cmd commit-C >expect &&
115+
git $cmd --merge-base commit-C >actual &&
116+
test_cmp expect actual
117+
'
118+
112119
test_expect_success "$cmd --merge-base with one commit and unstaged changes" '
113120
git checkout main &&
114121
test_when_finished git reset --hard &&
@@ -143,7 +150,7 @@ do
143150
test_expect_success "$cmd --merge-base with non-commit" '
144151
git checkout main &&
145152
test_must_fail git $cmd --merge-base main^{tree} 2>err &&
146-
test_i18ngrep "fatal: --merge-base only works with commits" err
153+
test_i18ngrep "is a tree, not a commit" err
147154
'
148155

149156
test_expect_success "$cmd --merge-base with no merge bases and one commit" '
@@ -169,7 +176,7 @@ do
169176

170177
test_expect_success "$cmd --merge-base commit and non-commit" '
171178
test_must_fail git $cmd --merge-base br2 main^{tree} 2>err &&
172-
test_i18ngrep "fatal: --merge-base only works with commits" err
179+
test_i18ngrep "is a tree, not a commit" err
173180
'
174181

175182
test_expect_success "$cmd --merge-base with no merge bases and two commits" '

0 commit comments

Comments
 (0)