summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-02-14 11:59:42 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2023-02-14 11:59:42 +0000
commitc1634611dde3feee874c0be545cbc1107caa2f29 (patch)
tree5ed64859502af1f451d56950f6869f5c1d353c65
parent0628e25d04bed2734091a8354aae7186f490037c (diff)
downloadlibgit2-c1634611dde3feee874c0be545cbc1107caa2f29.tar.gz
revparse: comment reflog HEAD@{n} parsing
-rw-r--r--src/libgit2/revparse.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/libgit2/revparse.c b/src/libgit2/revparse.c
index 255c566ca..780f1a0cb 100644
--- a/src/libgit2/revparse.c
+++ b/src/libgit2/revparse.c
@@ -268,11 +268,16 @@ static int retrieve_revobject_from_reflog(git_object **out, git_reference **base
int error = -1;
if (*base_ref == NULL) {
- 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)
+ /*
+ * When HEAD@{n} is specified, do not use dwim, which would resolve the
+ * reference (to the current branch that HEAD is pointing to).
+ */
+ if (position > 0 && strcmp(identifier, GIT_HEAD_FILE) == 0)
+ error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE);
+ else
+ error = git_reference_dwim(&ref, repo, identifier);
+
+ if (error < 0)
return error;
} else {
ref = *base_ref;