Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJameson Miller <jamill@microsoft.com>2014-08-20 18:24:41 +0400
committerJameson Miller <jamill@microsoft.com>2014-09-03 05:07:26 +0400
commitbc737620dd0d331cb80c22d074569fe29b7ab585 (patch)
tree02845048ed92a316433bf6c38d8283408d6b530f /tests/repo
parent0ee9f31c3b11116ab5806ab80d03b1d37197d6ce (diff)
Introduce option to use relative paths for repository work directory
Teach git_repository_init_ext to use relative paths for the gitlink to the work directory. This is used when creating a sub repository where the sub repository resides in the parent repository's .git directory.
Diffstat (limited to 'tests/repo')
-rw-r--r--tests/repo/init.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/repo/init.c b/tests/repo/init.c
index aea383c64..999afd625 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -367,6 +367,84 @@ void test_repo_init__extended_1(void)
cl_fixture_cleanup("root");
}
+void test_repo_init__relative_gitdir(void)
+{
+ git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
+ git_config *cfg;
+ const char *worktree_path;
+ 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 */
+ cl_git_pass(git_repository_config(&cfg, _repo));
+ cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
+ cl_assert_equal_s("../c_wd/", worktree_path);
+
+ /* 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);
+ git_config_free(cfg);
+ cleanup_repository("root");
+}
+
+void test_repo_init__relative_gitdir_2(void)
+{
+ git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
+ git_config *cfg;
+ const char *worktree_path;
+ git_buf dot_git_content = GIT_BUF_INIT;
+ git_buf full_path = GIT_BUF_INIT;
+
+ cl_git_pass(git_path_prettify(&full_path, ".", NULL));
+ cl_git_pass(git_buf_joinpath(&full_path, full_path.ptr, "root/b/c_wd"));
+
+ opts.workdir_path = full_path.ptr;
+ 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 */
+ cl_git_pass(git_repository_config(&cfg, _repo));
+ cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree"));
+ cl_assert_equal_s("../c_wd/", worktree_path);
+
+ /* 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);
+ git_config_free(cfg);
+ cleanup_repository("root");
+}
+
#define CLEAR_FOR_CORE_FILEMODE(M) ((M) &= ~0177)
static void assert_hooks_match(