Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 worktree.c | 15 ++++++++++++++-
 worktree.h |  7 +++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/worktree.c b/worktree.c
index a11c053..d4513b1 100644
--- a/worktree.c
+++ b/worktree.c
@@ -237,13 +237,26 @@ int update_worktree_location(struct worktree *wt, const 
char *path_)
                        wt->path = strbuf_detach(&path, NULL);
                        ret = 0;
                } else
-                       ret = sys_error(_("failed to update '%s' for update"),
+                       ret = sys_error(_("failed to update '%s'"),
                                        git_common_path("worktrees/%s/gitdir", 
wt->id));
        }
        strbuf_release(&path);
        return ret;
 }
 
+int update_worktree_gitfile(const char *gitfile,
+                           const char *repo_path,
+                           const char *id)
+{
+       if (!id)
+               return error(_("cannot update .git of main worktree"));
+
+       if (write_file_gently(gitfile, "gitdir: %s/worktrees/%s", 
real_path(repo_path), id))
+               return sys_error(_("failed to update '%s'"), gitfile);
+
+       return 0;
+}
+
 char *find_shared_symref(const char *symref, const char *target)
 {
        char *existing = NULL;
diff --git a/worktree.h b/worktree.h
index 4c0395a..55f3449 100644
--- a/worktree.h
+++ b/worktree.h
@@ -45,6 +45,13 @@ extern int update_worktree_location(struct worktree *wt,
                                    const char *path_);
 
 /*
+ * Update .git file to point to the new repository's location.
+ */
+extern int update_worktree_gitfile(const char *gitfile,
+                                  const char *repo_path,
+                                  const char *id);
+
+/*
  * Free up the memory for worktree
  */
 extern void clear_worktree(struct worktree *);
-- 
2.7.0.377.g4cd97dd

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to