|
1 | 1 | #include "clar_libgit2.h" |
2 | 2 | #include "worktree_helpers.h" |
| 3 | +#include "submodule/submodule_helpers.h" |
3 | 4 |
|
4 | 5 | #include "checkout.h" |
5 | 6 | #include "repository.h" |
@@ -289,6 +290,33 @@ void test_worktree_worktree__init_existing_path(void) |
289 | 290 | git_buf_free(&path); |
290 | 291 | } |
291 | 292 |
|
| 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 | + |
292 | 320 | void test_worktree_worktree__validate(void) |
293 | 321 | { |
294 | 322 | git_worktree *wt; |
|
0 commit comments