diff options
author | Vicent Marti <tanoku@gmail.com> | 2011-04-08 12:42:18 -0700 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-04-08 12:42:18 -0700 |
commit | 41233c40c0e9cb8556a8ba131aa97a0ffbe46cb1 (patch) | |
tree | 4cc53045010f488f675b9a2bb99b6f55f7893231 /src | |
parent | cef75d743006401121cfe9a9da63933cfc7ecec1 (diff) | |
download | libgit2-41233c40c0e9cb8556a8ba131aa97a0ffbe46cb1.tar.gz |
Add new method `git_repository_is_empty`
Diffstat (limited to 'src')
-rw-r--r-- | src/repository.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/repository.c b/src/repository.c index abbbd126a..471c02444 100644 --- a/src/repository.c +++ b/src/repository.c @@ -473,3 +473,18 @@ cleanup: return error; } +int git_repository_is_empty(git_repository *repo) +{ + git_reference *head, *branch; + int error; + + error = git_reference_lookup(&head, repo, "HEAD"); + if (error < GIT_SUCCESS) + return error; + + if (git_reference_type(head) != GIT_REF_SYMBOLIC) + return GIT_EOBJCORRUPTED; + + return git_reference_resolve(&branch, head) == GIT_SUCCESS ? 0 : 1; +} + |