diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-03-15 15:29:29 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-03-17 09:27:55 +0100 |
commit | 20a368e2d72e65b6401f18a440c24df0dd9683ae (patch) | |
tree | e04e2eca7adcddfe49a457dd772631330c789bbe | |
parent | 3017ba94a33a5dae07521afd96a94e21afb07b8c (diff) | |
download | libgit2-20a368e2d72e65b6401f18a440c24df0dd9683ae.tar.gz |
worktree: parent path should point to the working dir
The working tree's parent path should not point to the parent's gitdir,
but to the parent's working directory. Pointing to the gitdir would not
make any sense, as the parent's working directory is actually equal to
both repository's common directory.
Fix the issue.
-rw-r--r-- | src/worktree.c | 6 | ||||
-rw-r--r-- | src/worktree.h | 2 | ||||
-rw-r--r-- | tests/worktree/worktree.c | 3 |
3 files changed, 6 insertions, 5 deletions
diff --git a/src/worktree.c b/src/worktree.c index 783b183b7..13113f846 100644 --- a/src/worktree.c +++ b/src/worktree.c @@ -174,7 +174,7 @@ int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *na if ((error = git_buf_printf(&path, "%s/worktrees/%s", repo->commondir, name)) < 0) goto out; - if ((error = (open_worktree_dir(out, git_repository_path(repo), path.ptr, name))) < 0) + if ((error = (open_worktree_dir(out, git_repository_workdir(repo), path.ptr, name))) < 0) goto out; out: @@ -202,7 +202,7 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo) gitdir = git_repository_path(repo); commondir = git_repository_commondir(repo); - if ((error = git_path_prettify_dir(&parent, commondir, NULL)) < 0) + if ((error = git_path_prettify_dir(&parent, "..", commondir)) < 0) goto out; /* The name is defined by the last component in '.git/worktree/%s' */ @@ -457,7 +457,7 @@ int git_worktree_prune(git_worktree *wt, unsigned flags) } /* Delete gitdir in parent repository */ - if ((err = git_buf_printf(&path, "%s/worktrees/%s", wt->parent_path, wt->name)) < 0) + if ((err = git_buf_printf(&path, "%s/worktrees/%s", wt->commondir_path, wt->name)) < 0) goto out; if (!git_path_exists(path.ptr)) { diff --git a/src/worktree.h b/src/worktree.h index b8e527968..57c2e65f0 100644 --- a/src/worktree.h +++ b/src/worktree.h @@ -24,7 +24,7 @@ struct git_worktree { /* Path to the common directory contained in the parent * repository */ char *commondir_path; - /* Path to the parent's .git directory */ + /* Path to the parent's working directory */ char *parent_path; int locked:1; diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c index 86554c56a..e74647f54 100644 --- a/tests/worktree/worktree.c +++ b/tests/worktree/worktree.c @@ -118,8 +118,9 @@ void test_worktree_worktree__lookup(void) cl_git_pass(git_buf_joinpath(&gitdir_path, fixture.repo->commondir, "worktrees/testrepo-worktree/")); cl_assert_equal_s(wt->gitdir_path, gitdir_path.ptr); - cl_assert_equal_s(wt->parent_path, fixture.repo->gitdir); + cl_assert_equal_s(wt->parent_path, fixture.repo->workdir); cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink); + cl_assert_equal_s(wt->commondir_path, fixture.repo->gitdir); cl_assert_equal_s(wt->commondir_path, fixture.repo->commondir); git_buf_free(&gitdir_path); |