aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-10-13 14:18:28 -0700
committerJunio C Hamano <gitster@pobox.com>2023-10-13 14:18:28 -0700
commit09dcbb486d964b59222136dd1668023098658eda (patch)
tree55dcbe81f5b84e32861d8391a1ca08c64a264af5
parentMerge branch 'js/submodule-fix-misuse-of-path-and-name' (diff)
parentdiff: fix --merge-base with annotated tags (diff)
downloadgit-09dcbb486d964b59222136dd1668023098658eda.tar.gz
git-09dcbb486d964b59222136dd1668023098658eda.zip
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
-rw-r--r--diff-lib.c2
-rwxr-xr-xt/t4068-diff-symmetric-merge-base.sh13
2 files changed, 10 insertions, 5 deletions
diff --git a/diff-lib.c b/diff-lib.c
index 5848e4f9ca..0e9ec4f68a 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -571,8 +571,6 @@ void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb)
struct object *obj = revs->pending.objects[i].item;
if (obj->flags)
die(_("--merge-base does not work with ranges"));
- if (obj->type != OBJ_COMMIT)
- die(_("--merge-base only works with commits"));
}
/*
diff --git a/t/t4068-diff-symmetric-merge-base.sh b/t/t4068-diff-symmetric-merge-base.sh
index 2d650d8f10..541642650f 100755
--- a/t/t4068-diff-symmetric-merge-base.sh
+++ b/t/t4068-diff-symmetric-merge-base.sh
@@ -34,7 +34,7 @@ test_expect_success setup '
echo c >c &&
git add c &&
git commit -m C &&
- git tag commit-C &&
+ git tag -m commit-C commit-C &&
git merge -m D main &&
git tag commit-D &&
git checkout main &&
@@ -109,6 +109,13 @@ do
test_cmp expect actual
'
+ test_expect_success "$cmd --merge-base with annotated tag" '
+ git checkout main &&
+ git $cmd commit-C >expect &&
+ git $cmd --merge-base commit-C >actual &&
+ test_cmp expect actual
+ '
+
test_expect_success "$cmd --merge-base with one commit and unstaged changes" '
git checkout main &&
test_when_finished git reset --hard &&
@@ -143,7 +150,7 @@ do
test_expect_success "$cmd --merge-base with non-commit" '
git checkout main &&
test_must_fail git $cmd --merge-base main^{tree} 2>err &&
- test_i18ngrep "fatal: --merge-base only works with commits" err
+ test_i18ngrep "is a tree, not a commit" err
'
test_expect_success "$cmd --merge-base with no merge bases and one commit" '
@@ -169,7 +176,7 @@ do
test_expect_success "$cmd --merge-base commit and non-commit" '
test_must_fail git $cmd --merge-base br2 main^{tree} 2>err &&
- test_i18ngrep "fatal: --merge-base only works with commits" err
+ test_i18ngrep "is a tree, not a commit" err
'
test_expect_success "$cmd --merge-base with no merge bases and two commits" '