diff options
author | Vicent Martà <vicent@github.com> | 2012-11-12 14:12:41 -0800 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2012-11-12 14:12:41 -0800 |
commit | 3b44ced096bbb4903dcf71c63675c99753d2343d (patch) | |
tree | c6a6065e66ff80c7eb5665e2dd7bfe467f3b9655 /src | |
parent | e090a5681beeef522de34c8ca5d01997e1b76505 (diff) | |
parent | b1a3a70ed1ca45bb155ec4c10b40a047d27614f3 (diff) | |
download | libgit2-3b44ced096bbb4903dcf71c63675c99753d2343d.tar.gz |
Merge pull request #1061 from nulltoken/topic/explicit-head-errors
repository: Refine repository_head() error report
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; } |