Blame tests/repo/init.c

Packit ae9e2a
#include "clar_libgit2.h"
Packit ae9e2a
#include "fileops.h"
Packit ae9e2a
#include "repository.h"
Packit ae9e2a
#include "config.h"
Packit ae9e2a
#include "path.h"
Packit ae9e2a
#include "config/config_helpers.h"
Packit ae9e2a
Packit ae9e2a
enum repo_mode {
Packit ae9e2a
	STANDARD_REPOSITORY = 0,
Packit ae9e2a
	BARE_REPOSITORY = 1
Packit ae9e2a
};
Packit ae9e2a
Packit ae9e2a
static git_repository *_repo = NULL;
Packit ae9e2a
static git_buf _global_path = GIT_BUF_INIT;
Packit ae9e2a
static git_buf _tmp_path = GIT_BUF_INIT;
Packit ae9e2a
static mode_t g_umask = 0;
Packit ae9e2a
Packit ae9e2a
void test_repo_init__initialize(void)
Packit ae9e2a
{
Packit ae9e2a
	_repo = NULL;
Packit ae9e2a
Packit ae9e2a
	/* load umask if not already loaded */
Packit ae9e2a
	if (!g_umask) {
Packit ae9e2a
		g_umask = p_umask(022);
Packit ae9e2a
		(void)p_umask(g_umask);
Packit ae9e2a
	}
Packit ae9e2a
Packit ae9e2a
    git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
Packit ae9e2a
		&_global_path);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__cleanup(void)
Packit ae9e2a
{
Packit ae9e2a
	git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
Packit ae9e2a
		_global_path.ptr);
Packit ae9e2a
	git_buf_free(&_global_path);
Packit ae9e2a
Packit ae9e2a
	if (_tmp_path.size > 0 && git_path_isdir(_tmp_path.ptr))
Packit ae9e2a
		git_futils_rmdir_r(_tmp_path.ptr, NULL, GIT_RMDIR_REMOVE_FILES);
Packit ae9e2a
	git_buf_free(&_tmp_path);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
static void cleanup_repository(void *path)
Packit ae9e2a
{
Packit ae9e2a
	git_repository_free(_repo);
Packit ae9e2a
	_repo = NULL;
Packit ae9e2a
Packit ae9e2a
	cl_fixture_cleanup((const char *)path);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
static void ensure_repository_init(
Packit ae9e2a
	const char *working_directory,
Packit ae9e2a
	int is_bare,
Packit ae9e2a
	const char *expected_path_repository,
Packit ae9e2a
	const char *expected_working_directory)
Packit ae9e2a
{
Packit ae9e2a
	const char *workdir;
Packit ae9e2a
Packit ae9e2a
	cl_assert(!git_path_isdir(working_directory));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, working_directory, is_bare));
Packit ae9e2a
Packit ae9e2a
	workdir = git_repository_workdir(_repo);
Packit ae9e2a
	if (workdir != NULL || expected_working_directory != NULL) {
Packit ae9e2a
		cl_assert(
Packit ae9e2a
			git__suffixcmp(workdir, expected_working_directory) == 0
Packit ae9e2a
		);
Packit ae9e2a
	}
Packit ae9e2a
Packit ae9e2a
	cl_assert(
Packit ae9e2a
		git__suffixcmp(git_repository_path(_repo), expected_path_repository) == 0
Packit ae9e2a
	);
Packit ae9e2a
Packit ae9e2a
	cl_assert(git_repository_is_bare(_repo) == is_bare);
Packit ae9e2a
Packit ae9e2a
#ifdef GIT_WIN32
Packit ae9e2a
	if (!is_bare) {
Packit ae9e2a
		DWORD fattrs = GetFileAttributes(git_repository_path(_repo));
Packit ae9e2a
		cl_assert((fattrs & FILE_ATTRIBUTE_HIDDEN) != 0);
Packit ae9e2a
	}
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
	cl_assert(git_repository_is_empty(_repo));
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__standard_repo(void)
Packit ae9e2a
{
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "testrepo");
Packit ae9e2a
	ensure_repository_init("testrepo/", 0, "testrepo/.git/", "testrepo/");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__standard_repo_noslash(void)
Packit ae9e2a
{
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "testrepo");
Packit ae9e2a
	ensure_repository_init("testrepo", 0, "testrepo/.git/", "testrepo/");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__bare_repo(void)
Packit ae9e2a
{
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "testrepo.git");
Packit ae9e2a
	ensure_repository_init("testrepo.git/", 1, "testrepo.git/", NULL);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__bare_repo_noslash(void)
Packit ae9e2a
{
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "testrepo.git");
Packit ae9e2a
	ensure_repository_init("testrepo.git", 1, "testrepo.git/", NULL);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__bare_repo_escaping_current_workdir(void)
Packit ae9e2a
{
Packit ae9e2a
	git_buf path_repository = GIT_BUF_INIT;
Packit ae9e2a
	git_buf path_current_workdir = GIT_BUF_INIT;
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&path_repository, git_buf_cstr(&path_current_workdir), "a/b/c"));
Packit ae9e2a
	cl_git_pass(git_futils_mkdir_r(git_buf_cstr(&path_repository), GIT_DIR_MODE));
