Add git_repository_is_bare() accessor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/include/git2/repository.h b/include/git2/repository.h
index c47fcfc..23f992f 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -212,6 +212,14 @@ GIT_EXTERN(const char *) git_repository_path(git_repository *repo);
*/
GIT_EXTERN(const char *) git_repository_workdir(git_repository *repo);
+/**
+ * Check if a repository is bare
+ *
+ * @param repo Repo to test
+ * @return 1 if the repository is empty, 0 otherwise.
+ */
+GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
+
/** @} */
GIT_END_DECL
#endif
diff --git a/src/repository.c b/src/repository.c
index 468c888..2054999 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -509,3 +509,9 @@ const char *git_repository_workdir(git_repository *repo)
assert(repo);
return repo->path_workdir;
}
+
+int git_repository_is_bare(git_repository *repo)
+{
+ assert(repo);
+ return repo->is_bare;
+}
diff --git a/tests/t12-repo.c b/tests/t12-repo.c
index 70dba42..4e51f1b 100644
--- a/tests/t12-repo.c
+++ b/tests/t12-repo.c
@@ -126,7 +126,14 @@ static int ensure_repository_init(
if (repo->path_index != NULL || expected_path_index != NULL) {
if (git__suffixcmp(repo->path_index, expected_path_index) != 0)
goto cleanup;
- }
+
+ if (git_repository_is_bare(repo) == 1)
+ goto cleanup;
+ } else if (git_repository_is_bare(repo) == 0)
+ goto cleanup;
+
+ if (git_repository_is_empty(repo) == 0)
+ goto cleanup;
git_repository_free(repo);
rmdir_recurs(working_directory);