Skip to content

Commit 9c620fc

Browse files
pcloudsgitster
authored andcommitted
worktree.c: add update_worktree_location()
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4ddddc1 commit 9c620fc

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

worktree.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,23 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg)
326326
return ret;
327327
}
328328

329+
void update_worktree_location(struct worktree *wt, const char *path_)
330+
{
331+
struct strbuf path = STRBUF_INIT;
332+
333+
if (is_main_worktree(wt))
334+
die("BUG: can't relocate main worktree");
335+
336+
strbuf_realpath(&path, path_, 1);
337+
if (fspathcmp(wt->path, path.buf)) {
338+
write_file(git_common_path("worktrees/%s/gitdir", wt->id),
339+
"%s/.git", path.buf);
340+
free(wt->path);
341+
wt->path = strbuf_detach(&path, NULL);
342+
}
343+
strbuf_release(&path);
344+
}
345+
329346
int is_worktree_being_rebased(const struct worktree *wt,
330347
const char *target)
331348
{

worktree.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ extern const char *is_worktree_locked(struct worktree *wt);
6868
extern int validate_worktree(const struct worktree *wt,
6969
struct strbuf *errmsg);
7070

71+
/*
72+
* Update worktrees/xxx/gitdir with the new path.
73+
*/
74+
extern void update_worktree_location(struct worktree *wt,
75+
const char *path_);
76+
7177
/*
7278
* Free up the memory for worktree(s)
7379
*/

0 commit comments

Comments
 (0)