worktree.c: add update_worktree_location()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2018-02-12 16:49:35 +07:00 committed by Junio C Hamano
parent 4ddddc1f1d
commit 9c620fc7a6
2 changed files with 23 additions and 0 deletions

View File

@ -326,6 +326,23 @@ done:
return ret; return ret;
} }
void update_worktree_location(struct worktree *wt, const char *path_)
{
struct strbuf path = STRBUF_INIT;
if (is_main_worktree(wt))
die("BUG: can't relocate main worktree");
strbuf_realpath(&path, path_, 1);
if (fspathcmp(wt->path, path.buf)) {
write_file(git_common_path("worktrees/%s/gitdir", wt->id),
"%s/.git", path.buf);
free(wt->path);
wt->path = strbuf_detach(&path, NULL);
}
strbuf_release(&path);
}
int is_worktree_being_rebased(const struct worktree *wt, int is_worktree_being_rebased(const struct worktree *wt,
const char *target) const char *target)
{ {

View File

@ -68,6 +68,12 @@ extern const char *is_worktree_locked(struct worktree *wt);
extern int validate_worktree(const struct worktree *wt, extern int validate_worktree(const struct worktree *wt,
struct strbuf *errmsg); struct strbuf *errmsg);
/*
* Update worktrees/xxx/gitdir with the new path.
*/
extern void update_worktree_location(struct worktree *wt,
const char *path_);
/* /*
* Free up the memory for worktree(s) * Free up the memory for worktree(s)
*/ */