Packit ae9e2a
Packit ae9e2a
	/* Change the current working directory */
Packit ae9e2a
	cl_git_pass(chdir(git_buf_cstr(&path_repository)));
Packit ae9e2a
Packit ae9e2a
	/* Initialize a bare repo with a relative path escaping out of the current working directory */
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, "../d/e.git", 1));
Packit ae9e2a
	cl_git_pass(git__suffixcmp(git_repository_path(_repo), "/a/b/d/e.git/"));
Packit ae9e2a
Packit ae9e2a
	git_repository_free(_repo);
Packit ae9e2a
Packit ae9e2a
	/* Open a bare repo with a relative path escaping out of the current working directory */
Packit ae9e2a
	cl_git_pass(git_repository_open(&_repo, "../d/e.git"));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(chdir(git_buf_cstr(&path_current_workdir)));
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&path_current_workdir);
Packit ae9e2a
	git_buf_free(&path_repository);
Packit ae9e2a
Packit ae9e2a
	cleanup_repository("a");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__reinit_bare_repo(void)
Packit ae9e2a
{
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "reinit.git");
Packit ae9e2a
Packit ae9e2a
	/* Initialize the repository */
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, "reinit.git", 1));
Packit ae9e2a
	git_repository_free(_repo);
Packit ae9e2a
Packit ae9e2a
	/* Reinitialize the repository */
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, "reinit.git", 1));
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__reinit_too_recent_bare_repo(void)
Packit ae9e2a
{
Packit ae9e2a
	git_config *config;
Packit ae9e2a
Packit ae9e2a
	/* Initialize the repository */
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, "reinit.git", 1));
Packit ae9e2a
	git_repository_config(&config, _repo);
Packit ae9e2a
Packit ae9e2a
	/*
Packit ae9e2a
	 * Hack the config of the repository to make it look like it has
Packit ae9e2a
	 * been created by a recenter version of git/libgit2
Packit ae9e2a
	 */
Packit ae9e2a
	cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 42));
Packit ae9e2a
Packit ae9e2a
	git_config_free(config);
Packit ae9e2a
	git_repository_free(_repo);
Packit ae9e2a
Packit ae9e2a
	/* Try to reinitialize the repository */
Packit ae9e2a
	cl_git_fail(git_repository_init(&_repo, "reinit.git", 1));
Packit ae9e2a
Packit ae9e2a
	cl_fixture_cleanup("reinit.git");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__additional_templates(void)
Packit ae9e2a
{
Packit ae9e2a
	git_buf path = GIT_BUF_INIT;
Packit ae9e2a
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "tester");
Packit ae9e2a
Packit ae9e2a
	ensure_repository_init("tester", 0, "tester/.git/", "tester/");
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(
Packit ae9e2a
		git_buf_joinpath(&path, git_repository_path(_repo), "description"));
Packit ae9e2a
	cl_assert(git_path_isfile(git_buf_cstr(&path)));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(
Packit ae9e2a
		git_buf_joinpath(&path, git_repository_path(_repo), "info/exclude"));
Packit ae9e2a
	cl_assert(git_path_isfile(git_buf_cstr(&path)));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(
Packit ae9e2a
		git_buf_joinpath(&path, git_repository_path(_repo), "hooks"));
Packit ae9e2a
	cl_assert(git_path_isdir(git_buf_cstr(&path)));
Packit ae9e2a
	/* won't confirm specific contents of hooks dir since it may vary */
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&path);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
static void assert_config_entry_on_init_bytype(
Packit ae9e2a
	const char *config_key, int expected_value, bool is_bare)
Packit ae9e2a
{
Packit ae9e2a
	git_config *config;
Packit ae9e2a
	int error, current_value;
Packit ae9e2a
	const char *repo_path = is_bare ?
Packit ae9e2a
		"config_entry/test.bare.git" : "config_entry/test.non.bare.git";
Packit ae9e2a
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "config_entry");
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, repo_path, is_bare));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_repository_config(&config, _repo));
Packit ae9e2a
	error = git_config_get_bool(&current_value, config, config_key);
Packit ae9e2a
	git_config_free(config);
Packit ae9e2a
Packit ae9e2a
	if (expected_value >= 0) {
Packit ae9e2a
		cl_assert_equal_i(0, error);
Packit ae9e2a
		cl_assert_equal_i(expected_value, current_value);
Packit ae9e2a
	} else {
Packit ae9e2a
		cl_assert_equal_i(expected_value, error);
Packit ae9e2a
	}
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
static void assert_config_entry_on_init(
Packit ae9e2a
	const char *config_key, int expected_value)
