Skip to content

Commit 6f6dd17

Browse files
committed
worktree: test creating and opening submodule worktrees
1 parent 1fd6e03 commit 6f6dd17

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/worktree/worktree.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "clar_libgit2.h"
22
#include "worktree_helpers.h"
3+
#include "submodule/submodule_helpers.h"
34

45
#include "checkout.h"
56
#include "repository.h"
@@ -289,6 +290,33 @@ void test_worktree_worktree__init_existing_path(void)
289290
git_buf_free(&path);
290291
}
291292

293+
void test_worktree_worktree__init_submodule(void)
294+
{
295+
git_repository *repo, *sm, *wt;
296+
git_worktree *worktree;
297+
git_buf path = GIT_BUF_INIT;
298+
299+
cleanup_fixture_worktree(&fixture);
300+
repo = setup_fixture_submod2();
301+
302+
cl_git_pass(git_buf_joinpath(&path, repo->workdir, "sm_unchanged"));
303+
cl_git_pass(git_repository_open(&sm, path.ptr));
304+
cl_git_pass(git_buf_joinpath(&path, repo->workdir, "../worktree/"));
305+
cl_git_pass(git_worktree_add(&worktree, sm, "repo-worktree", path.ptr));
306+
cl_git_pass(git_repository_open_from_worktree(&wt, worktree));
307+
308+
cl_assert_equal_s(path.ptr, wt->workdir);
309+
cl_assert_equal_s(sm->commondir, wt->commondir);
310+
311+
cl_git_pass(git_buf_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/"));
312+
cl_assert_equal_s(path.ptr, wt->gitdir);
313+
314+
git_buf_free(&path);
315+
git_worktree_free(worktree);
316+
git_repository_free(sm);
317+
git_repository_free(wt);
318+
}
319+
292320
void test_worktree_worktree__validate(void)
293321
{
294322
git_worktree *wt;

0 commit comments

Comments
 (0)