diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-07-13 10:10:02 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-08-03 11:53:20 +0100 |
commit | 84d2a0353d3934e88b08095e0100a408c4b0a42e (patch) | |
tree | ff052d41c9def20806d65afb4cf3f4b1a1fc3f22 | |
parent | 4cc3b2cb9aed4a5d2b4e2740ffc6bbd69f0634cc (diff) | |
download | libgit2-84d2a0353d3934e88b08095e0100a408c4b0a42e.tar.gz |
repo: teach isempty about default branch config
The git_repository_isempty function now respects the init.defaultbranch
setting (instead of hardcoding "master") to understand if a repository
is empty or not.
-rw-r--r-- | src/repository.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/repository.c b/src/repository.c index e4a374d12..a1186832b 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2391,20 +2391,22 @@ done: int git_repository_is_empty(git_repository *repo) { git_reference *head = NULL; - int is_empty = 0; + git_buf initialbranch = GIT_BUF_INIT; + int result = 0; - if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0) - return -1; + if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 || + (result = git_repository_initialbranch(&initialbranch, repo)) < 0) + goto done; - if (git_reference_type(head) == GIT_REFERENCE_SYMBOLIC) - is_empty = - (strcmp(git_reference_symbolic_target(head), - GIT_REFS_HEADS_DIR "master") == 0) && - repo_contains_no_reference(repo); + result = (git_reference_type(head) == GIT_REFERENCE_SYMBOLIC && + strcmp(git_reference_symbolic_target(head), initialbranch.ptr) == 0 && + repo_contains_no_reference(repo)); +done: git_reference_free(head); + git_buf_dispose(&initialbranch); - return is_empty; + return result; } static const char *resolved_parent_path(const git_repository *repo, git_repository_item_t item, git_repository_item_t fallback) |