Packit ae9e2a
{
Packit ae9e2a
	assert_config_entry_on_init_bytype(config_key, expected_value, true);
Packit ae9e2a
	git_repository_free(_repo);
Packit ae9e2a
Packit ae9e2a
	assert_config_entry_on_init_bytype(config_key, expected_value, false);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__detect_filemode(void)
Packit ae9e2a
{
Packit ae9e2a
	assert_config_entry_on_init("core.filemode", cl_is_chmod_supported());
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__detect_ignorecase(void)
Packit ae9e2a
{
Packit ae9e2a
	struct stat st;
Packit ae9e2a
	bool found_without_match;
Packit ae9e2a
Packit ae9e2a
	cl_git_write2file("testCAPS", "whatever\n", 0, O_CREAT | O_WRONLY, 0666);
Packit ae9e2a
	found_without_match = (p_stat("Testcaps", &st) == 0);
Packit ae9e2a
	cl_must_pass(p_unlink("testCAPS"));
Packit ae9e2a
Packit ae9e2a
	assert_config_entry_on_init(
Packit ae9e2a
		"core.ignorecase", found_without_match ? true : GIT_ENOTFOUND);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__detect_precompose_unicode_required(void)
Packit ae9e2a
{
Packit ae9e2a
#ifdef GIT_USE_ICONV
Packit ae9e2a
	char *composed = "ḱṷṓn", *decomposed = "ḱṷṓn";
Packit ae9e2a
	struct stat st;
Packit ae9e2a
	bool found_with_nfd;
Packit ae9e2a
Packit ae9e2a
	cl_git_write2file(composed, "whatever\n", 0, O_CREAT | O_WRONLY, 0666);
Packit ae9e2a
	found_with_nfd = (p_stat(decomposed, &st) == 0);
Packit ae9e2a
	cl_must_pass(p_unlink(composed));
Packit ae9e2a
Packit ae9e2a
	assert_config_entry_on_init("core.precomposeunicode", found_with_nfd);
Packit ae9e2a
#else
Packit ae9e2a
	assert_config_entry_on_init("core.precomposeunicode", GIT_ENOTFOUND);
Packit ae9e2a
#endif
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__reinit_doesnot_overwrite_ignorecase(void)
Packit ae9e2a
{
Packit ae9e2a
	git_config *config;
Packit ae9e2a
	int current_value;
Packit ae9e2a
Packit ae9e2a
	/* Init a new repo */
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "not.overwrite.git");
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, "not.overwrite.git", 1));
Packit ae9e2a
Packit ae9e2a
	/* Change the "core.ignorecase" config value to something unlikely */
Packit ae9e2a
	git_repository_config(&config, _repo);
Packit ae9e2a
	git_config_set_int32(config, "core.ignorecase", 42);
Packit ae9e2a
	git_config_free(config);
Packit ae9e2a
	git_repository_free(_repo);
Packit ae9e2a
	_repo = NULL;
Packit ae9e2a
Packit ae9e2a
	/* Reinit the repository */
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, "not.overwrite.git", 1));
Packit ae9e2a
	git_repository_config(&config, _repo);
Packit ae9e2a
Packit ae9e2a
	/* Ensure the "core.ignorecase" config value hasn't been updated */
Packit ae9e2a
	cl_git_pass(git_config_get_int32(&current_value, config, "core.ignorecase"));
Packit ae9e2a
	cl_assert_equal_i(42, current_value);
Packit ae9e2a
Packit ae9e2a
	git_config_free(config);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__reinit_overwrites_filemode(void)
Packit ae9e2a
{
Packit ae9e2a
	int expected = cl_is_chmod_supported(), current_value;
Packit ae9e2a
Packit ae9e2a
	/* Init a new repo */
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "overwrite.git");
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1));
Packit ae9e2a
Packit ae9e2a
	/* Change the "core.filemode" config value to something unlikely */
Packit ae9e2a
	cl_repo_set_bool(_repo, "core.filemode", !expected);
Packit ae9e2a
Packit ae9e2a
	git_repository_free(_repo);
Packit ae9e2a
	_repo = NULL;
Packit ae9e2a
Packit ae9e2a
	/* Reinit the repository */
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1));
Packit ae9e2a
Packit ae9e2a
	/* Ensure the "core.filemode" config value has been reset */
Packit ae9e2a
	current_value = cl_repo_get_bool(_repo, "core.filemode");
Packit ae9e2a
	cl_assert_equal_i(expected, current_value);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__sets_logAllRefUpdates_according_to_type_of_repository(void)
