summaryrefslogtreecommitdiff
path: root/tests-clar/repo/setters.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-07-10 15:35:38 -0700
committerRussell Belfer <rb@github.com>2012-07-10 23:19:47 -0700
commit991a56c704f931e7eb52a0583e5d8684803f3b04 (patch)
tree28c0b9f7d113d5a55a060723516a9414d002c9f8 /tests-clar/repo/setters.c
parentb3ff1dab317dc9194c4bc124afd95ae9be2ad57b (diff)
downloadlibgit2-991a56c704f931e7eb52a0583e5d8684803f3b04.tar.gz
Add flag to write gitlink on setting repo workdir
This added a flag to the `git_repository_set_workdir()` function that enables generation of a `.git` gitlink file that links the new workdir to the parent repository. Essentially, the flag tells the function to write out the changes to disk to permanently set the workdir of the repository to the new path. If you pass this flag as true, then setting the workdir to something other than the default workdir (i.e. the parent of the .git repo directory), will create a plain file named ".git" with the standard gitlink contents "gitdir: <repo-path>", and also update the "core.worktree" and "core.bare" config values. Setting the workdir to the default repo workdir will clear the core.worktree flag (but still permanently set core.bare to false). BTW, the libgit2 API does not currently provide a function for clearing the workdir and converting a non-bare repo into a bare one.
Diffstat (limited to 'tests-clar/repo/setters.c')
-rw-r--r--tests-clar/repo/setters.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/tests-clar/repo/setters.c b/tests-clar/repo/setters.c
index 6242d8541..cd6e389ae 100644
--- a/tests-clar/repo/setters.c
+++ b/tests-clar/repo/setters.c
@@ -2,6 +2,8 @@
#include "buffer.h"
#include "posix.h"
#include "util.h"
+#include "path.h"
+#include "fileops.h"
static git_repository *repo;
@@ -16,7 +18,7 @@ void test_repo_setters__cleanup(void)
{
git_repository_free(repo);
cl_fixture_cleanup("testrepo.git");
- cl_must_pass(p_rmdir("new_workdir"));
+ cl_fixture_cleanup("new_workdir");
}
void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standard_one(void)
@@ -24,7 +26,7 @@ void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standar
cl_assert(git_repository_is_bare(repo) == 1);
cl_assert(git_repository_workdir(repo) == NULL);
- cl_git_pass(git_repository_set_workdir(repo, "./new_workdir"));
+ cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", false));
cl_assert(git_repository_workdir(repo) != NULL);
cl_assert(git_repository_is_bare(repo) == 0);
@@ -32,9 +34,30 @@ void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standar
void test_repo_setters__setting_a_workdir_prettifies_its_path(void)
{
- cl_git_pass(git_repository_set_workdir(repo, "./new_workdir"));
+ cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", false));
- cl_assert(git__suffixcmp(git_repository_workdir(repo), "/") == 0);
+ cl_assert(git__suffixcmp(git_repository_workdir(repo), "new_workdir/") == 0);
+}
+
+void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
+{
+ git_config *cfg;
+ const char *val;
+ git_buf content = GIT_BUF_INIT;
+
+ cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));
+
+ cl_assert(git_path_isfile("./new_workdir/.git"));
+
+ cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git"));
+ cl_assert(git__prefixcmp(git_buf_cstr(&content), "gitdir: ") == 0);
+ cl_assert(git__suffixcmp(git_buf_cstr(&content), "testrepo.git/") == 0);
+ git_buf_free(&content);
+
+ cl_git_pass(git_repository_config(&cfg, repo));
+ cl_git_pass(git_config_get_string(&val, cfg, "core.worktree"));
+ cl_assert(git__suffixcmp(val, "new_workdir/") == 0);
+ git_config_free(cfg);
}
void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_one_properly_honors_the_refcount(void)