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>
Nguyễn Thái Ngọc Duy committed
Feb 12, 2018 at 16:49 UTC
9c620fc7a60c64e183a661f4df4f7b9e25501099
2 files changed
+23
worktree.c
+17
@@ -326,6 +326,23 @@ done:
326
return ret;
327
}
328
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
+
346
int is_worktree_being_rebased(const struct worktree *wt,
347
const char *target)
348
{
worktree.h
+6
@@ -68,6 +68,12 @@ extern const char *is_worktree_locked(struct worktree *wt);
68
extern int validate_worktree(const struct worktree *wt,
69
struct strbuf *errmsg);
70
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
+
77
/*
78
* Free up the memory for worktree(s)
79
*/