Packit ae9e2a
{
Packit ae9e2a
	assert_config_entry_on_init_bytype("core.logallrefupdates", GIT_ENOTFOUND, true);
Packit ae9e2a
	git_repository_free(_repo);
Packit ae9e2a
	assert_config_entry_on_init_bytype("core.logallrefupdates", true, false);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__empty_template_path(void)
Packit ae9e2a
{
Packit ae9e2a
	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
Packit ae9e2a
	opts.template_path = "";
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_futils_mkdir("foo", 0755, 0));
Packit ae9e2a
	cl_git_pass(git_repository_init_ext(&_repo, "foo", &opts));
Packit ae9e2a
Packit ae9e2a
	cleanup_repository("foo");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__extended_0(void)
Packit ae9e2a
{
Packit ae9e2a
	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
Packit ae9e2a
Packit ae9e2a
	/* without MKDIR this should fail */
Packit ae9e2a
	cl_git_fail(git_repository_init_ext(&_repo, "extended", &opts));
Packit ae9e2a
Packit ae9e2a
	/* make the directory first, then it should succeed */
Packit ae9e2a
	cl_git_pass(git_futils_mkdir("extended", 0775, 0));
Packit ae9e2a
	cl_git_pass(git_repository_init_ext(&_repo, "extended", &opts));
Packit ae9e2a
Packit ae9e2a
	cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/extended/"));
Packit ae9e2a
	cl_assert(!git__suffixcmp(git_repository_path(_repo), "/extended/.git/"));
Packit ae9e2a
	cl_assert(!git_repository_is_bare(_repo));
Packit ae9e2a
	cl_assert(git_repository_is_empty(_repo));
Packit ae9e2a
Packit ae9e2a
	cleanup_repository("extended");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__extended_1(void)
Packit ae9e2a
{
Packit ae9e2a
	git_reference *ref;
Packit ae9e2a
	git_remote *remote;
Packit ae9e2a
	struct stat st;
Packit ae9e2a
	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
Packit ae9e2a
Packit ae9e2a
	opts.flags = GIT_REPOSITORY_INIT_MKPATH |
Packit ae9e2a
		GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
Packit ae9e2a
	opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP;
Packit ae9e2a
	opts.workdir_path = "../c_wd";
Packit ae9e2a
	opts.description = "Awesomest test repository evah";
Packit ae9e2a
	opts.initial_head = "development";
Packit ae9e2a
	opts.origin_url = "https://github.com/libgit2/libgit2.git";
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_repository_init_ext(&_repo, "root/b/c.git", &opts));
Packit ae9e2a
Packit ae9e2a
	cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/c_wd/"));
Packit ae9e2a
	cl_assert(!git__suffixcmp(git_repository_path(_repo), "/c.git/"));
Packit ae9e2a
	cl_assert(git_path_isfile("root/b/c_wd/.git"));
Packit ae9e2a
	cl_assert(!git_repository_is_bare(_repo));
Packit ae9e2a
	/* repo will not be counted as empty because we set head to "development" */
Packit ae9e2a
	cl_assert(!git_repository_is_empty(_repo));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_path_lstat(git_repository_path(_repo), &st);;
Packit ae9e2a
	cl_assert(S_ISDIR(st.st_mode));
Packit ae9e2a
	if (cl_is_chmod_supported())
Packit ae9e2a
		cl_assert((S_ISGID & st.st_mode) == S_ISGID);
Packit ae9e2a
	else
Packit ae9e2a
		cl_assert((S_ISGID & st.st_mode) == 0);
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_reference_lookup(&ref, _repo, "HEAD"));
Packit ae9e2a
	cl_assert(git_reference_type(ref) == GIT_REF_SYMBOLIC);
Packit ae9e2a
	cl_assert_equal_s("refs/heads/development", git_reference_symbolic_target(ref));
Packit ae9e2a
	git_reference_free(ref);
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_remote_lookup(&remote, _repo, "origin"));
Packit ae9e2a
	cl_assert_equal_s("origin", git_remote_name(remote));
Packit ae9e2a
	cl_assert_equal_s(opts.origin_url, git_remote_url(remote));
Packit ae9e2a
	git_remote_free(remote);
Packit ae9e2a
Packit ae9e2a
	git_repository_free(_repo);
Packit ae9e2a
	cl_fixture_cleanup("root");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__relative_gitdir(void)
Packit ae9e2a
{
Packit ae9e2a
	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
Packit ae9e2a
	git_buf dot_git_content = GIT_BUF_INIT;
Packit ae9e2a
Packit ae9e2a
	opts.workdir_path = "../c_wd";
Packit ae9e2a
	opts.flags =
Packit ae9e2a
		GIT_REPOSITORY_INIT_MKPATH |
Packit ae9e2a
		GIT_REPOSITORY_INIT_RELATIVE_GITLINK |
Packit ae9e2a
		GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
Packit ae9e2a
Packit ae9e2a
	/* make the directory first, then it should succeed */
Packit ae9e2a
	cl_git_pass(git_repository_init_ext(&_repo, "root/b/my_repository", &opts));
Packit ae9e2a
Packit ae9e2a
	cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "root/b/c_wd/"));
Packit ae9e2a
	cl_assert(!git__suffixcmp(git_repository_path(_repo), "root/b/my_repository/"));
Packit ae9e2a
	cl_assert(!git_repository_is_bare(_repo));
Packit ae9e2a
	cl_assert(git_repository_is_empty(_repo));
Packit ae9e2a
Packit ae9e2a
	/* Verify that the gitlink and worktree entries are relative */
Packit ae9e2a
Packit ae9e2a
	/* Verify worktree */
Packit ae9e2a
	assert_config_entry_value(_repo, "core.worktree", "../c_wd/");
