diff options
| author | Patrick Steinhardt <ps@pks.im> | 2017-03-17 08:13:59 +0100 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2017-03-17 09:27:56 +0100 |
| commit | 8f154be3eb04c44755e7b0a5020dc9b82c0c1f24 (patch) | |
| tree | fce9133fe9bbf98157d7efa35a9bd2d128085cde /src/worktree.c | |
| parent | 7cf7a407497dab6978ca6b8fc68713e2a50eb803 (diff) | |
| download | libgit2-8f154be3eb04c44755e7b0a5020dc9b82c0c1f24.tar.gz | |
worktree: write resolved paths into link files
The three link files "worktree/.git", ".git/worktrees/<name>/commondir"
and ".git/worktrees/<name>/gitdir" should always contain absolute and
resolved paths. Adjust the logic creating new worktrees to first use
`git_path_prettify_dir` before writing out these files, so that paths
are resolved first.
Diffstat (limited to 'src/worktree.c')
| -rw-r--r-- | src/worktree.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/worktree.c b/src/worktree.c index 2b0ebfb83..393a088fe 100644 --- a/src/worktree.c +++ b/src/worktree.c @@ -272,7 +272,7 @@ out: int git_worktree_add(git_worktree **out, git_repository *repo, const char *name, const char *worktree) { - git_buf gitdir = GIT_BUF_INIT, buf = GIT_BUF_INIT; + git_buf gitdir = GIT_BUF_INIT, wddir = GIT_BUF_INIT, buf = GIT_BUF_INIT; git_reference *ref = NULL, *head = NULL; git_commit *commit = NULL; git_repository *wt = NULL; @@ -293,23 +293,27 @@ int git_worktree_add(git_worktree **out, git_repository *repo, const char *name, goto out; if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0) goto out; + if ((err = git_path_prettify_dir(&gitdir, gitdir.ptr, NULL)) < 0) + goto out; /* Create worktree work dir */ if ((err = git_futils_mkdir(worktree, 0755, GIT_MKDIR_EXCL)) < 0) goto out; + if ((err = git_path_prettify_dir(&wddir, worktree, NULL)) < 0) + goto out; /* Create worktree .git file */ if ((err = git_buf_printf(&buf, "gitdir: %s\n", gitdir.ptr)) < 0) goto out; - if ((err = write_wtfile(worktree, ".git", &buf)) < 0) + if ((err = write_wtfile(wddir.ptr, ".git", &buf)) < 0) goto out; /* Create gitdir files */ - if ((err = git_buf_sets(&buf, repo->commondir)) < 0 + if ((err = git_path_prettify_dir(&buf, repo->commondir, NULL) < 0) || (err = git_buf_putc(&buf, '\n')) < 0 || (err = write_wtfile(gitdir.ptr, "commondir", &buf)) < 0) goto out; - if ((err = git_buf_joinpath(&buf, worktree, ".git")) < 0 + if ((err = git_buf_joinpath(&buf, wddir.ptr, ".git")) < 0 || (err = git_buf_putc(&buf, '\n')) < 0 || (err = write_wtfile(gitdir.ptr, "gitdir", &buf)) < 0) goto out; @@ -325,7 +329,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo, const char *name, /* Set worktree's HEAD */ if ((err = git_repository_create_head(gitdir.ptr, git_reference_name(ref))) < 0) goto out; - if ((err = git_repository_open(&wt, worktree)) < 0) + if ((err = git_repository_open(&wt, wddir.ptr)) < 0) goto out; /* Checkout worktree's HEAD */ @@ -339,6 +343,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo, const char *name, out: git_buf_free(&gitdir); + git_buf_free(&wddir); git_buf_free(&buf); git_reference_free(ref); git_reference_free(head); |
