From 4218183631faa48f97e76a23e928d1a98983be46 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Thu, 29 Aug 2013 10:27:01 -0700 Subject: [PATCH] Treat detached HEAD as non-empty repo This simplifies the git_repository_is_empty a bit so that a detached HEAD is just taken to mean the repo is not empty, since a newly initialized repo will not have a detached HEAD. --- src/repository.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/repository.c b/src/repository.c index 80904d5fa..eae22ce51 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1495,26 +1495,20 @@ static int repo_contains_no_reference(git_repository *repo) int git_repository_is_empty(git_repository *repo) { git_reference *head = NULL; - int error; + int is_empty = 0; if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0) return -1; - if (git_reference_type(head) != GIT_REF_SYMBOLIC) { - error = -1; - goto cleanup; - } + if (git_reference_type(head) == GIT_REF_SYMBOLIC) + is_empty = + (strcmp(git_reference_symbolic_target(head), + GIT_REFS_HEADS_DIR "master") == 0) && + repo_contains_no_reference(repo); - if (!(error = (strcmp( - git_reference_symbolic_target(head), - GIT_REFS_HEADS_DIR "master") == 0))) - goto cleanup; - - error = repo_contains_no_reference(repo); - -cleanup: git_reference_free(head); - return error < 0 ? -1 : error; + + return is_empty; } const char *git_repository_path(git_repository *repo)