Packit ae9e2a
Packit ae9e2a
	/* Verify gitlink */
Packit ae9e2a
	cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
Packit ae9e2a
	cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&dot_git_content);
Packit ae9e2a
	cleanup_repository("root");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__relative_gitdir_2(void)
Packit ae9e2a
{
Packit ae9e2a
	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
Packit ae9e2a
	git_buf dot_git_content = GIT_BUF_INIT;
Packit ae9e2a
	git_buf full_path = GIT_BUF_INIT;
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_path_prettify(&full_path, ".", NULL));
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&full_path, full_path.ptr, "root/b/c_wd"));
Packit ae9e2a
Packit ae9e2a
	opts.workdir_path = full_path.ptr;
Packit ae9e2a
	opts.flags =
Packit ae9e2a
		GIT_REPOSITORY_INIT_MKPATH |
Packit ae9e2a
		GIT_REPOSITORY_INIT_RELATIVE_GITLINK |
Packit ae9e2a
		GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
Packit ae9e2a
Packit ae9e2a
	/* make the directory first, then it should succeed */
Packit ae9e2a
	cl_git_pass(git_repository_init_ext(&_repo, "root/b/my_repository", &opts));
Packit ae9e2a
	git_buf_free(&full_path);
Packit ae9e2a
Packit ae9e2a
	cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "root/b/c_wd/"));
Packit ae9e2a
	cl_assert(!git__suffixcmp(git_repository_path(_repo), "root/b/my_repository/"));
Packit ae9e2a
	cl_assert(!git_repository_is_bare(_repo));
Packit ae9e2a
	cl_assert(git_repository_is_empty(_repo));
Packit ae9e2a
Packit ae9e2a
	/* Verify that the gitlink and worktree entries are relative */
Packit ae9e2a
Packit ae9e2a
	/* Verify worktree */
Packit ae9e2a
	assert_config_entry_value(_repo, "core.worktree", "../c_wd/");
Packit ae9e2a
Packit ae9e2a
	/* Verify gitlink */
Packit ae9e2a
	cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
Packit ae9e2a
	cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&dot_git_content);
Packit ae9e2a
	cleanup_repository("root");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
#define CLEAR_FOR_CORE_FILEMODE(M) ((M) &= ~0177)
Packit ae9e2a
Packit ae9e2a
static void assert_hooks_match(
Packit ae9e2a
	const char *template_dir,
Packit ae9e2a
	const char *repo_dir,
Packit ae9e2a
	const char *hook_path,
Packit ae9e2a
	bool core_filemode)
Packit ae9e2a
{
Packit ae9e2a
	git_buf expected = GIT_BUF_INIT;
Packit ae9e2a
	git_buf actual = GIT_BUF_INIT;
Packit ae9e2a
	struct stat expected_st, st;
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&expected, template_dir, hook_path));
Packit ae9e2a
	cl_git_pass(git_path_lstat(expected.ptr, &expected_st));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&actual, repo_dir, hook_path));
Packit ae9e2a
	cl_git_pass(git_path_lstat(actual.ptr, &st);;
Packit ae9e2a
Packit ae9e2a
	cl_assert(expected_st.st_size == st.st_size);
Packit ae9e2a
Packit ae9e2a
	if (GIT_MODE_TYPE(expected_st.st_mode) != GIT_FILEMODE_LINK) {
Packit ae9e2a
		mode_t expected_mode =
Packit ae9e2a
			GIT_MODE_TYPE(expected_st.st_mode) |
Packit ae9e2a
			(GIT_PERMS_FOR_WRITE(expected_st.st_mode) & ~g_umask);
Packit ae9e2a
Packit ae9e2a
		if (!core_filemode) {
Packit ae9e2a
			CLEAR_FOR_CORE_FILEMODE(expected_mode);
Packit ae9e2a
			CLEAR_FOR_CORE_FILEMODE(st.st_mode);
Packit ae9e2a
		}
Packit ae9e2a
Packit ae9e2a
		cl_assert_equal_i_fmt(expected_mode, st.st_mode, "%07o");
Packit ae9e2a
	}
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&expected);
Packit ae9e2a
	git_buf_free(&actual);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
static void assert_mode_seems_okay(
Packit ae9e2a
	const char *base, const char *path,
Packit ae9e2a
	git_filemode_t expect_mode, bool expect_setgid, bool core_filemode)
