git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 07/10] worktree.c: add update_worktree_location()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jun 25, 2016, 07:54 UTC
Message-ID
<20160625075433.4608-8-pclouds@gmail.com>
In-Reply-To
<20160625075433.4608-1-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 worktree.c | 25 +++++++++++++++++++++++++
 worktree.h |  6 ++++++
 2 files changed, 31 insertions(+)
diff --git a/worktree.c b/worktree.c
index d5149d8..9b227a4 100644
--- a/worktree.c
+++ b/worktree.c
@@ -354,6 +354,31 @@ int validate_worktree(const struct worktree *wt, int quiet)
 	return 0;
 }
 
+int update_worktree_location(struct worktree *wt, const char *path_)
+{
+	struct strbuf path = STRBUF_INIT;
+	int ret = 0;
+
+	if (is_main_worktree(wt))
+		return 0;
+
+	strbuf_add_absolute_path(&path, path_);
+	if (fspathcmp(wt->path, path.buf)) {
+		if (!write_file_gently(git_common_path("worktrees/%s/gitdir",
+						       wt->id),
+				       "%s/.git", real_path(path.buf))) {
+			free(wt->path);
+			wt->path = strbuf_detach(&path, NULL);
+			ret = 0;
+		} else
+			ret = error_errno(_("failed to update '%s'"),
+					  git_common_path("worktrees/%s/gitdir",
+							  wt->id));
+	}
+	strbuf_release(&path);
+	return ret;
+}
+
 int is_worktree_being_rebased(const struct worktree *wt,
 			      const char *target)
 {
diff --git a/worktree.h b/worktree.h
index e782ae5..0477a3d 100644
--- a/worktree.h
+++ b/worktree.h
@@ -55,6 +55,12 @@ extern const char *is_worktree_locked(struct worktree *wt);
  */
 extern int validate_worktree(const struct worktree *wt, int quiet);
 
+/*
+ * Update worktrees/xxx/gitdir with the new path.
+ */
+extern int update_worktree_location(struct worktree *wt,
+				    const char *path_);
+
 /*
  * Free up the memory for worktree(s)
  */
-- 
2.8.2.526.g02eed6d
Previous: Eric SunshineNext: Eric Sunshine
Message 13 of 16 in “git worktree (re)move”
  1. 00/10 git worktree (re)moveNguyễn Thái Ngọc Duy, Jun 25, 2016
  2. 04/10 copy.c: style fixNguyễn Thái Ngọc Duy, Jun 25, 2016
  3. 02/10 copy.c: delete unused code in copy_file()Nguyễn Thái Ngọc Duy, Jun 25, 2016
  4. 09/10 worktree move: accept destination as directoryNguyễn Thái Ngọc Duy, Jun 25, 2016
  5. 05/10 copy.c: convert copy_file() to copy_dir_recursively()Nguyễn Thái Ngọc Duy, Jun 25, 2016
  6. Eric SunshineAug 1, 2017
  7. 01/10 copy.c: import copy_file() from busyboxNguyễn Thái Ngọc Duy, Jun 25, 2016
  8. 10/10 worktree: add "remove" commandNguyễn Thái Ngọc Duy, Jun 25, 2016
  9. Eric SunshineAug 1, 2017
  10. 06/10 worktree.c: add validate_worktree()Nguyễn Thái Ngọc Duy, Jun 25, 2016
  11. 08/10 worktree: add "move" commmandNguyễn Thái Ngọc Duy, Jun 25, 2016
  12. Eric SunshineAug 1, 2017
  13. 07/10 worktree.c: add update_worktree_location()Nguyễn Thái Ngọc Duy, Jun 25, 2016
  14. Eric SunshineAug 1, 2017
  15. 03/10 copy.c: convert bb_(p)error_msg to error(_errno)Nguyễn Thái Ngọc Duy, Jun 25, 2016
  16. Duy NguyenJul 23, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.