summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-11-12 00:14:51 +0100
committernulltoken <emeric.fermas@gmail.com>2012-11-12 00:14:51 +0100
commitb1a3a70ed1ca45bb155ec4c10b40a047d27614f3 (patch)
treec6a6065e66ff80c7eb5665e2dd7bfe467f3b9655 /src
parentef8871515bcb8af8d690609c086718bcaecbb5c6 (diff)
downloadlibgit2-b1a3a70ed1ca45bb155ec4c10b40a047d27614f3.tar.gz
repository: Refine repository_head() error report
Diffstat (limited to 'src')
-rw-r--r--src/branch.c2
-rw-r--r--src/repository.c12
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;
}