Packit ae9e2a
{
Packit ae9e2a
	git_buf full = GIT_BUF_INIT;
Packit ae9e2a
	struct stat st;
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&full, base, path));
Packit ae9e2a
	cl_git_pass(git_path_lstat(full.ptr, &st);;
Packit ae9e2a
	git_buf_free(&full);
Packit ae9e2a
Packit ae9e2a
	if (!core_filemode) {
Packit ae9e2a
		CLEAR_FOR_CORE_FILEMODE(expect_mode);
Packit ae9e2a
		CLEAR_FOR_CORE_FILEMODE(st.st_mode);
Packit ae9e2a
		expect_setgid = false;
Packit ae9e2a
	}
Packit ae9e2a
Packit ae9e2a
	if (S_ISGID != 0)
Packit ae9e2a
		cl_assert_equal_b(expect_setgid, (st.st_mode & S_ISGID) != 0);
Packit ae9e2a
Packit ae9e2a
	cl_assert_equal_b(
Packit ae9e2a
		GIT_PERMS_IS_EXEC(expect_mode), GIT_PERMS_IS_EXEC(st.st_mode));
Packit ae9e2a
Packit ae9e2a
	cl_assert_equal_i_fmt(
Packit ae9e2a
		GIT_MODE_TYPE(expect_mode), GIT_MODE_TYPE(st.st_mode), "%07o");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
static const char *template_sandbox(const char *name)
Packit ae9e2a
{
Packit ae9e2a
	git_buf hooks_path = GIT_BUF_INIT, link_path = GIT_BUF_INIT,
Packit ae9e2a
		dotfile_path = GIT_BUF_INIT;
Packit ae9e2a
	const char *path = cl_fixture(name);
Packit ae9e2a
Packit ae9e2a
	cl_fixture_sandbox(name);
Packit ae9e2a
Packit ae9e2a
	/* create a symlink from link.sample to update.sample if the filesystem
Packit ae9e2a
	 * supports it.
Packit ae9e2a
	 */
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&hooks_path, name, "hooks"));
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&link_path, hooks_path.ptr, "link.sample"));
Packit ae9e2a
Packit ae9e2a
#ifdef GIT_WIN32
Packit ae9e2a
	cl_git_mkfile(link_path.ptr, "#!/bin/sh\necho hello, world\n");
Packit ae9e2a
#else
Packit ae9e2a
	cl_must_pass(symlink("update.sample", link_path.ptr));
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
	/* create a file starting with a dot */
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&dotfile_path, hooks_path.ptr, ".dotfile"));
Packit ae9e2a
	cl_git_mkfile(dotfile_path.ptr, "something\n");
Packit ae9e2a
	git_buf_free(&dotfile_path);
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&dotfile_path);
Packit ae9e2a
	git_buf_free(&link_path);
Packit ae9e2a
	git_buf_free(&hooks_path);
Packit ae9e2a
Packit ae9e2a
	return path;
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
static void configure_templatedir(const char *template_path)
Packit ae9e2a
{
Packit ae9e2a
	git_buf config_path = GIT_BUF_INIT;
Packit ae9e2a
	git_buf config_data = GIT_BUF_INIT;
Packit ae9e2a
Packit ae9e2a
    cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
Packit ae9e2a
		GIT_CONFIG_LEVEL_GLOBAL, &_tmp_path));
Packit ae9e2a
	cl_git_pass(git_buf_puts(&_tmp_path, ".tmp"));
Packit ae9e2a
	cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH,
Packit ae9e2a
		GIT_CONFIG_LEVEL_GLOBAL, _tmp_path.ptr));
Packit ae9e2a
Packit ae9e2a
	cl_must_pass(p_mkdir(_tmp_path.ptr, 0777));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&config_path, _tmp_path.ptr, ".gitconfig"));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_buf_printf(&config_data,
Packit ae9e2a
		"[init]\n\ttemplatedir = \"%s\"\n", template_path));
Packit ae9e2a
Packit ae9e2a
	cl_git_mkfile(config_path.ptr, config_data.ptr);
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&config_path);
Packit ae9e2a
	git_buf_free(&config_data);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
static void validate_templates(git_repository *repo, const char *template_path)
Packit ae9e2a
{
Packit ae9e2a
	git_buf template_description = GIT_BUF_INIT;
Packit ae9e2a
	git_buf repo_description = GIT_BUF_INIT;
Packit ae9e2a
	git_buf expected = GIT_BUF_INIT;
Packit ae9e2a
	git_buf actual = GIT_BUF_INIT;
Packit ae9e2a
	int filemode;
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&template_description, template_path,
Packit ae9e2a
		"description"));
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&repo_description, git_repository_path(repo),
Packit ae9e2a
		"description"));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_futils_readbuffer(&expected, template_description.ptr));
Packit ae9e2a
	cl_git_pass(git_futils_readbuffer(&actual, repo_description.ptr));
Packit ae9e2a
Packit ae9e2a
	cl_assert_equal_s(expected.ptr, actual.ptr);
Packit ae9e2a
Packit ae9e2a
	filemode = cl_repo_get_bool(repo, "core.filemode");
Packit ae9e2a
Packit ae9e2a
	assert_hooks_match(
Packit ae9e2a
		template_path, git_repository_path(repo),
Packit ae9e2a
		"hooks/update.sample", filemode);
Packit ae9e2a
Packit ae9e2a
	assert_hooks_match(
Packit ae9e2a
		template_path, git_repository_path(repo),
Packit ae9e2a
		"hooks/link.sample", filemode);
Packit ae9e2a
Packit ae9e2a
	assert_hooks_match(
Packit ae9e2a
		template_path, git_repository_path(repo),
Packit ae9e2a
		"hooks/.dotfile", filemode);
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&expected);
Packit ae9e2a
	git_buf_free(&actual);
