]> git.proxmox.com Git - libgit2.git/blobdiff - tests/repo/open.c
New upstream version 1.3.0+dfsg.1
[libgit2.git] / tests / repo / open.c
index d3d087231a7bdcf9e04a795ff2f79364972332c5..bd60c12c29b2834e3aff442433bf694485a2b5b2 100644 (file)
@@ -1,8 +1,9 @@
 #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();
@@ -34,7 +35,11 @@ void test_repo_open__format_version_1(void)
 
        git_config_free(config);
        git_repository_free(repo);
-       cl_git_fail(git_repository_open(&repo, "empty_bare.git"));
+
+       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);
 }
 
 void test_repo_open__standard_empty_repo_through_gitdir(void)
@@ -87,6 +92,17 @@ void test_repo_open__open_with_discover(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;
@@ -94,7 +110,7 @@ static void make_gitlink_dir(const char *dir, const char *linktext)
        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)
@@ -117,6 +133,36 @@ 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
@@ -165,9 +211,9 @@ void test_repo_open__from_git_new_workdir(void)
                }
        }
 
-       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"));
@@ -179,6 +225,8 @@ void test_repo_open__from_git_new_workdir(void)
        cl_assert_(git__suffixcmp(git_repository_workdir(repo2), "alternate/") == 0, git_repository_workdir(repo2));
 
        git_repository_free(repo2);
+#else
+       cl_skip();
 #endif
 }
 
@@ -196,8 +244,9 @@ void test_repo_open__failures(void)
                &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));
@@ -205,7 +254,13 @@ void test_repo_open__failures(void)
        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)
@@ -226,7 +281,9 @@ void test_repo_open__bad_gitlinks(void)
 
        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);
@@ -298,7 +355,7 @@ void test_repo_open__win32_path(void)
        cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
        git_repository_free(repo2);
 
-       git_buf_free(&winpath);
+       git_buf_dispose(&winpath);
 #endif
 }
 
@@ -332,7 +389,7 @@ void test_repo_open__no_config(void)
        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));
@@ -390,7 +447,9 @@ void test_repo_open__force_bare(void)
        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);
 }
+