Skip to content

Commit a82082d

Browse files
tiennoupks-t
authored andcommitted
worktree: a worktree can be made from a bare repository
1 parent c7964c2 commit a82082d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char
139139
if ((wt->name = git__strdup(name)) == NULL
140140
|| (wt->commondir_path = git_worktree__read_link(dir, "commondir")) == NULL
141141
|| (wt->gitlink_path = git_worktree__read_link(dir, "gitdir")) == NULL
142-
|| (wt->parent_path = git__strdup(parent)) == NULL
142+
|| (parent && (wt->parent_path = git__strdup(parent)) == NULL)
143143
|| (wt->worktree_path = git_path_dirname(wt->gitlink_path)) == NULL) {
144144
error = -1;
145145
goto out;

tests/worktree/worktree.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,26 @@ void test_worktree_worktree__init(void)
228228
git_repository_free(repo);
229229
}
230230

231+
void test_worktree_worktree__add_from_bare(void)
232+
{
233+
git_worktree *wt;
234+
git_repository *repo, *wtrepo;
235+
236+
repo = cl_git_sandbox_init("short_tag.git");
237+
238+
cl_assert_equal_i(1, git_repository_is_bare(repo));
239+
cl_assert_equal_i(0, git_repository_is_worktree(repo));
240+
241+
cl_git_pass(git_worktree_add(&wt, repo, "worktree-frombare", "worktree-frombare", NULL));
242+
cl_git_pass(git_repository_open(&wtrepo, "worktree-frombare"));
243+
cl_assert_equal_i(0, git_repository_is_bare(wtrepo));
244+
cl_assert_equal_i(1, git_repository_is_worktree(wtrepo));
245+
246+
git_worktree_free(wt);
247+
git_repository_free(repo);
248+
git_repository_free(wtrepo);
249+
}
250+
231251
void test_worktree_worktree__add_locked(void)
232252
{
233253
git_worktree *wt;

0 commit comments

Comments
 (0)