Packit ae9e2a
	git_buf_free(&repo_description);
Packit ae9e2a
	git_buf_free(&template_description);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__external_templates_specified_in_options(void)
Packit ae9e2a
{
Packit ae9e2a
	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
Packit ae9e2a
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "templated.git");
Packit ae9e2a
	template_sandbox("template");
Packit ae9e2a
Packit ae9e2a
	opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE |
Packit ae9e2a
		GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
Packit ae9e2a
	opts.template_path = "template";
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts));
Packit ae9e2a
Packit ae9e2a
	cl_assert(git_repository_is_bare(_repo));
Packit ae9e2a
Packit ae9e2a
	cl_assert(!git__suffixcmp(git_repository_path(_repo), "/templated.git/"));
Packit ae9e2a
Packit ae9e2a
	validate_templates(_repo, "template");
Packit ae9e2a
	cl_fixture_cleanup("template");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__external_templates_specified_in_config(void)
Packit ae9e2a
{
Packit ae9e2a
	git_buf template_path = GIT_BUF_INIT;
Packit ae9e2a
Packit ae9e2a
	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
Packit ae9e2a
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "templated.git");
Packit ae9e2a
	template_sandbox("template");
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&template_path, clar_sandbox_path(),
Packit ae9e2a
		"template"));
Packit ae9e2a
Packit ae9e2a
	configure_templatedir(template_path.ptr);
Packit ae9e2a
Packit ae9e2a
	opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE |
Packit ae9e2a
		GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts));
Packit ae9e2a
Packit ae9e2a
	validate_templates(_repo, "template");
Packit ae9e2a
	cl_fixture_cleanup("template");
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&template_path);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__external_templates_with_leading_dot(void)
Packit ae9e2a
{
Packit ae9e2a
	git_buf template_path = GIT_BUF_INIT;
Packit ae9e2a
Packit ae9e2a
	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
Packit ae9e2a
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "templated.git");
Packit ae9e2a
	template_sandbox("template");
Packit ae9e2a
Packit ae9e2a
	cl_must_pass(p_rename("template", ".template_with_leading_dot"));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_buf_joinpath(&template_path, clar_sandbox_path(),
Packit ae9e2a
		".template_with_leading_dot"));
Packit ae9e2a
Packit ae9e2a
	configure_templatedir(template_path.ptr);
Packit ae9e2a
Packit ae9e2a
	opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE |
Packit ae9e2a
		GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts));
Packit ae9e2a
Packit ae9e2a
	validate_templates(_repo, ".template_with_leading_dot");
Packit ae9e2a
	cl_fixture_cleanup(".template_with_leading_dot");
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&template_path);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__extended_with_template_and_shared_mode(void)
Packit ae9e2a
{
Packit ae9e2a
	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
Packit ae9e2a
	int filemode = true;
Packit ae9e2a
	const char *repo_path = NULL;
Packit ae9e2a
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "init_shared_from_tpl");
Packit ae9e2a
	template_sandbox("template");
Packit ae9e2a
Packit ae9e2a
	opts.flags = GIT_REPOSITORY_INIT_MKPATH |
Packit ae9e2a
		GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
Packit ae9e2a
	opts.template_path = "template";
Packit ae9e2a
	opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP;
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_repository_init_ext(&_repo, "init_shared_from_tpl", &opts));
Packit ae9e2a
Packit ae9e2a
	cl_assert(!git_repository_is_bare(_repo));
Packit ae9e2a
	cl_assert(!git__suffixcmp(git_repository_path(_repo), "/init_shared_from_tpl/.git/"));
Packit ae9e2a
Packit ae9e2a
	filemode = cl_repo_get_bool(_repo, "core.filemode");
Packit ae9e2a
Packit ae9e2a
	repo_path = git_repository_path(_repo);
Packit ae9e2a
	assert_mode_seems_okay(repo_path, "hooks",
Packit ae9e2a
		GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode);
Packit ae9e2a
	assert_mode_seems_okay(repo_path, "info",
Packit ae9e2a
		GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode);
Packit ae9e2a
	assert_mode_seems_okay(repo_path, "description",
Packit ae9e2a
		GIT_FILEMODE_BLOB, false, filemode);
Packit ae9e2a
Packit ae9e2a
	validate_templates(_repo, "template");
Packit ae9e2a
Packit ae9e2a
	cl_fixture_cleanup("template");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__can_reinit_an_initialized_repository(void)
Packit ae9e2a
{
Packit ae9e2a
	git_repository *reinit;
Packit ae9e2a
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "extended");
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_futils_mkdir("extended", 0775, 0));
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, "extended", false));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_repository_init(&reinit, "extended", false));
Packit ae9e2a
Packit ae9e2a
	cl_assert_equal_s(git_repository_path(_repo), git_repository_path(reinit));
Packit ae9e2a
Packit ae9e2a
	git_repository_free(reinit);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__init_with_initial_commit(void)
