#include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
#include "sysdir.h"
#include <ctype.h>
+
void test_repo_open__cleanup(void)
{
cl_git_sandbox_cleanup();
void test_repo_open__format_version_1(void)
{
- git_buf path = GIT_BUF_INIT;
git_repository *repo;
git_config *config;
repo = cl_git_sandbox_init("empty_bare.git");
cl_git_pass(git_repository_open(&repo, "empty_bare.git"));
- cl_git_pass(git_repository_config__weakptr(&config, repo));
+ cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 1));
+ git_config_free(config);
+ git_repository_free(repo);
+
+ cl_git_pass(git_repository_open(&repo, "empty_bare.git"));
+ cl_assert(git_repository_path(repo) != NULL);
+ cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0);
git_repository_free(repo);
- cl_git_fail(git_repository_open(&repo, "empty_bare.git"));
}
void test_repo_open__standard_empty_repo_through_gitdir(void)
cl_fixture_cleanup("attr");
}
+void test_repo_open__check_if_repository(void)
+{
+ cl_git_sandbox_init("empty_standard_repo");
+
+ /* Pass NULL for the output parameter to check for but not open the repo */
+ cl_git_pass(git_repository_open_ext(NULL, "empty_standard_repo", 0, NULL));
+ cl_git_fail(git_repository_open_ext(NULL, "repo_does_not_exist", 0, NULL));
+
+ cl_fixture_cleanup("empty_standard_repo");
+}
+
static void make_gitlink_dir(const char *dir, const char *linktext)
{
git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_futils_mkdir(dir, NULL, 0777, GIT_MKDIR_VERIFY_DIR));
+ cl_git_pass(git_futils_mkdir(dir, 0777, GIT_MKDIR_VERIFY_DIR));
cl_git_pass(git_buf_joinpath(&path, dir, ".git"));
cl_git_rewritefile(path.ptr, linktext);
- git_buf_free(&path);
+ git_buf_dispose(&path);
}
void test_repo_open__gitlinked(void)
git_repository_free(repo2);
}
+void test_repo_open__with_symlinked_config(void)
+{
+#ifndef GIT_WIN32
+ git_buf path = GIT_BUF_INIT;
+ git_repository *repo;
+ git_config *cfg;
+ int32_t value;
+
+ cl_git_sandbox_init("empty_standard_repo");
+
+ /* Setup .gitconfig as symlink */
+ cl_git_pass(git_futils_mkdir_r("home", 0777));
+ cl_git_mkfile("home/.gitconfig.linked", "[global]\ntest = 4567\n");
+ cl_must_pass(symlink(".gitconfig.linked", "home/.gitconfig"));
+ cl_git_pass(git_path_prettify(&path, "home", NULL));
+ cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
+
+ cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
+ cl_git_pass(git_config_open_default(&cfg));
+ cl_git_pass(git_config_get_int32(&value, cfg, "global.test"));
+ cl_assert_equal_i(4567, value);
+
+ git_config_free(cfg);
+ git_repository_free(repo);
+ cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
+ cl_sandbox_set_search_path_defaults();
+ git_buf_dispose(&path);
+#endif
+}
+
void test_repo_open__from_git_new_workdir(void)
{
#ifndef GIT_WIN32
}
}
- git_buf_free(&link_tgt);
- git_buf_free(&link);
- git_buf_free(&body);
+ git_buf_dispose(&link_tgt);
+ git_buf_dispose(&link);
+ git_buf_dispose(&body);
cl_git_pass(git_repository_open(&repo2, "alternate"));
cl_assert_(git__suffixcmp(git_repository_workdir(repo2), "alternate/") == 0, git_repository_workdir(repo2));
git_repository_free(repo2);
+#else
+ cl_skip();
#endif
}
&repo, "attr/sub", GIT_REPOSITORY_OPEN_NO_SEARCH, NULL));
/* fail with ceiling too low */
- cl_git_pass(git_buf_joinpath(&ceiling, ceiling.ptr, "sub"));
cl_git_fail(git_repository_open_ext(&repo, "attr/sub", 0, ceiling.ptr));
+ cl_git_pass(git_buf_joinpath(&ceiling, ceiling.ptr, "sub"));
+ cl_git_fail(git_repository_open_ext(&repo, "attr/sub/sub", 0, ceiling.ptr));
/* fail with no repo */
cl_git_pass(p_mkdir("alternate", 0777));
cl_git_fail(git_repository_open_ext(&repo, "alternate", 0, NULL));
cl_git_fail(git_repository_open_ext(&repo, "alternate/.git", 0, NULL));
- git_buf_free(&ceiling);
+ /* fail with no searching and no appending .git */
+ cl_git_fail(git_repository_open_ext(
+ &repo, "attr",
+ GIT_REPOSITORY_OPEN_NO_SEARCH | GIT_REPOSITORY_OPEN_NO_DOTGIT,
+ NULL));
+
+ git_buf_dispose(&ceiling);
}
void test_repo_open__bad_gitlinks(void)
cl_git_sandbox_init("attr");
cl_git_pass(p_mkdir("invalid", 0777));
- cl_git_pass(git_futils_mkdir_r("invalid2/.git", NULL, 0777));
+ cl_git_pass(git_futils_mkdir_r("invalid2/.git", 0777));
for (scan = bad_links; *scan != NULL; scan++) {
make_gitlink_dir("alternate", *scan);
+ repo = NULL;
cl_git_fail(git_repository_open_ext(&repo, "alternate", 0, NULL));
+ cl_assert(repo == NULL);
}
git_futils_rmdir_r("invalid", NULL, GIT_RMDIR_REMOVE_FILES);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
- git_buf_free(&winpath);
+ git_buf_dispose(&winpath);
#endif
}
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
- git_buf_free(&path);
+ git_buf_dispose(&path);
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_repository_config(&config, repo));
cl_git_fail(git_repository_open_bare(&barerepo, "alternate/subdir/sub2"));
cl_git_pass(git_repository_open_ext(
- &barerepo, "alternate/subdir/sub2", GIT_REPOSITORY_OPEN_BARE, NULL));
+ &barerepo, "alternate/subdir/sub2",
+ GIT_REPOSITORY_OPEN_BARE|GIT_REPOSITORY_OPEN_CROSS_FS, NULL));
cl_assert(git_repository_is_bare(barerepo));
git_repository_free(barerepo);
}
+