Skip to content

Commit c163461

Browse files
committed
revparse: comment reflog HEAD@{n} parsing
1 parent 0628e25 commit c163461

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/libgit2/revparse.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,16 @@ static int retrieve_revobject_from_reflog(git_object **out, git_reference **base
268268
int error = -1;
269269

270270
if (*base_ref == NULL) {
271-
if (position > 0 &&
272-
(!strcmp(identifier, "HEAD"))) {
273-
if ((error = git_reference_lookup(&ref, repo, "HEAD")) < 0)
274-
return error;
275-
} else if ((error = git_reference_dwim(&ref, repo, identifier)) < 0)
271+
/*
272+
* When HEAD@{n} is specified, do not use dwim, which would resolve the
273+
* reference (to the current branch that HEAD is pointing to).
274+
*/
275+
if (position > 0 && strcmp(identifier, GIT_HEAD_FILE) == 0)
276+
error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE);
277+
else
278+
error = git_reference_dwim(&ref, repo, identifier);
279+
280+
if (error < 0)
276281
return error;
277282
} else {
278283
ref = *base_ref;

0 commit comments

Comments
 (0)