diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/branch.c | 2 | ||||
-rw-r--r-- | src/repository.c | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/branch.c b/src/branch.c index 62c4adbf4..c6173caca 100644 --- a/src/branch.c +++ b/src/branch.c @@ -317,7 +317,7 @@ int git_branch_is_head( error = git_repository_head(&head, git_reference_owner(branch)); - if (error == GIT_EORPHANEDHEAD) + if (error == GIT_EORPHANEDHEAD || error == GIT_ENOTFOUND) return false; if (error < 0) diff --git a/src/repository.c b/src/repository.c index fbae8935b..101497c4d 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1207,9 +1207,19 @@ int git_repository_head_detached(git_repository *repo) int git_repository_head(git_reference **head_out, git_repository *repo) { + git_reference *head; int error; - error = git_reference_lookup_resolved(head_out, repo, GIT_HEAD_FILE, -1); + if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0) + return error; + + if (git_reference_type(head) == GIT_REF_OID) { + *head_out = head; + return 0; + } + + error = git_reference_lookup_resolved(head_out, repo, git_reference_target(head), -1); + git_reference_free(head); return error == GIT_ENOTFOUND ? GIT_EORPHANEDHEAD : error; } |