Commit 522df1cf1d83e169fdfd09843cb4795883c82288

Carlos Martín Nieto 2015-03-11T03:03:54

Merge pull request #2970 from ethomson/inmemory_bare "In-memory" repos are bare by default

diff --git a/src/repository.c b/src/repository.c
index e9d74b7..0cbdf08 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -171,7 +171,13 @@ static git_repository *repository_alloc(void)
 
 int git_repository_new(git_repository **out)
 {
-	*out = repository_alloc();
+	git_repository *repo;
+
+	*out = repo = repository_alloc();
+	GITERR_CHECK_ALLOC(repo);
+
+	repo->is_bare = 1;
+
 	return 0;
 }
 
diff --git a/tests/repo/new.c b/tests/repo/new.c
new file mode 100644
index 0000000..d77e903
--- /dev/null
+++ b/tests/repo/new.c
@@ -0,0 +1,27 @@
+#include "clar_libgit2.h"
+#include "git2/sys/repository.h"
+
+void test_repo_new__has_nothing(void)
+{
+	git_repository *repo;
+
+	cl_git_pass(git_repository_new(&repo));
+	cl_assert_equal_b(true, git_repository_is_bare(repo));
+	cl_assert_equal_p(NULL, git_repository_path(repo));
+	cl_assert_equal_p(NULL, git_repository_workdir(repo));
+	git_repository_free(repo);
+}
+
+void test_repo_new__is_bare_until_workdir_set(void)
+{
+	git_repository *repo;
+
+	cl_git_pass(git_repository_new(&repo));
+	cl_assert_equal_b(true, git_repository_is_bare(repo));
+
+	cl_git_pass(git_repository_set_workdir(repo, clar_sandbox_path(), 0));
+	cl_assert_equal_b(false, git_repository_is_bare(repo));
+
+	git_repository_free(repo);
+}
+