Packit ae9e2a
{
Packit ae9e2a
	git_index *index;
Packit ae9e2a
Packit ae9e2a
	cl_set_cleanup(&cleanup_repository, "committed");
Packit ae9e2a
Packit ae9e2a
	/* Initialize the repository */
Packit ae9e2a
	cl_git_pass(git_repository_init(&_repo, "committed", 0));
Packit ae9e2a
Packit ae9e2a
	/* Init will be automatically created when requested for a new repo */
Packit ae9e2a
	cl_git_pass(git_repository_index(&index, _repo));
Packit ae9e2a
Packit ae9e2a
	/* Create a file so we can commit it
Packit ae9e2a
	 *
Packit ae9e2a
	 * If you are writing code outside the test suite, you can create this
Packit ae9e2a
	 * file any way that you like, such as:
Packit ae9e2a
	 *      FILE *fp = fopen("committed/file.txt", "w");
Packit ae9e2a
	 *      fputs("some stuff\n", fp);
Packit ae9e2a
	 *      fclose(fp);
Packit ae9e2a
	 * We like to use the help functions because they do error detection
Packit ae9e2a
	 * in a way that's easily compatible with our test suite.
Packit ae9e2a
	 */
Packit ae9e2a
	cl_git_mkfile("committed/file.txt", "some stuff\n");
Packit ae9e2a
Packit ae9e2a
	/* Add file to the index */
Packit ae9e2a
	cl_git_pass(git_index_add_bypath(index, "file.txt"));
Packit ae9e2a
	cl_git_pass(git_index_write(index));
Packit ae9e2a
Packit ae9e2a
	/* Intentionally not using cl_repo_commit_from_index here so this code
Packit ae9e2a
	 * can be used as an example of how an initial commit is typically
Packit ae9e2a
	 * made to a repository...
Packit ae9e2a
	 */
Packit ae9e2a
Packit ae9e2a
	/* Make sure we're ready to use git_signature_default :-) */
Packit ae9e2a
	{
Packit ae9e2a
		git_config *cfg, *local;
Packit ae9e2a
		cl_git_pass(git_repository_config(&cfg, _repo));
Packit ae9e2a
		cl_git_pass(git_config_open_level(&local, cfg, GIT_CONFIG_LEVEL_LOCAL));
Packit ae9e2a
		cl_git_pass(git_config_set_string(local, "user.name", "Test User"));
Packit ae9e2a
		cl_git_pass(git_config_set_string(local, "user.email", "t@example.com"));
Packit ae9e2a
		git_config_free(local);
Packit ae9e2a
		git_config_free(cfg);
Packit ae9e2a
	}
Packit ae9e2a
Packit ae9e2a
	/* Create a commit with the new contents of the index */
Packit ae9e2a
	{
Packit ae9e2a
		git_signature *sig;
Packit ae9e2a
		git_oid tree_id, commit_id;
Packit ae9e2a
		git_tree *tree;
Packit ae9e2a
Packit ae9e2a
		cl_git_pass(git_signature_default(&sig, _repo));
Packit ae9e2a
		cl_git_pass(git_index_write_tree(&tree_id, index));
Packit ae9e2a
		cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
Packit ae9e2a
Packit ae9e2a
		cl_git_pass(git_commit_create_v(
Packit ae9e2a
			&commit_id, _repo, "HEAD", sig, sig,
Packit ae9e2a
			NULL, "First", tree, 0));
Packit ae9e2a
Packit ae9e2a
		git_tree_free(tree);
Packit ae9e2a
		git_signature_free(sig);
Packit ae9e2a
	}
Packit ae9e2a
Packit ae9e2a
	git_index_free(index);
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_repo_init__at_filesystem_root(void)
Packit ae9e2a
{
Packit ae9e2a
	git_repository *repo;
Packit ae9e2a
	const char *sandbox = clar_sandbox_path();
Packit ae9e2a
	git_buf root = GIT_BUF_INIT;
Packit ae9e2a
	int root_len;
Packit ae9e2a
Packit ae9e2a
	if (!cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE"))
Packit ae9e2a
		cl_skip();
Packit ae9e2a
Packit ae9e2a
	root_len = git_path_root(sandbox);
Packit ae9e2a
	cl_assert(root_len >= 0);
Packit ae9e2a
Packit ae9e2a
	git_buf_put(&root, sandbox, root_len+1);
Packit ae9e2a
	git_buf_joinpath(&root, root.ptr, "libgit2_test_dir");
Packit ae9e2a
Packit ae9e2a
	cl_assert(!git_path_exists(root.ptr));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_repository_init(&repo, root.ptr, 0));
Packit ae9e2a
	cl_assert(git_path_isdir(root.ptr));
Packit ae9e2a
	cl_git_pass(git_futils_rmdir_r(root.ptr, NULL, GIT_RMDIR_REMOVE_FILES));
Packit ae9e2a
Packit ae9e2a
	git_buf_free(&root);
Packit ae9e2a
	git_repository_free(repo);
Packit ae9e2a
}