diff options
author | Etienne Samson <samson.etienne@gmail.com> | 2018-04-20 08:38:50 +0000 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2018-10-26 14:58:50 +0200 |
commit | c62c6379092ba61e6c6d29c191a5b94dbdc8375c (patch) | |
tree | 8404340951b7b5b650233857858ed20a1c173942 | |
parent | a7fbb051ef5e89e866369ad86216eaa415dde58b (diff) | |
download | libgit2-c62c6379092ba61e6c6d29c191a5b94dbdc8375c.tar.gz |
worktree: a worktree can be made from a bare repository
-rw-r--r-- | src/worktree.c | 2 | ||||
-rw-r--r-- | tests/worktree/worktree.c | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/worktree.c b/src/worktree.c index 91527663e..6ba1fce33 100644 --- a/src/worktree.c +++ b/src/worktree.c @@ -139,7 +139,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char if ((wt->name = git__strdup(name)) == NULL || (wt->commondir_path = git_worktree__read_link(dir, "commondir")) == NULL || (wt->gitlink_path = git_worktree__read_link(dir, "gitdir")) == NULL - || (wt->parent_path = git__strdup(parent)) == NULL) { + || (parent && (wt->parent_path = git__strdup(parent)) == NULL)) { error = -1; goto out; } diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c index 4ac3b8bba..8f6bd7c55 100644 --- a/tests/worktree/worktree.c +++ b/tests/worktree/worktree.c @@ -228,6 +228,26 @@ void test_worktree_worktree__init(void) git_repository_free(repo); } +void test_worktree_worktree__add_from_bare(void) +{ + git_worktree *wt; + git_repository *repo, *wtrepo; + + repo = cl_git_sandbox_init("short_tag.git"); + + cl_assert_equal_i(1, git_repository_is_bare(repo)); + cl_assert_equal_i(0, git_repository_is_worktree(repo)); + + cl_git_pass(git_worktree_add(&wt, repo, "worktree-frombare", "worktree-frombare", NULL)); + cl_git_pass(git_repository_open(&wtrepo, "worktree-frombare")); + cl_assert_equal_i(0, git_repository_is_bare(wtrepo)); + cl_assert_equal_i(1, git_repository_is_worktree(wtrepo)); + + git_worktree_free(wt); + git_repository_free(repo); + git_repository_free(wtrepo); +} + void test_worktree_worktree__add_locked(void) { git_worktree *wt; |