]> 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 3239b6fecf2722e3483f04e49c7d6d3a6bed249c..bd60c12c29b2834e3aff442433bf694485a2b5b2 100644 (file)
@@ -1,5 +1,5 @@
 #include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
 #include "sysdir.h"
 #include <ctype.h>
 
@@ -35,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)
@@ -88,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;
@@ -95,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)
@@ -118,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
@@ -166,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"));
@@ -180,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
 }
 
@@ -213,7 +260,7 @@ void test_repo_open__failures(void)
                GIT_REPOSITORY_OPEN_NO_SEARCH | GIT_REPOSITORY_OPEN_NO_DOTGIT,
                NULL));
 
-       git_buf_free(&ceiling);
+       git_buf_dispose(&ceiling);
 }
 
 void test_repo_open__bad_gitlinks(void)
@@ -234,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);
@@ -306,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
 }
 
@@ -340,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));