summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Strickroth <email@cs-ware.de>2022-08-19 21:16:21 +0200
committerEdward Thomson <ethomson@edwardthomson.com>2023-02-14 11:52:28 +0000
commit0628e25d04bed2734091a8354aae7186f490037c (patch)
treeb16b8cb2d693b9088508c99bd9d01d573daf8ec1
parentf02bcf721105d3dfb0a7d12dec2816b495451c45 (diff)
downloadlibgit2-0628e25d04bed2734091a8354aae7186f490037c.tar.gz
Fix parsing rev with reflog of HEAD (e.g., HEAD@{3})
Fixes issue #6156. Signed-off-by: Sven Strickroth <email@cs-ware.de>
-rw-r--r--src/libgit2/revparse.c6
-rw-r--r--tests/libgit2/refs/revparse.c3
2 files changed, 8 insertions, 1 deletions
diff --git a/src/libgit2/revparse.c b/src/libgit2/revparse.c
index 2ed282159..255c566ca 100644
--- a/src/libgit2/revparse.c
+++ b/src/libgit2/revparse.c
@@ -268,7 +268,11 @@ static int retrieve_revobject_from_reflog(git_object **out, git_reference **base
int error = -1;
if (*base_ref == NULL) {
- if ((error = git_reference_dwim(&ref, repo, identifier)) < 0)
+ if (position > 0 &&
+ (!strcmp(identifier, "HEAD"))) {
+ if ((error = git_reference_lookup(&ref, repo, "HEAD")) < 0)
+ return error;
+ } else if ((error = git_reference_dwim(&ref, repo, identifier)) < 0)
return error;
} else {
ref = *base_ref;
diff --git a/tests/libgit2/refs/revparse.c b/tests/libgit2/refs/revparse.c
index 02ffe005d..d2f464840 100644
--- a/tests/libgit2/refs/revparse.c
+++ b/tests/libgit2/refs/revparse.c
@@ -304,6 +304,9 @@ void test_refs_revparse__ordinal(void)
test_object("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("HEAD@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("HEAD@{4}", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
+
test_object("master@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
test_object("heads/master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");