void test_repo_init__relative_gitdir(void) { git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; git_buf dot_git_content = GIT_BUF_INIT; opts.workdir_path = "../c_wd"; opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_RELATIVE_GITLINK | GIT_REPOSITORY_INIT_NO_DOTGIT_DIR; /* make the directory first, then it should succeed */ cl_git_pass(git_repository_init_ext(&_repo, "root/b/my_repository", &opts)); cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "root/b/c_wd/")); cl_assert(!git__suffixcmp(git_repository_path(_repo), "root/b/my_repository/")); cl_assert(!git_repository_is_bare(_repo)); cl_assert(git_repository_is_empty(_repo)); /* Verify that the gitlink and worktree entries are relative */ /* Verify worktree */ assert_config_entry_value(_repo, "core.worktree", "../c_wd/"); /* Verify gitlink */ cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git")); cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr); git_buf_free(&dot_git_content); cleanup_repository("root"); }
void test_repo_init__bare_repo_escaping_current_workdir(void) { git_buf path_repository = GIT_BUF_INIT; git_buf path_current_workdir = GIT_BUF_INIT; cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL)); cl_git_pass(git_buf_joinpath(&path_repository, git_buf_cstr(&path_current_workdir), "a/b/c")); cl_git_pass(git_futils_mkdir_r(git_buf_cstr(&path_repository), GIT_DIR_MODE)); /* Change the current working directory */ cl_git_pass(chdir(git_buf_cstr(&path_repository))); /* Initialize a bare repo with a relative path escaping out of the current working directory */ cl_git_pass(git_repository_init(&_repo, "../d/e.git", 1)); cl_git_pass(git__suffixcmp(git_repository_path(_repo), "/a/b/d/e.git/")); git_repository_free(_repo); /* Open a bare repo with a relative path escaping out of the current working directory */ cl_git_pass(git_repository_open(&_repo, "../d/e.git")); cl_git_pass(chdir(git_buf_cstr(&path_current_workdir))); git_buf_free(&path_current_workdir); git_buf_free(&path_repository); cleanup_repository("a"); }
void test_repo_init__empty_template_path(void) { git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; opts.template_path = ""; cl_git_pass(git_futils_mkdir("foo", 0755, 0)); cl_git_pass(git_repository_init_ext(&_repo, "foo", &opts)); cleanup_repository("foo"); }
void test_repo_init__can_reinit_an_initialized_repository(void) { git_repository *reinit; cl_git_pass(git_futils_mkdir("extended", NULL, 0775, 0)); cl_git_pass(git_repository_init(&_repo, "extended", false)); cl_git_pass(git_repository_init(&reinit, "extended", false)); cl_assert_equal_s(git_repository_path(_repo), git_repository_path(reinit)); git_repository_free(reinit); cleanup_repository("extended"); }
void test_repo_init__extended_with_template(void) { git_repository_init_options opts; memset(&opts, 0, sizeof(opts)); opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE; opts.template_path = cl_fixture("template"); cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts)); cl_assert(git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/templated.git/")); cleanup_repository("templated.git"); }
void test_repo_init__extended_0(void) { git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; /* without MKDIR this should fail */ cl_git_fail(git_repository_init_ext(&_repo, "extended", &opts)); /* make the directory first, then it should succeed */ cl_git_pass(git_futils_mkdir("extended", 0775, 0)); cl_git_pass(git_repository_init_ext(&_repo, "extended", &opts)); cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/extended/")); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/extended/.git/")); cl_assert(!git_repository_is_bare(_repo)); cl_assert(git_repository_is_empty(_repo)); cleanup_repository("extended"); }