Skip to content

Commit 09dcbb4

Browse files
committed
Merge branch 'ar/diff-index-merge-base-fix'
"git diff --merge-base X other args..." insisted that X must be a commit and errored out when given an annotated tag that peels to a commit, but we only need it to be a committish. This has been corrected. * ar/diff-index-merge-base-fix: diff: fix --merge-base with annotated tags
2 parents b32f5b6 + 4adceb5 commit 09dcbb4

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
@@ -571,8 +571,6 @@ void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb)
571571
struct object *obj = revs->pending.objects[i].item;
572572
if (obj->flags)
573573
die(_("--merge-base does not work with ranges"));
574-
if (obj->type != OBJ_COMMIT)
575-
die(_("--merge-base only works with commits"));
576574
}
577575

578576
/*

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)