{"thread":{"id":"62407","subject":"[PATCH v3 0/5] Optionally link worktrees with relative paths","startedAt":"2024-10-25T20:57:26Z","lastAt":"2024-10-25T22:35:04Z","messageCount":11,"participants":["Caleb White","Taylor Blau"],"isPatch":true,"patchVersion":3,"patchTotal":5},"messages":[{"id":"506113","messageId":"20241025-wt_relative_paths-v3-0-8860a5321c01@pm.me","threadId":"62407","inReplyTo":null,"subject":"[PATCH v3 0/5] Optionally link worktrees with relative paths","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T20:57:17Z","receivedAt":"2024-10-25T20:57:26Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"Git stores absolute paths when linking worktrees to the main repository.\nHowever, this can cause problems when moving repositories and worktrees,\nor when working in containerized environments where absolute paths\ndiffer between systems. The worktree links break, and users are required\nto manually execute `worktree repair` to repair them, leading to workflow\ndisruptions. Additionally, when repositories are mapped inside containers\nwith different absolute paths, they may become unusable. Repairing\nworktrees in the container can then break them outside the container.\n\nIn some cases, relative paths can eliminate the need for `worktree repair`.\nIf both the repository and worktrees are moved together while preserving\ntheir relative locations, the links remain intact. Common examples include\nmanually moving repositories and worktrees (or by tarballing) or mapping\nboth inside containers that use different absolute paths.\n\nThis patch series introduces the option to link worktrees with relative\npaths via the `--relative-paths` argument or the `worktree.useRelativePaths`\nconfig option. Relative paths improve the resilience of worktree links\nacross systems, especially when worktrees are self-contained in the main\nrepository (e.g., bare repositories). This enhances portability, improves\nworkflow efficiency, and reduces the need for manual repair.\n\nGit now supports both absolute and relative paths ensuring backwards\ncompatibility and offering the flexibility of relative paths when desired.\n\nSigned-off-by: Caleb White <cdwhite3@pm.me>\n---\nThe base for this patch series is obtained by applying the following\npatches onto v2.47.0 (777489f9e0):\n- <20241021-cleanup-extension-docs-v1-1-ab02cece3132@pm.me> (doc:\n  consolidate extensions in git-config documentation, 2024-10-22)\n- es/worktree-repair-copied topic (worktree: repair copied repository\n  and linked worktrees, 2024-09-23, <20240923075416.54289-1-ericsunshine@charter.net>)\n\nChanges in v4:\n- Added <20241021-cleanup-extension-docs-v1-1-ab02cece3132@pm.me> to base\n- Updated title to better reflect added functionality.\n- Added more test cases\n- Added `--relative-paths` option to `git worktree {add,repair}`\n- Added `worktree.useRelativePaths` config option.\n- Added `relativeWorktrees` extension to prevent older git versions\n  from operating on worktrees with relative paths.\n- Split patch [2/3] into two patches for easier review: the first\n  handles reading potentially relative paths from the files, and the\n  second add the cli/config options and handles writing the relative\n  paths to the linking files.\n- Patch [1/3]: updated infer_backlink() to return -1 on error and\n  strbuf.len on success, removed superfluous brackets, added docs,\n  updated commit message.\n- Improved cover letter and commit messages.\n- Added instructions on how to construct the base in the cover letter.\n- Link to v3: https://lore.kernel.org/git/20241007-wt_relative_paths-v3-0-622cf18c45eb@pm.me\nChanges in v3:\n- Squashed patch [3/4] into patch [2/4] to streamline changes.\n- Dropped patch [4/4] as it was no longer necessary.\n- Rebased onto 20240923075416.54289-1-ericsunshine@charter.net\n- Updated `infer_backlink()` to return 1 on success for consistency.\n- Swapped the order of `infer_backlink()` arguments for clarity.\n- Clear `inferred` if error occurs in `infer_backlink()`.\n- Renamed `git_contents` to `dotgit_contents` for clearer semantics.\n- Cleaned up `dotgit_contents` logic in `repair_worktree_at_path()`.\n- Replaced multiple `xstrfmt/free` calls with a single `strbuf`.\n- Added a test case covering a failure noted in a separate patch series.\n- Improved commit messages.\n- Link to v2: https://lore.kernel.org/r/20241006060017.171788-1-cdwhite3@pm.me\nChanges in v2:\n- No changes, just a resubmission\n- Link to v1: https://lore.kernel.org/git/20241006045847.159937-1-cdwhite3@pm.me/\n\n---\nCaleb White (5):\n      worktree: refactor infer_backlink() to use strbuf*\n      worktree: support worktrees linked with relative paths\n      worktree: optionally link worktrees with relative paths\n      worktree: add test for path handling in linked worktrees\n      worktree: add `relativeWorktrees` extension\n\n Documentation/config/extensions.txt |   6 +\n Documentation/config/worktree.txt   |   5 +\n Documentation/git-worktree.txt      |   9 ++\n builtin/worktree.c                  |  18 ++-\n repository.c                        |   1 +\n repository.h                        |   1 +\n setup.c                             |   9 +-\n setup.h                             |   1 +\n t/t0001-init.sh                     |  20 ++-\n t/t2400-worktree-add.sh             |  54 +++++++\n t/t2401-worktree-prune.sh           |  20 +++\n t/t2402-worktree-list.sh            |  22 +++\n t/t2403-worktree-move.sh            |  22 +++\n t/t2406-worktree-repair.sh          |  26 ++++\n worktree.c                          | 283 ++++++++++++++++++++++++++----------\n worktree.h                          |  24 +++\n 16 files changed, 433 insertions(+), 88 deletions(-)\n---\nbase-commit: 4ec4435df758668055cc904ef64c275bc8d1089b\nchange-id: 20241007-wt_relative_paths-88f9cf5a070c\nprerequisite-change-id: 20241020-cleanup-extension-docs-f365868711bf:v1\nprerequisite-patch-id: 60a443b24e92938b9b6f4a016a7bab87e13bf3ea\nprerequisite-message-id: <20240923075416.54289-1-ericsunshine@charter.net>\nprerequisite-patch-id: 78371f4dbb635e6edab8c51ee7857b903e60df8f\n\nBest regards,\n-- \nCaleb White <cdwhite3@pm.me>\n\n\n"},{"id":"506114","messageId":"20241025-wt_relative_paths-v3-1-8860a5321c01@pm.me","threadId":"62407","inReplyTo":"20241025-wt_relative_paths-v3-0-8860a5321c01@pm.me","subject":"[PATCH v3 1/5] worktree: refactor infer_backlink() to use strbuf*","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T20:57:25Z","receivedAt":"2024-10-25T20:57:31Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"The infer_backlink() function initializes a `strbuf` for the inferred\nbacklink and returns the result as a `char*` by detaching the `strbuf`.\n\nThe next patch needs the backlink returned from infer_backlink() as a\n`strbuf`. It seemed inefficient to convert from `strbuf` to `char*`\nand back to `strbuf` again. This refactors infer_backlink() to return\nan integer result and accept a pre-allocated `strbuf` for the inferred\nbacklink path, improving efficiency.\n\nSigned-off-by: Caleb White <cdwhite3@pm.me>\n---\n worktree.c | 52 ++++++++++++++++++++++++++--------------------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/worktree.c b/worktree.c\nindex ec95ea2986107b3bc12d38b0825d7c6e87402bc6..ad60ba0b5843f1676e89b05eca3c82aace5fb49b 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -641,13 +641,15 @@ static int is_main_worktree_path(const char *path)\n  * won't know which <repo>/worktrees/<id>/gitdir to repair. However, we may\n  * be able to infer the gitdir by manually reading /path/to/worktree/.git,\n  * extracting the <id>, and checking if <repo>/worktrees/<id> exists.\n+ *\n+ * Returns -1 on failure and strbuf.len on success.\n  */\n-static char *infer_backlink(const char *gitfile)\n+static int infer_backlink(const char *gitfile, struct strbuf *inferred)\n {\n \tstruct strbuf actual = STRBUF_INIT;\n-\tstruct strbuf inferred = STRBUF_INIT;\n \tconst char *id;\n \n+\tstrbuf_reset(inferred);\n \tif (strbuf_read_file(&actual, gitfile, 0) < 0)\n \t\tgoto error;\n \tif (!starts_with(actual.buf, \"gitdir:\"))\n@@ -658,17 +660,16 @@ static char *infer_backlink(const char *gitfile)\n \tid++; /* advance past '/' to point at <id> */\n \tif (!*id)\n \t\tgoto error;\n-\tstrbuf_git_common_path(&inferred, the_repository, \"worktrees/%s\", id);\n-\tif (!is_directory(inferred.buf))\n+\tstrbuf_git_common_path(inferred, the_repository, \"worktrees/%s\", id);\n+\tif (!is_directory(inferred->buf))\n \t\tgoto error;\n \n \tstrbuf_release(&actual);\n-\treturn strbuf_detach(&inferred, NULL);\n-\n+\treturn inferred->len;\n error:\n \tstrbuf_release(&actual);\n-\tstrbuf_release(&inferred);\n-\treturn NULL;\n+\tstrbuf_reset(inferred); /* clear invalid path */\n+\treturn -1;\n }\n \n /*\n@@ -680,10 +681,11 @@ void repair_worktree_at_path(const char *path,\n {\n \tstruct strbuf dotgit = STRBUF_INIT;\n \tstruct strbuf realdotgit = STRBUF_INIT;\n+\tstruct strbuf backlink = STRBUF_INIT;\n+\tstruct strbuf inferred_backlink = STRBUF_INIT;\n \tstruct strbuf gitdir = STRBUF_INIT;\n \tstruct strbuf olddotgit = STRBUF_INIT;\n-\tchar *backlink = NULL;\n-\tchar *inferred_backlink = NULL;\n+\tchar *dotgit_contents = NULL;\n \tconst char *repair = NULL;\n \tint err;\n \n@@ -699,23 +701,23 @@ void repair_worktree_at_path(const char *path,\n \t\tgoto done;\n \t}\n \n-\tinferred_backlink = infer_backlink(realdotgit.buf);\n-\tbacklink = xstrdup_or_null(read_gitfile_gently(realdotgit.buf, &err));\n-\tif (err == READ_GITFILE_ERR_NOT_A_FILE) {\n+\tinfer_backlink(realdotgit.buf, &inferred_backlink);\n+\tdotgit_contents = xstrdup_or_null(read_gitfile_gently(realdotgit.buf, &err));\n+\tif (dotgit_contents) {\n+\t\tstrbuf_addstr(&backlink, dotgit_contents);\n+\t} else if (err == READ_GITFILE_ERR_NOT_A_FILE) {\n \t\tfn(1, realdotgit.buf, _(\"unable to locate repository; .git is not a file\"), cb_data);\n \t\tgoto done;\n \t} else if (err == READ_GITFILE_ERR_NOT_A_REPO) {\n-\t\tif (inferred_backlink) {\n+\t\tif (inferred_backlink.len) {\n \t\t\t/*\n \t\t\t * Worktree's .git file does not point at a repository\n \t\t\t * but we found a .git/worktrees/<id> in this\n \t\t\t * repository with the same <id> as recorded in the\n \t\t\t * worktree's .git file so make the worktree point at\n-\t\t\t * the discovered .git/worktrees/<id>. (Note: backlink\n-\t\t\t * is already NULL, so no need to free it first.)\n+\t\t\t * the discovered .git/worktrees/<id>.\n \t\t\t */\n-\t\t\tbacklink = inferred_backlink;\n-\t\t\tinferred_backlink = NULL;\n+\t\t\tstrbuf_swap(&backlink, &inferred_backlink);\n \t\t} else {\n \t\t\tfn(1, realdotgit.buf, _(\"unable to locate repository; .git file does not reference a repository\"), cb_data);\n \t\t\tgoto done;\n@@ -743,13 +745,10 @@ void repair_worktree_at_path(const char *path,\n \t * in the \"copy\" repository. In this case, point the \"copy\" worktree's\n \t * .git file at the \"copy\" repository.\n \t */\n-\tif (inferred_backlink && fspathcmp(backlink, inferred_backlink)) {\n-\t\tfree(backlink);\n-\t\tbacklink = inferred_backlink;\n-\t\tinferred_backlink = NULL;\n-\t}\n+\tif (inferred_backlink.len && fspathcmp(backlink.buf, inferred_backlink.buf))\n+\t\tstrbuf_swap(&backlink, &inferred_backlink);\n \n-\tstrbuf_addf(&gitdir, \"%s/gitdir\", backlink);\n+\tstrbuf_addf(&gitdir, \"%s/gitdir\", backlink.buf);\n \tif (strbuf_read_file(&olddotgit, gitdir.buf, 0) < 0)\n \t\trepair = _(\"gitdir unreadable\");\n \telse {\n@@ -763,9 +762,10 @@ void repair_worktree_at_path(const char *path,\n \t\twrite_file(gitdir.buf, \"%s\", realdotgit.buf);\n \t}\n done:\n-\tfree(backlink);\n-\tfree(inferred_backlink);\n+\tfree(dotgit_contents);\n \tstrbuf_release(&olddotgit);\n+\tstrbuf_release(&backlink);\n+\tstrbuf_release(&inferred_backlink);\n \tstrbuf_release(&gitdir);\n \tstrbuf_release(&realdotgit);\n \tstrbuf_release(&dotgit);\n\n-- \n2.47.0\n\n\n"},{"id":"506115","messageId":"20241025-wt_relative_paths-v3-2-8860a5321c01@pm.me","threadId":"62407","inReplyTo":"20241025-wt_relative_paths-v3-0-8860a5321c01@pm.me","subject":"[PATCH v3 2/5] worktree: support worktrees linked with relative paths","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T20:57:32Z","receivedAt":"2024-10-25T20:57:45Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"Git stores absolute paths when linking worktrees to the main repository.\nHowever, this can cause problems when moving repositories and worktrees,\nor when working in containerized environments where absolute paths\ndiffer between systems. The worktree links break, and users are required\nto manually execute `worktree repair` to repair them, leading to workflow\ndisruptions. Additionally, when repositories are mapped inside containers\nwith different absolute paths, they may become unusable. Repairing\nworktrees in the container can then break them outside the container.\n\nIn some cases, relative paths can eliminate the need for `worktree repair`.\nIf both the repository and worktrees are moved together while preserving\ntheir relative locations, the links remain intact. Common examples include\nmanually moving repositories and worktrees (or by tarballing) or mapping\nboth inside containers that use different absolute paths.\n\nThis patch adds support for _reading_ linking files which could contain\nrelative paths (computing and _writing_ the relative paths will come in\nthe next patch). Generally, relative paths are resolved into absolute\npaths before any operations or comparisons are performed.\n\nThe `worktree.path` struct member has also been updated to always contain\nthe absolute path of a worktree. This ensures that worktree consumers\nnever have to worry about trying to resolve the absolute path themselves.\n\nSigned-off-by: Caleb White <cdwhite3@pm.me>\n---\n worktree.c | 131 +++++++++++++++++++++++++++++++++++++++++++------------------\n 1 file changed, 92 insertions(+), 39 deletions(-)\n\ndiff --git a/worktree.c b/worktree.c\nindex ad60ba0b5843f1676e89b05eca3c82aace5fb49b..cf578c447589425d642fc8aa7a7fa07600e60a70 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -110,6 +110,12 @@ struct worktree *get_linked_worktree(const char *id,\n \tstrbuf_rtrim(&worktree_path);\n \tstrbuf_strip_suffix(&worktree_path, \"/.git\");\n \n+\tif (!is_absolute_path(worktree_path.buf)) {\n+\t\tstrbuf_strip_suffix(&path, \"gitdir\");\n+\t\tstrbuf_addbuf(&path, &worktree_path);\n+\t\tstrbuf_realpath_forgiving(&worktree_path, path.buf, 0);\n+\t}\n+\n \tCALLOC_ARRAY(worktree, 1);\n \tworktree->repo = the_repository;\n \tworktree->path = strbuf_detach(&worktree_path, NULL);\n@@ -564,28 +570,38 @@ static void repair_gitfile(struct worktree *wt,\n {\n \tstruct strbuf dotgit = STRBUF_INIT;\n \tstruct strbuf repo = STRBUF_INIT;\n-\tchar *backlink;\n+\tstruct strbuf backlink = STRBUF_INIT;\n+\tchar *dotgit_contents = NULL;\n \tconst char *repair = NULL;\n \tint err;\n \n \t/* missing worktree can't be repaired */\n \tif (!file_exists(wt->path))\n-\t\treturn;\n+\t\tgoto done;\n \n \tif (!is_directory(wt->path)) {\n \t\tfn(1, wt->path, _(\"not a directory\"), cb_data);\n-\t\treturn;\n+\t\tgoto done;\n \t}\n \n \tstrbuf_realpath(&repo, git_common_path(\"worktrees/%s\", wt->id), 1);\n \tstrbuf_addf(&dotgit, \"%s/.git\", wt->path);\n-\tbacklink = xstrdup_or_null(read_gitfile_gently(dotgit.buf, &err));\n+\tdotgit_contents = xstrdup_or_null(read_gitfile_gently(dotgit.buf, &err));\n+\n+\tif (dotgit_contents) {\n+\t\tif (is_absolute_path(dotgit_contents)) {\n+\t\t\tstrbuf_addstr(&backlink, dotgit_contents);\n+\t\t} else {\n+\t\t\tstrbuf_addf(&backlink, \"%s/%s\", wt->path, dotgit_contents);\n+\t\t\tstrbuf_realpath_forgiving(&backlink, backlink.buf, 0);\n+\t\t}\n+\t}\n \n \tif (err == READ_GITFILE_ERR_NOT_A_FILE)\n \t\tfn(1, wt->path, _(\".git is not a file\"), cb_data);\n \telse if (err)\n \t\trepair = _(\".git file broken\");\n-\telse if (fspathcmp(backlink, repo.buf))\n+\telse if (fspathcmp(backlink.buf, repo.buf))\n \t\trepair = _(\".git file incorrect\");\n \n \tif (repair) {\n@@ -593,9 +609,11 @@ static void repair_gitfile(struct worktree *wt,\n \t\twrite_file(dotgit.buf, \"gitdir: %s\", repo.buf);\n \t}\n \n-\tfree(backlink);\n+done:\n+\tfree(dotgit_contents);\n \tstrbuf_release(&repo);\n \tstrbuf_release(&dotgit);\n+\tstrbuf_release(&backlink);\n }\n \n static void repair_noop(int iserr UNUSED,\n@@ -685,6 +703,7 @@ void repair_worktree_at_path(const char *path,\n \tstruct strbuf inferred_backlink = STRBUF_INIT;\n \tstruct strbuf gitdir = STRBUF_INIT;\n \tstruct strbuf olddotgit = STRBUF_INIT;\n+\tstruct strbuf realolddotgit = STRBUF_INIT;\n \tchar *dotgit_contents = NULL;\n \tconst char *repair = NULL;\n \tint err;\n@@ -702,9 +721,17 @@ void repair_worktree_at_path(const char *path,\n \t}\n \n \tinfer_backlink(realdotgit.buf, &inferred_backlink);\n+\tstrbuf_realpath_forgiving(&inferred_backlink, inferred_backlink.buf, 0);\n \tdotgit_contents = xstrdup_or_null(read_gitfile_gently(realdotgit.buf, &err));\n \tif (dotgit_contents) {\n-\t\tstrbuf_addstr(&backlink, dotgit_contents);\n+\t\tif (is_absolute_path(dotgit_contents)) {\n+\t\t\tstrbuf_addstr(&backlink, dotgit_contents);\n+\t\t} else {\n+\t\t\tstrbuf_addbuf(&backlink, &realdotgit);\n+\t\t\tstrbuf_strip_suffix(&backlink, \".git\");\n+\t\t\tstrbuf_addstr(&backlink, dotgit_contents);\n+\t\t\tstrbuf_realpath_forgiving(&backlink, backlink.buf, 0);\n+\t\t}\n \t} else if (err == READ_GITFILE_ERR_NOT_A_FILE) {\n \t\tfn(1, realdotgit.buf, _(\"unable to locate repository; .git is not a file\"), cb_data);\n \t\tgoto done;\n@@ -722,7 +749,7 @@ void repair_worktree_at_path(const char *path,\n \t\t\tfn(1, realdotgit.buf, _(\"unable to locate repository; .git file does not reference a repository\"), cb_data);\n \t\t\tgoto done;\n \t\t}\n-\t} else if (err) {\n+\t} else {\n \t\tfn(1, realdotgit.buf, _(\"unable to locate repository; .git file broken\"), cb_data);\n \t\tgoto done;\n \t}\n@@ -753,7 +780,13 @@ void repair_worktree_at_path(const char *path,\n \t\trepair = _(\"gitdir unreadable\");\n \telse {\n \t\tstrbuf_rtrim(&olddotgit);\n-\t\tif (fspathcmp(olddotgit.buf, realdotgit.buf))\n+\t\tif (is_absolute_path(olddotgit.buf)) {\n+\t\t\tstrbuf_addbuf(&realolddotgit, &olddotgit);\n+\t\t} else {\n+\t\t\tstrbuf_addf(&realolddotgit, \"%s/%s\", backlink.buf, olddotgit.buf);\n+\t\t\tstrbuf_realpath_forgiving(&realolddotgit, realolddotgit.buf, 0);\n+\t\t}\n+\t\tif (fspathcmp(realolddotgit.buf, realdotgit.buf))\n \t\t\trepair = _(\"gitdir incorrect\");\n \t}\n \n@@ -764,6 +797,7 @@ void repair_worktree_at_path(const char *path,\n done:\n \tfree(dotgit_contents);\n \tstrbuf_release(&olddotgit);\n+\tstrbuf_release(&realolddotgit);\n \tstrbuf_release(&backlink);\n \tstrbuf_release(&inferred_backlink);\n \tstrbuf_release(&gitdir);\n@@ -774,69 +808,88 @@ void repair_worktree_at_path(const char *path,\n int should_prune_worktree(const char *id, struct strbuf *reason, char **wtpath, timestamp_t expire)\n {\n \tstruct stat st;\n-\tchar *path;\n+\tstruct strbuf dotgit = STRBUF_INIT;\n+\tstruct strbuf gitdir = STRBUF_INIT;\n+\tstruct strbuf repo = STRBUF_INIT;\n+\tstruct strbuf file = STRBUF_INIT;\n+\tchar *path = NULL;\n+\tint rc = 0;\n \tint fd;\n \tsize_t len;\n \tssize_t read_result;\n \n \t*wtpath = NULL;\n-\tif (!is_directory(git_path(\"worktrees/%s\", id))) {\n+\tstrbuf_realpath(&repo, git_common_path(\"worktrees/%s\", id), 1);\n+\tstrbuf_addf(&gitdir, \"%s/gitdir\", repo.buf);\n+\tif (!is_directory(repo.buf)) {\n \t\tstrbuf_addstr(reason, _(\"not a valid directory\"));\n-\t\treturn 1;\n+\t\trc = 1;\n+\t\tgoto done;\n \t}\n-\tif (file_exists(git_path(\"worktrees/%s/locked\", id)))\n-\t\treturn 0;\n-\tif (stat(git_path(\"worktrees/%s/gitdir\", id), &st)) {\n+\tstrbuf_addf(&file, \"%s/locked\", repo.buf);\n+\tif (file_exists(file.buf)) {\n+\t\tgoto done;\n+\t}\n+\tif (stat(gitdir.buf, &st)) {\n \t\tstrbuf_addstr(reason, _(\"gitdir file does not exist\"));\n-\t\treturn 1;\n+\t\trc = 1;\n+\t\tgoto done;\n \t}\n-\tfd = open(git_path(\"worktrees/%s/gitdir\", id), O_RDONLY);\n+\tfd = open(gitdir.buf, O_RDONLY);\n \tif (fd < 0) {\n \t\tstrbuf_addf(reason, _(\"unable to read gitdir file (%s)\"),\n \t\t\t    strerror(errno));\n-\t\treturn 1;\n+\t\trc = 1;\n+\t\tgoto done;\n \t}\n \tlen = xsize_t(st.st_size);\n \tpath = xmallocz(len);\n \n \tread_result = read_in_full(fd, path, len);\n+\tclose(fd);\n \tif (read_result < 0) {\n \t\tstrbuf_addf(reason, _(\"unable to read gitdir file (%s)\"),\n \t\t\t    strerror(errno));\n-\t\tclose(fd);\n-\t\tfree(path);\n-\t\treturn 1;\n-\t}\n-\tclose(fd);\n-\n-\tif (read_result != len) {\n+\t\trc = 1;\n+\t\tgoto done;\n+\t} else if (read_result != len) {\n \t\tstrbuf_addf(reason,\n \t\t\t    _(\"short read (expected %\"PRIuMAX\" bytes, read %\"PRIuMAX\")\"),\n \t\t\t    (uintmax_t)len, (uintmax_t)read_result);\n-\t\tfree(path);\n-\t\treturn 1;\n+\t\trc = 1;\n+\t\tgoto done;\n \t}\n \twhile (len && (path[len - 1] == '\\n' || path[len - 1] == '\\r'))\n \t\tlen--;\n \tif (!len) {\n \t\tstrbuf_addstr(reason, _(\"invalid gitdir file\"));\n-\t\tfree(path);\n-\t\treturn 1;\n+\t\trc = 1;\n+\t\tgoto done;\n \t}\n \tpath[len] = '\\0';\n-\tif (!file_exists(path)) {\n-\t\tif (stat(git_path(\"worktrees/%s/index\", id), &st) ||\n-\t\t    st.st_mtime <= expire) {\n+\tif (is_absolute_path(path)) {\n+\t\tstrbuf_addstr(&dotgit, path);\n+\t} else {\n+\t\tstrbuf_addf(&dotgit, \"%s/%s\", repo.buf, path);\n+\t\tstrbuf_realpath_forgiving(&dotgit, dotgit.buf, 0);\n+\t}\n+\tif (!file_exists(dotgit.buf)) {\n+\t\tstrbuf_reset(&file);\n+\t\tstrbuf_addf(&file, \"%s/index\", repo.buf);\n+\t\tif (stat(file.buf, &st) || st.st_mtime <= expire) {\n \t\t\tstrbuf_addstr(reason, _(\"gitdir file points to non-existent location\"));\n-\t\t\tfree(path);\n-\t\t\treturn 1;\n-\t\t} else {\n-\t\t\t*wtpath = path;\n-\t\t\treturn 0;\n+\t\t\trc = 1;\n+\t\t\tgoto done;\n \t\t}\n \t}\n-\t*wtpath = path;\n-\treturn 0;\n+\t*wtpath = strbuf_detach(&dotgit, NULL);\n+done:\n+\tfree(path);\n+\tstrbuf_release(&dotgit);\n+\tstrbuf_release(&gitdir);\n+\tstrbuf_release(&repo);\n+\tstrbuf_release(&file);\n+\treturn rc;\n }\n \n static int move_config_setting(const char *key, const char *value,\n\n-- \n2.47.0\n\n\n"},{"id":"506116","messageId":"20241025-wt_relative_paths-v3-4-8860a5321c01@pm.me","threadId":"62407","inReplyTo":"20241025-wt_relative_paths-v3-0-8860a5321c01@pm.me","subject":"[PATCH v3 4/5] worktree: add test for path handling in linked worktrees","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T20:57:46Z","receivedAt":"2024-10-25T20:57:53Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"A failure scenario reported in an earlier patch series[1] that several\n`git worktree` subcommands failed or misbehaved when invoked from within\nlinked worktrees that used relative paths.\n\nThis adds a test that executes a `worktree prune` command inside both an\ninternally and an externally linked worktree and asserts that the other\nworktree was not pruned.\n\n[1]: https://lore.kernel.org/git/CAPig+cQXFy=xPVpoSq6Wq0pxMRCjS=WbkgdO+3LySPX=q0nPCw@mail.gmail.com/\n\nReported-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Caleb White <cdwhite3@pm.me>\n---\n t/t2401-worktree-prune.sh | 20 ++++++++++++++++++++\n 1 file changed, 20 insertions(+)\n\ndiff --git a/t/t2401-worktree-prune.sh b/t/t2401-worktree-prune.sh\nindex 71aa9bcd620f8a504fe628a2d7332d8b47fd4701..5eb52b9abbf29514dc082c260ebb7a5e8e63aae0 100755\n--- a/t/t2401-worktree-prune.sh\n+++ b/t/t2401-worktree-prune.sh\n@@ -120,4 +120,24 @@ test_expect_success 'prune duplicate (main/linked)' '\n \t! test -d .git/worktrees/wt\n '\n \n+test_expect_success 'not prune proper worktrees inside linked worktree with relative paths' '\n+\ttest_when_finished rm -rf repo wt_ext &&\n+\tgit init repo &&\n+\t(\n+\t    cd repo &&\n+\t    git config worktree.useRelativePaths true &&\n+\t    echo content >file &&\n+\t    git add file &&\n+\t    git commit -m msg &&\n+\t    git worktree add ../wt_ext &&\n+\t    git worktree add wt_int &&\n+\t    cd wt_int &&\n+\t    git worktree prune -v >out &&\n+\t    test_must_be_empty out &&\n+\t    cd ../../wt_ext &&\n+\t    git worktree prune -v >out &&\n+\t    test_must_be_empty out\n+\t)\n+'\n+\n test_done\n\n-- \n2.47.0\n\n\n"},{"id":"506117","messageId":"20241025-wt_relative_paths-v3-3-8860a5321c01@pm.me","threadId":"62407","inReplyTo":"20241025-wt_relative_paths-v3-0-8860a5321c01@pm.me","subject":"[PATCH v3 3/5] worktree: optionally link worktrees with relative paths","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T20:57:40Z","receivedAt":"2024-10-25T20:57:53Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"Git stores absolute paths when linking worktrees to the main repository.\nHowever, this can cause problems when moving repositories and worktrees,\nor when working in containerized environments where absolute paths\ndiffer between systems. The worktree links break, and users are required\nto manually execute `worktree repair` to repair them, leading to workflow\ndisruptions. Additionally, when repositories are mapped inside containers\nwith different absolute paths, they may become unusable. Repairing\nworktrees in the container can then break them outside the container.\n\nIn some cases, relative paths can eliminate the need for `worktree repair`.\nIf both the repository and worktrees are moved together while preserving\ntheir relative locations, the links remain intact. Common examples include\nmoving repositories and worktrees or mapping both inside containers that\nuse different absolute paths.\n\nThis patch adds support for optionally _writing_ relative paths to the\nlinking files. If desired, relative paths can be created through the\n`--relative-paths` CLI option for `worktree {add,move,repair}` as well\nas the `worktree.useRelativePaths` config option. If an existing\nworktree uses absolute paths, executing `worktree {move,repair}` with\nthe relative option will create relative paths (and visa versa).\n\nA new function, `write_worktree_linking_files()` is introduced to clean\nthe actual relative path computation in different locations. The\nfunction accepts a strbuf to the worktree `.git` file and a strbuf to\nthe repository `gitdir` file and then writes the appropriate path to\neach as configured by the user.\n\nAdditionally, `repair_worktrees_after_gitdir_move()` has been introduced\nto address the case where both the `<worktree>/.git` and\n`<repo>/worktrees/<id>/gitdir` links are broken after the gitdir is\nmoved (such as during a re-initialization). This function repairs both\nsides of the worktree link using the old gitdir path to reestablish the\ncorrect paths after a move.\n\nSigned-off-by: Caleb White <cdwhite3@pm.me>\n---\n Documentation/config/worktree.txt |   5 ++\n Documentation/git-worktree.txt    |   9 +++\n builtin/worktree.c                |  18 +++---\n setup.c                           |   2 +-\n t/t0001-init.sh                   |  20 +++++--\n t/t2400-worktree-add.sh           |  41 ++++++++++++++\n t/t2402-worktree-list.sh          |  22 ++++++++\n t/t2403-worktree-move.sh          |  22 ++++++++\n t/t2406-worktree-repair.sh        |  26 +++++++++\n worktree.c                        | 116 +++++++++++++++++++++++++++++++-------\n worktree.h                        |  24 ++++++++\n 11 files changed, 270 insertions(+), 35 deletions(-)\n\ndiff --git a/Documentation/config/worktree.txt b/Documentation/config/worktree.txt\nindex 048e349482df6c892055720eb53cdcd6c327b6ed..d0589c21d034f07f70ca172947520d7d78720cca 100644\n--- a/Documentation/config/worktree.txt\n+++ b/Documentation/config/worktree.txt\n@@ -7,3 +7,8 @@ worktree.guessRemote::\n \tsuch a branch exists, it is checked out and set as \"upstream\"\n \tfor the new branch.  If no such match can be found, it falls\n \tback to creating a new branch from the current HEAD.\n+worktree.useRelativePaths::\n+\tIf set to `true`, the worktree paths will be stored relative to the\n+\trepository’s top-level directory, rather than using absolute paths.\n+\tThis is particularly useful for setups where the repository may be moved\n+\tbetween different locations or environments.\ndiff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt\nindex 70437c815f13852bd2eb862176b8b933e6de0acf..4a6ad481ee1d44b43683bd67881a2771e2b090c7 100644\n--- a/Documentation/git-worktree.txt\n+++ b/Documentation/git-worktree.txt\n@@ -216,6 +216,15 @@ To remove a locked worktree, specify `--force` twice.\n This can also be set up as the default behaviour by using the\n `worktree.guessRemote` config option.\n \n+--[no-]relative-paths::\n+\tThe worktree paths will be stored relative to the repository’s\n+\ttop-level directory, rather than using absolute paths.\n+\tThis is particularly useful for setups where the repository may be moved\n+\tbetween different locations or environments.\n++\n+This can also be set up as the default behaviour by using the\n+`worktree.useRelativePaths` config option.\n+\n --[no-]track::\n \tWhen creating a new branch, if `<commit-ish>` is a branch,\n \tmark it as \"upstream\" from the new branch.  This is the\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex fc31d072a620d7b455d7f150bd3a9e773ee9d4ed..bb06830d6fe82aa97833c6e87f034115dfaa23bd 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -134,6 +134,9 @@ static int git_worktree_config(const char *var, const char *value,\n \tif (!strcmp(var, \"worktree.guessremote\")) {\n \t\tguess_remote = git_config_bool(var, value);\n \t\treturn 0;\n+\t} else if (!strcmp(var, \"worktree.userelativepaths\")) {\n+\t\tuse_relative_paths = git_config_bool(var, value);\n+\t\treturn 0;\n \t}\n \n \treturn git_default_config(var, value, ctx, cb);\n@@ -414,7 +417,7 @@ static int add_worktree(const char *path, const char *refname,\n \t\t\tconst struct add_opts *opts)\n {\n \tstruct strbuf sb_git = STRBUF_INIT, sb_repo = STRBUF_INIT;\n-\tstruct strbuf sb = STRBUF_INIT, realpath = STRBUF_INIT;\n+\tstruct strbuf sb = STRBUF_INIT;\n \tconst char *name;\n \tstruct strvec child_env = STRVEC_INIT;\n \tunsigned int counter = 0;\n@@ -490,11 +493,7 @@ static int add_worktree(const char *path, const char *refname,\n \n \tstrbuf_reset(&sb);\n \tstrbuf_addf(&sb, \"%s/gitdir\", sb_repo.buf);\n-\tstrbuf_realpath(&realpath, sb_git.buf, 1);\n-\twrite_file(sb.buf, \"%s\", realpath.buf);\n-\tstrbuf_realpath(&realpath, repo_get_common_dir(the_repository), 1);\n-\twrite_file(sb_git.buf, \"gitdir: %s/worktrees/%s\",\n-\t\t   realpath.buf, name);\n+\twrite_worktree_linking_files(sb_git, sb);\n \tstrbuf_reset(&sb);\n \tstrbuf_addf(&sb, \"%s/commondir\", sb_repo.buf);\n \twrite_file(sb.buf, \"../..\");\n@@ -582,7 +581,6 @@ static int add_worktree(const char *path, const char *refname,\n \tstrbuf_release(&sb_repo);\n \tstrbuf_release(&sb_git);\n \tstrbuf_release(&sb_name);\n-\tstrbuf_release(&realpath);\n \tfree_worktree(wt);\n \treturn ret;\n }\n@@ -794,6 +792,8 @@ static int add(int ac, const char **av, const char *prefix)\n \t\t\t     PARSE_OPT_NOARG | PARSE_OPT_OPTARG),\n \t\tOPT_BOOL(0, \"guess-remote\", &guess_remote,\n \t\t\t N_(\"try to match the new branch name with a remote-tracking branch\")),\n+\t\tOPT_BOOL(0, \"relative-paths\", &use_relative_paths,\n+\t\t\t N_(\"use relative paths for worktrees\")),\n \t\tOPT_END()\n \t};\n \tint ret;\n@@ -1187,6 +1187,8 @@ static int move_worktree(int ac, const char **av, const char *prefix)\n \t\tOPT__FORCE(&force,\n \t\t\t N_(\"force move even if worktree is dirty or locked\"),\n \t\t\t PARSE_OPT_NOCOMPLETE),\n+\t\tOPT_BOOL(0, \"relative-paths\", &use_relative_paths,\n+\t\t\t N_(\"use relative paths for worktrees\")),\n \t\tOPT_END()\n \t};\n \tstruct worktree **worktrees, *wt;\n@@ -1380,6 +1382,8 @@ static int repair(int ac, const char **av, const char *prefix)\n \tconst char **p;\n \tconst char *self[] = { \".\", NULL };\n \tstruct option options[] = {\n+\t\tOPT_BOOL(0, \"relative-paths\", &use_relative_paths,\n+\t\t\t N_(\"use relative paths for worktrees\")),\n \t\tOPT_END()\n \t};\n \tint rc = 0;\ndiff --git a/setup.c b/setup.c\nindex 94e79b2e487f3faa537547e190acf9b7ea0be3b5..7b648de0279116b381eea46800ad130606926103 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -2420,7 +2420,7 @@ static void separate_git_dir(const char *git_dir, const char *git_link)\n \n \t\tif (rename(src, git_dir))\n \t\t\tdie_errno(_(\"unable to move %s to %s\"), src, git_dir);\n-\t\trepair_worktrees(NULL, NULL);\n+\t\trepair_worktrees_after_gitdir_move(src);\n \t}\n \n \twrite_file(git_link, \"gitdir: %s\", git_dir);\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 0178aa62a41f1606f2382a4a10ab593ccf11e0e8..03ac9624cb418d05adb8dfb786c31b809c73efec 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -435,19 +435,27 @@ sep_git_dir_worktree ()  {\n \ttest_when_finished \"rm -rf mainwt linkwt seprepo\" &&\n \tgit init mainwt &&\n \ttest_commit -C mainwt gumby &&\n-\tgit -C mainwt worktree add --detach ../linkwt &&\n-\tgit -C \"$1\" init --separate-git-dir ../seprepo &&\n+\tgit -C mainwt worktree add $1 --detach ../linkwt &&\n+\tgit -C \"$2\" init --separate-git-dir ../seprepo &&\n \tgit -C mainwt rev-parse --git-common-dir >expect &&\n \tgit -C linkwt rev-parse --git-common-dir >actual &&\n \ttest_cmp expect actual\n }\n \n-test_expect_success 're-init to move gitdir with linked worktrees' '\n-\tsep_git_dir_worktree mainwt\n+test_expect_success 're-init to move gitdir with linked worktrees (absolute)' '\n+\tsep_git_dir_worktree --no-relative-paths mainwt\n '\n \n-test_expect_success 're-init to move gitdir within linked worktree' '\n-\tsep_git_dir_worktree linkwt\n+test_expect_success 're-init to move gitdir within linked worktree (absolute)' '\n+\tsep_git_dir_worktree --no-relative-paths linkwt\n+'\n+\n+test_expect_success 're-init to move gitdir with linked worktrees (relative)' '\n+\tsep_git_dir_worktree --relative-paths mainwt\n+'\n+\n+test_expect_success 're-init to move gitdir within linked worktree (relative)' '\n+\tsep_git_dir_worktree --relative-paths linkwt\n '\n \n test_expect_success MINGW '.git hidden' '\ndiff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh\nindex cfc4aeb1798c6d023909cec771e5b74e983af5ea..630c13230b3cc762ce8d943e22be8891aa2b1871 100755\n--- a/t/t2400-worktree-add.sh\n+++ b/t/t2400-worktree-add.sh\n@@ -1207,4 +1207,45 @@ test_expect_success '\"add\" with initialized submodule, with submodule.recurse se\n \tgit -C project-clone -c submodule.recurse worktree add ../project-5\n '\n \n+test_expect_success 'can create worktrees with relative paths' '\n+\ttest_when_finished \"git worktree remove relative\" &&\n+\tgit config worktree.useRelativePaths false &&\n+\tgit worktree add --relative-paths ./relative &&\n+\tcat relative/.git >actual &&\n+\techo \"gitdir: ../.git/worktrees/relative\" >expect &&\n+\ttest_cmp expect actual &&\n+\tcat .git/worktrees/relative/gitdir >actual &&\n+\techo \"../../../relative/.git\" >expect &&\n+\ttest_cmp expect actual\n+\n+'\n+\n+test_expect_success 'can create worktrees with absolute paths' '\n+\tgit config worktree.useRelativePaths true &&\n+\tgit worktree add ./relative &&\n+\tcat relative/.git >actual &&\n+\techo \"gitdir: ../.git/worktrees/relative\" >expect &&\n+\ttest_cmp expect actual &&\n+\tgit worktree add --no-relative-paths ./absolute &&\n+\tcat absolute/.git >actual &&\n+\techo \"gitdir: $(pwd)/.git/worktrees/absolute\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'move repo without breaking relative internal links' '\n+\ttest_when_finished rm -rf repo moved &&\n+\tgit init repo &&\n+\t(\n+\t\tcd repo &&\n+\t\tgit config worktree.useRelativePaths true &&\n+\t\ttest_commit initial &&\n+\t\tgit worktree add wt1 &&\n+\t\tcd .. &&\n+\t\tmv repo moved &&\n+\t\tcd moved/wt1 &&\n+\t\tgit status >out 2>err &&\n+\t\ttest_must_be_empty err\n+\t)\n+'\n+\n test_done\ndiff --git a/t/t2402-worktree-list.sh b/t/t2402-worktree-list.sh\nindex 33ea9cb21ba07c9563530b54da06753eaa993fe2..780daa6cd6351f8fa9434619cc212aade8f01420 100755\n--- a/t/t2402-worktree-list.sh\n+++ b/t/t2402-worktree-list.sh\n@@ -261,6 +261,7 @@ test_expect_success 'broken main worktree still at the top' '\n '\n \n test_expect_success 'linked worktrees are sorted' '\n+\ttest_when_finished \"rm -rf sorted\" &&\n \tmkdir sorted &&\n \tgit init sorted/main &&\n \t(\n@@ -280,6 +281,27 @@ test_expect_success 'linked worktrees are sorted' '\n \ttest_cmp expected sorted/main/actual\n '\n \n+test_expect_success 'linked worktrees with relative paths are shown with absolute paths' '\n+\ttest_when_finished \"rm -rf sorted\" &&\n+\tmkdir sorted &&\n+\tgit init sorted/main &&\n+\t(\n+\t\tcd sorted/main &&\n+\t\ttest_tick &&\n+\t\ttest_commit new &&\n+\t\tgit worktree add --relative-paths ../first &&\n+\t\tgit worktree add ../second &&\n+\t\tgit worktree list --porcelain >out &&\n+\t\tgrep ^worktree out >actual\n+\t) &&\n+\tcat >expected <<-EOF &&\n+\tworktree $(pwd)/sorted/main\n+\tworktree $(pwd)/sorted/first\n+\tworktree $(pwd)/sorted/second\n+\tEOF\n+\ttest_cmp expected sorted/main/actual\n+'\n+\n test_expect_success 'worktree path when called in .git directory' '\n \tgit worktree list >list1 &&\n \tgit -C .git worktree list >list2 &&\ndiff --git a/t/t2403-worktree-move.sh b/t/t2403-worktree-move.sh\nindex 901342ea09b51a8e832f1109fbb737df84283aa2..6ce9ed3f1e6b3f73d2a290e770233eec30221fe5 100755\n--- a/t/t2403-worktree-move.sh\n+++ b/t/t2403-worktree-move.sh\n@@ -247,4 +247,26 @@ test_expect_success 'not remove a repo with initialized submodule' '\n \t)\n '\n \n+test_expect_success 'move worktree with absolute path to relative path' '\n+\tgit config worktree.useRelativePaths false &&\n+\tgit worktree add ./absolute &&\n+\tgit worktree move --relative-paths absolute relative &&\n+\tcat relative/.git >actual &&\n+\techo \"gitdir: ../.git/worktrees/absolute\" >expect &&\n+\ttest_cmp expect actual &&\n+\tgit config worktree.useRelativePaths true &&\n+\tgit worktree move relative relative2 &&\n+\tcat relative2/.git >actual &&\n+\techo \"gitdir: ../.git/worktrees/absolute\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'move worktree with relative path to absolute path' '\n+\tgit config worktree.useRelativePaths true &&\n+\tgit worktree move --no-relative-paths relative2 absolute &&\n+\tcat absolute/.git >actual &&\n+\techo \"gitdir: $(pwd)/.git/worktrees/absolute\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\ndiff --git a/t/t2406-worktree-repair.sh b/t/t2406-worktree-repair.sh\nindex 7686e60f6ad186519b275f11a5e14064c905b207..84451e903b2ef3c645c0311faf055c846588baf6 100755\n--- a/t/t2406-worktree-repair.sh\n+++ b/t/t2406-worktree-repair.sh\n@@ -216,4 +216,30 @@ test_expect_success 'repair copied main and linked worktrees' '\n \ttest_cmp dup/linked.expect dup/linked/.git\n '\n \n+test_expect_success 'repair absolute worktree to use relative paths' '\n+\ttest_when_finished \"rm -rf main side sidemoved\" &&\n+\ttest_create_repo main &&\n+\ttest_commit -C main init &&\n+\tgit -C main worktree add --detach ../side &&\n+\techo \"../../../../sidemoved/.git\" >expect-gitdir &&\n+\techo \"gitdir: ../main/.git/worktrees/side\" >expect-gitfile &&\n+\tmv side sidemoved &&\n+\tgit -C main worktree repair --relative-paths ../sidemoved &&\n+\ttest_cmp expect-gitdir main/.git/worktrees/side/gitdir &&\n+\ttest_cmp expect-gitfile sidemoved/.git\n+'\n+\n+test_expect_success 'repair relative worktree to use absolute paths' '\n+\ttest_when_finished \"rm -rf main side sidemoved\" &&\n+\ttest_create_repo main &&\n+\ttest_commit -C main init &&\n+\tgit -C main worktree add --relative-paths --detach ../side &&\n+\techo \"$(pwd)/sidemoved/.git\" >expect-gitdir &&\n+\techo \"gitdir: $(pwd)/main/.git/worktrees/side\" >expect-gitfile &&\n+\tmv side sidemoved &&\n+\tgit -C main worktree repair ../sidemoved &&\n+\ttest_cmp expect-gitdir main/.git/worktrees/side/gitdir &&\n+\ttest_cmp expect-gitfile sidemoved/.git\n+'\n+\n test_done\ndiff --git a/worktree.c b/worktree.c\nindex cf578c447589425d642fc8aa7a7fa07600e60a70..0d1685b892fcddf74a91304424a94e5ee847388b 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -14,6 +14,8 @@\n #include \"wt-status.h\"\n #include \"config.h\"\n \n+int use_relative_paths = 0;\n+\n void free_worktree(struct worktree *worktree)\n {\n \tif (!worktree)\n@@ -379,18 +381,24 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,\n void update_worktree_location(struct worktree *wt, const char *path_)\n {\n \tstruct strbuf path = STRBUF_INIT;\n+\tstruct strbuf dotgit = STRBUF_INIT;\n+\tstruct strbuf gitdir = STRBUF_INIT;\n \n \tif (is_main_worktree(wt))\n \t\tBUG(\"can't relocate main worktree\");\n \n+\tstrbuf_realpath(&gitdir, git_common_path(\"worktrees/%s/gitdir\", wt->id), 1);\n \tstrbuf_realpath(&path, path_, 1);\n+\tstrbuf_addf(&dotgit, \"%s/.git\", path.buf);\n \tif (fspathcmp(wt->path, path.buf)) {\n-\t\twrite_file(git_common_path(\"worktrees/%s/gitdir\", wt->id),\n-\t\t\t   \"%s/.git\", path.buf);\n+\t\twrite_worktree_linking_files(dotgit, gitdir);\n+\n \t\tfree(wt->path);\n \t\twt->path = strbuf_detach(&path, NULL);\n \t}\n \tstrbuf_release(&path);\n+\tstrbuf_release(&dotgit);\n+\tstrbuf_release(&gitdir);\n }\n \n int is_worktree_being_rebased(const struct worktree *wt,\n@@ -569,6 +577,7 @@ static void repair_gitfile(struct worktree *wt,\n \t\t\t   worktree_repair_fn fn, void *cb_data)\n {\n \tstruct strbuf dotgit = STRBUF_INIT;\n+\tstruct strbuf gitdir = STRBUF_INIT;\n \tstruct strbuf repo = STRBUF_INIT;\n \tstruct strbuf backlink = STRBUF_INIT;\n \tchar *dotgit_contents = NULL;\n@@ -586,6 +595,7 @@ static void repair_gitfile(struct worktree *wt,\n \n \tstrbuf_realpath(&repo, git_common_path(\"worktrees/%s\", wt->id), 1);\n \tstrbuf_addf(&dotgit, \"%s/.git\", wt->path);\n+\tstrbuf_addf(&gitdir, \"%s/gitdir\", repo.buf);\n \tdotgit_contents = xstrdup_or_null(read_gitfile_gently(dotgit.buf, &err));\n \n \tif (dotgit_contents) {\n@@ -603,16 +613,19 @@ static void repair_gitfile(struct worktree *wt,\n \t\trepair = _(\".git file broken\");\n \telse if (fspathcmp(backlink.buf, repo.buf))\n \t\trepair = _(\".git file incorrect\");\n+\telse if (use_relative_paths == is_absolute_path(dotgit_contents))\n+\t\trepair = _(\".git file absolute/relative path mismatch\");\n \n \tif (repair) {\n \t\tfn(0, wt->path, repair, cb_data);\n-\t\twrite_file(dotgit.buf, \"gitdir: %s\", repo.buf);\n+\t\twrite_worktree_linking_files(dotgit, gitdir);\n \t}\n \n done:\n \tfree(dotgit_contents);\n \tstrbuf_release(&repo);\n \tstrbuf_release(&dotgit);\n+\tstrbuf_release(&gitdir);\n \tstrbuf_release(&backlink);\n }\n \n@@ -636,6 +649,45 @@ void repair_worktrees(worktree_repair_fn fn, void *cb_data)\n \tfree_worktrees(worktrees);\n }\n \n+void repair_worktree_after_gitdir_move(struct worktree *wt,\n+\t\t\t\t       const char *old_path)\n+{\n+\tstruct strbuf gitdir = STRBUF_INIT;\n+\tstruct strbuf dotgit = STRBUF_INIT;\n+\n+\tif (is_main_worktree(wt))\n+\t\tgoto done;\n+\n+\tstrbuf_realpath(&gitdir, git_common_path(\"worktrees/%s/gitdir\", wt->id), 1);\n+\n+\tif (strbuf_read_file(&dotgit, gitdir.buf, 0) < 0)\n+\t\tgoto done;\n+\n+\tstrbuf_rtrim(&dotgit);\n+\tif (!is_absolute_path(dotgit.buf)) {\n+\t\tstrbuf_insertf(&dotgit, 0, \"%s/worktrees/%s/\", old_path, wt->id);\n+\t\tstrbuf_realpath_forgiving(&dotgit, dotgit.buf, 0);\n+\t}\n+\n+\tif (!file_exists(dotgit.buf))\n+\t\tgoto done;\n+\n+\twrite_worktree_linking_files(dotgit, gitdir);\n+done:\n+\tstrbuf_release(&gitdir);\n+\tstrbuf_release(&dotgit);\n+}\n+\n+void repair_worktrees_after_gitdir_move(const char *old_path)\n+{\n+\tstruct worktree **worktrees = get_worktrees_internal(1);\n+\tstruct worktree **wt = worktrees + 1; /* +1 skips main worktree */\n+\n+\tfor (; *wt; wt++)\n+\t\trepair_worktree_after_gitdir_move(*wt, old_path);\n+\tfree_worktrees(worktrees);\n+}\n+\n static int is_main_worktree_path(const char *path)\n {\n \tstruct strbuf target = STRBUF_INIT;\n@@ -698,12 +750,10 @@ void repair_worktree_at_path(const char *path,\n \t\t\t     worktree_repair_fn fn, void *cb_data)\n {\n \tstruct strbuf dotgit = STRBUF_INIT;\n-\tstruct strbuf realdotgit = STRBUF_INIT;\n \tstruct strbuf backlink = STRBUF_INIT;\n \tstruct strbuf inferred_backlink = STRBUF_INIT;\n \tstruct strbuf gitdir = STRBUF_INIT;\n \tstruct strbuf olddotgit = STRBUF_INIT;\n-\tstruct strbuf realolddotgit = STRBUF_INIT;\n \tchar *dotgit_contents = NULL;\n \tconst char *repair = NULL;\n \tint err;\n@@ -715,25 +765,25 @@ void repair_worktree_at_path(const char *path,\n \t\tgoto done;\n \n \tstrbuf_addf(&dotgit, \"%s/.git\", path);\n-\tif (!strbuf_realpath(&realdotgit, dotgit.buf, 0)) {\n+\tif (!strbuf_realpath(&dotgit, dotgit.buf, 0)) {\n \t\tfn(1, path, _(\"not a valid path\"), cb_data);\n \t\tgoto done;\n \t}\n \n-\tinfer_backlink(realdotgit.buf, &inferred_backlink);\n+\tinfer_backlink(dotgit.buf, &inferred_backlink);\n \tstrbuf_realpath_forgiving(&inferred_backlink, inferred_backlink.buf, 0);\n-\tdotgit_contents = xstrdup_or_null(read_gitfile_gently(realdotgit.buf, &err));\n+\tdotgit_contents = xstrdup_or_null(read_gitfile_gently(dotgit.buf, &err));\n \tif (dotgit_contents) {\n \t\tif (is_absolute_path(dotgit_contents)) {\n \t\t\tstrbuf_addstr(&backlink, dotgit_contents);\n \t\t} else {\n-\t\t\tstrbuf_addbuf(&backlink, &realdotgit);\n+\t\t\tstrbuf_addbuf(&backlink, &dotgit);\n \t\t\tstrbuf_strip_suffix(&backlink, \".git\");\n \t\t\tstrbuf_addstr(&backlink, dotgit_contents);\n \t\t\tstrbuf_realpath_forgiving(&backlink, backlink.buf, 0);\n \t\t}\n \t} else if (err == READ_GITFILE_ERR_NOT_A_FILE) {\n-\t\tfn(1, realdotgit.buf, _(\"unable to locate repository; .git is not a file\"), cb_data);\n+\t\tfn(1, dotgit.buf, _(\"unable to locate repository; .git is not a file\"), cb_data);\n \t\tgoto done;\n \t} else if (err == READ_GITFILE_ERR_NOT_A_REPO) {\n \t\tif (inferred_backlink.len) {\n@@ -746,11 +796,11 @@ void repair_worktree_at_path(const char *path,\n \t\t\t */\n \t\t\tstrbuf_swap(&backlink, &inferred_backlink);\n \t\t} else {\n-\t\t\tfn(1, realdotgit.buf, _(\"unable to locate repository; .git file does not reference a repository\"), cb_data);\n+\t\t\tfn(1, dotgit.buf, _(\"unable to locate repository; .git file does not reference a repository\"), cb_data);\n \t\t\tgoto done;\n \t\t}\n \t} else {\n-\t\tfn(1, realdotgit.buf, _(\"unable to locate repository; .git file broken\"), cb_data);\n+\t\tfn(1, dotgit.buf, _(\"unable to locate repository; .git file broken\"), cb_data);\n \t\tgoto done;\n \t}\n \n@@ -778,30 +828,28 @@ void repair_worktree_at_path(const char *path,\n \tstrbuf_addf(&gitdir, \"%s/gitdir\", backlink.buf);\n \tif (strbuf_read_file(&olddotgit, gitdir.buf, 0) < 0)\n \t\trepair = _(\"gitdir unreadable\");\n+\telse if (use_relative_paths == is_absolute_path(olddotgit.buf))\n+\t\trepair = _(\"gitdir absolute/relative path mismatch\");\n \telse {\n \t\tstrbuf_rtrim(&olddotgit);\n-\t\tif (is_absolute_path(olddotgit.buf)) {\n-\t\t\tstrbuf_addbuf(&realolddotgit, &olddotgit);\n-\t\t} else {\n-\t\t\tstrbuf_addf(&realolddotgit, \"%s/%s\", backlink.buf, olddotgit.buf);\n-\t\t\tstrbuf_realpath_forgiving(&realolddotgit, realolddotgit.buf, 0);\n+\t\tif (!is_absolute_path(olddotgit.buf)) {\n+\t\t\tstrbuf_insertf(&olddotgit, 0, \"%s/\", backlink.buf);\n+\t\t\tstrbuf_realpath_forgiving(&olddotgit, olddotgit.buf, 0);\n \t\t}\n-\t\tif (fspathcmp(realolddotgit.buf, realdotgit.buf))\n+\t\tif (fspathcmp(olddotgit.buf, dotgit.buf))\n \t\t\trepair = _(\"gitdir incorrect\");\n \t}\n \n \tif (repair) {\n \t\tfn(0, gitdir.buf, repair, cb_data);\n-\t\twrite_file(gitdir.buf, \"%s\", realdotgit.buf);\n+\t\twrite_worktree_linking_files(dotgit, gitdir);\n \t}\n done:\n \tfree(dotgit_contents);\n \tstrbuf_release(&olddotgit);\n-\tstrbuf_release(&realolddotgit);\n \tstrbuf_release(&backlink);\n \tstrbuf_release(&inferred_backlink);\n \tstrbuf_release(&gitdir);\n-\tstrbuf_release(&realdotgit);\n \tstrbuf_release(&dotgit);\n }\n \n@@ -963,3 +1011,29 @@ int init_worktree_config(struct repository *r)\n \tfree(main_worktree_file);\n \treturn res;\n }\n+\n+void write_worktree_linking_files(struct strbuf dotgit, struct strbuf gitdir)\n+{\n+\tstruct strbuf path = STRBUF_INIT;\n+\tstruct strbuf repo = STRBUF_INIT;\n+\tstruct strbuf tmp = STRBUF_INIT;\n+\n+\tstrbuf_addbuf(&path, &dotgit);\n+\tstrbuf_strip_suffix(&path, \"/.git\");\n+\tstrbuf_realpath(&path, path.buf, 1);\n+\tstrbuf_addbuf(&repo, &gitdir);\n+\tstrbuf_strip_suffix(&repo, \"/gitdir\");\n+\tstrbuf_realpath(&repo, repo.buf, 1);\n+\n+\tif (use_relative_paths) {\n+\t\twrite_file(gitdir.buf, \"%s/.git\", relative_path(path.buf, repo.buf, &tmp));\n+\t\twrite_file(dotgit.buf, \"gitdir: %s\", relative_path(repo.buf, path.buf, &tmp));\n+\t} else {\n+\t\twrite_file(gitdir.buf, \"%s/.git\", path.buf);\n+\t\twrite_file(dotgit.buf, \"gitdir: %s\", repo.buf);\n+\t}\n+\n+\tstrbuf_release(&path);\n+\tstrbuf_release(&repo);\n+\tstrbuf_release(&tmp);\n+}\ndiff --git a/worktree.h b/worktree.h\nindex 11279d0c8fe249bb30642563bf221a8de7f3b0a3..5929089891c97318a8f5329f7938264c717050d5 100644\n--- a/worktree.h\n+++ b/worktree.h\n@@ -5,6 +5,8 @@\n \n struct strbuf;\n \n+extern int use_relative_paths;\n+\n struct worktree {\n \t/* The repository this worktree belongs to. */\n \tstruct repository *repo;\n@@ -131,6 +133,16 @@ typedef void (* worktree_repair_fn)(int iserr, const char *path,\n  */\n void repair_worktrees(worktree_repair_fn, void *cb_data);\n \n+/*\n+ * Repair the linked worktrees after the gitdir has been moved.\n+ */\n+void repair_worktrees_after_gitdir_move(const char *old_path);\n+\n+/*\n+ * Repair the linked worktree after the gitdir has been moved.\n+ */\n+void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path);\n+\n /*\n  * Repair administrative files corresponding to the worktree at the given path.\n  * The worktree's .git file pointing at the repository must be intact for the\n@@ -205,4 +217,16 @@ void strbuf_worktree_ref(const struct worktree *wt,\n  */\n int init_worktree_config(struct repository *r);\n \n+/**\n+ * Write the .git file and gitdir file that links the worktree to the repository.\n+ *\n+ * The `dotgit` parameter is the path to the worktree's .git file, and `gitdir`\n+ * is the path to the repository's `gitdir` file.\n+ *\n+ * Example\n+ *  dotgit: \"/path/to/foo/.git\"\n+ *  gitdir: \"/path/to/repo/worktrees/foo/gitdir\"\n+ */\n+void write_worktree_linking_files(struct strbuf dotgit, struct strbuf gitdir);\n+\n #endif\n\n-- \n2.47.0\n\n\n"},{"id":"506118","messageId":"20241025-wt_relative_paths-v3-5-8860a5321c01@pm.me","threadId":"62407","inReplyTo":"20241025-wt_relative_paths-v3-0-8860a5321c01@pm.me","subject":"[PATCH v3 5/5] worktree: add `relativeWorktrees` extension","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T20:57:52Z","receivedAt":"2024-10-25T20:58:01Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"A new extension, `relativeWorktrees`, is added to indicate that at least\none worktree in the repository has been linked with relative paths. This\nextension is automatically set when a worktree is created or repaired\nusing the `--relative-paths` option, or when the\n`worktree.useRelativePaths` config is set to `true`.\n\nThe `relativeWorktrees` extension ensures older Git versions do not\nattempt to automatically prune worktrees with relative paths, as they\nwould not not recognize the paths as being valid.\n\nSuggested-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Caleb White <cdwhite3@pm.me>\n---\n Documentation/config/extensions.txt |  6 ++++++\n repository.c                        |  1 +\n repository.h                        |  1 +\n setup.c                             |  7 +++++++\n setup.h                             |  1 +\n t/t2400-worktree-add.sh             | 13 +++++++++++++\n worktree.c                          |  8 ++++++++\n 7 files changed, 37 insertions(+)\n\ndiff --git a/Documentation/config/extensions.txt b/Documentation/config/extensions.txt\nindex 5dc569d1c9c77c15e32441493289f9c9dd5e7f0b..5cb4721a0e0ae1ed64f90492c0dc18b96473cb33 100644\n--- a/Documentation/config/extensions.txt\n+++ b/Documentation/config/extensions.txt\n@@ -63,6 +63,12 @@ Note that this setting should only be set by linkgit:git-init[1] or\n linkgit:git-clone[1]. Trying to change it after initialization will not\n work and will produce hard-to-diagnose issues.\n \n+relativeWorktrees::\n+\tIf enabled, indicates at least one worktree has been linked with\n+\trelative paths. Automatically set if a worktree has been created or\n+\trepaired with either the `--relative-paths` option or with the\n+\t`worktree.useRelativePaths` config set to `true`.\n+\n worktreeConfig::\n \tIf enabled, then worktrees will load config settings from the\n \t`$GIT_DIR/config.worktree` file in addition to the\ndiff --git a/repository.c b/repository.c\nindex f988b8ae68a6a29792e7f2c980a02bd0e388a3b9..1a6a62bbd03a5dc4fdade3eb45ea2696968abc23 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -283,6 +283,7 @@ int repo_init(struct repository *repo,\n \trepo_set_compat_hash_algo(repo, format.compat_hash_algo);\n \trepo_set_ref_storage_format(repo, format.ref_storage_format);\n \trepo->repository_format_worktree_config = format.worktree_config;\n+\trepo->repository_format_relative_worktrees = format.relative_worktrees;\n \n \t/* take ownership of format.partial_clone */\n \trepo->repository_format_partial_clone = format.partial_clone;\ndiff --git a/repository.h b/repository.h\nindex 24a66a496a6ff516ce06d47b7329b3d36eb701ca..c4c92b2ab9c9e3b425dc2974636e33d1f4089c69 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -150,6 +150,7 @@ struct repository {\n \n \t/* Configurations */\n \tint repository_format_worktree_config;\n+\tint repository_format_relative_worktrees;\n \n \t/* Indicate if a repository has a different 'commondir' from 'gitdir' */\n \tunsigned different_commondir:1;\ndiff --git a/setup.c b/setup.c\nindex 7b648de0279116b381eea46800ad130606926103..6bf56cf72c4b46a95f46f9b3901f7e77d702cec7 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -683,6 +683,9 @@ static enum extension_result handle_extension(const char *var,\n \t\t\t\t     \"extensions.refstorage\", value);\n \t\tdata->ref_storage_format = format;\n \t\treturn EXTENSION_OK;\n+\t} else if (!strcmp(ext, \"relativeworktrees\")) {\n+\t\tdata->relative_worktrees = git_config_bool(var, value);\n+\t\treturn EXTENSION_OK;\n \t}\n \treturn EXTENSION_UNKNOWN;\n }\n@@ -1854,6 +1857,8 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\t\t\t\t    repo_fmt.ref_storage_format);\n \t\t\tthe_repository->repository_format_worktree_config =\n \t\t\t\trepo_fmt.worktree_config;\n+\t\t\tthe_repository->repository_format_relative_worktrees =\n+\t\t\t\trepo_fmt.relative_worktrees;\n \t\t\t/* take ownership of repo_fmt.partial_clone */\n \t\t\tthe_repository->repository_format_partial_clone =\n \t\t\t\trepo_fmt.partial_clone;\n@@ -1950,6 +1955,8 @@ void check_repository_format(struct repository_format *fmt)\n \t\t\t\t    fmt->ref_storage_format);\n \tthe_repository->repository_format_worktree_config =\n \t\tfmt->worktree_config;\n+\tthe_repository->repository_format_relative_worktrees =\n+\t\tfmt->relative_worktrees;\n \tthe_repository->repository_format_partial_clone =\n \t\txstrdup_or_null(fmt->partial_clone);\n \tclear_repository_format(&repo_fmt);\ndiff --git a/setup.h b/setup.h\nindex e496ab3e4de580c2d9f95a7ea0eaf90e0d41b070..18dc3b73686ce28fac2fe04282ce95f8bf3e6b74 100644\n--- a/setup.h\n+++ b/setup.h\n@@ -129,6 +129,7 @@ struct repository_format {\n \tint precious_objects;\n \tchar *partial_clone; /* value of extensions.partialclone */\n \tint worktree_config;\n+\tint relative_worktrees;\n \tint is_bare;\n \tint hash_algo;\n \tint compat_hash_algo;\ndiff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh\nindex 630c13230b3cc762ce8d943e22be8891aa2b1871..d36d8a4db0e924877787697579544f10f92dc0cf 100755\n--- a/t/t2400-worktree-add.sh\n+++ b/t/t2400-worktree-add.sh\n@@ -1248,4 +1248,17 @@ test_expect_success 'move repo without breaking relative internal links' '\n \t)\n '\n \n+test_expect_success 'relative worktree sets extension config' '\n+\ttest_when_finished \"rm -rf repo\" &&\n+\tgit init repo &&\n+\tgit -C repo commit --allow-empty -m base &&\n+\tgit -C repo worktree add --relative-paths ./foo &&\n+\tgit -C repo config get core.repositoryformatversion >actual &&\n+\techo 1 >expected &&\n+\ttest_cmp expected actual &&\n+\tgit -C repo config get extensions.relativeworktrees >actual &&\n+\techo true >expected &&\n+\ttest_cmp expected actual\n+'\n+\n test_done\ndiff --git a/worktree.c b/worktree.c\nindex 0d1685b892fcddf74a91304424a94e5ee847388b..41ebddb495d146e302fedefdb03e0d2637fb2831 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -1025,6 +1025,14 @@ void write_worktree_linking_files(struct strbuf dotgit, struct strbuf gitdir)\n \tstrbuf_strip_suffix(&repo, \"/gitdir\");\n \tstrbuf_realpath(&repo, repo.buf, 1);\n \n+\tif (use_relative_paths && !the_repository->repository_format_relative_worktrees) {\n+\t\tif (upgrade_repository_format(1) < 0)\n+\t\t\tdie(_(\"unable to upgrade repository format to support relative worktrees\"));\n+\t\tif (git_config_set_gently(\"extensions.relativeWorktrees\", \"true\"))\n+\t\t\tdie(_(\"unable to set extensions.relativeWorktrees setting\"));\n+\t\tthe_repository->repository_format_relative_worktrees = 1;\n+\t}\n+\n \tif (use_relative_paths) {\n \t\twrite_file(gitdir.buf, \"%s/.git\", relative_path(path.buf, repo.buf, &tmp));\n \t\twrite_file(dotgit.buf, \"gitdir: %s\", relative_path(repo.buf, path.buf, &tmp));\n\n-- \n2.47.0\n\n\n"},{"id":"506119","messageId":"D556TFZ8X35O.20C1EQYRMY3Q4@pm.me","threadId":"62407","inReplyTo":"20241025-wt_relative_paths-v3-0-8860a5321c01@pm.me","subject":"Re: [PATCH v3 0/5] Optionally link worktrees with relative paths","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T20:59:40Z","receivedAt":"2024-10-25T20:59:46Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"My apologies, this should have said v4 instead of v3.\n\n"},{"id":"506120","messageId":"ZxwIEcUKMELmxeMh@nand.local","threadId":"62407","inReplyTo":"20241025-wt_relative_paths-v3-0-8860a5321c01@pm.me","subject":"Re: [PATCH v3 0/5] Optionally link worktrees with relative paths","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-25T21:05:21Z","receivedAt":"2024-10-25T21:05:23Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Oct 25, 2024 at 08:57:17PM +0000, Caleb White wrote:\n> Caleb White (5):\n>       worktree: refactor infer_backlink() to use strbuf*\n>       worktree: support worktrees linked with relative paths\n>       worktree: optionally link worktrees with relative paths\n>       worktree: add test for path handling in linked worktrees\n>       worktree: add `relativeWorktrees` extension\n\nThe previous round was already merged to 'master' a few days ago[1],\nafter merging it to 'next' and saying so in this[2] WC report.\n\nI'm not sure if you intended to send this series as a follow-up to the\nstate that was already merged to 'master', or if you had intended to\nsend a new round of changes not knowing it had already been merged.\n\nIn either case, can you please send a new round based on the current tip\nof 'master'?\n\nThanks,\nTaylor\n\n[1]: 8e08668322 (Merge branch 'cw/worktree-relative', 2024-10-22).\n[2]: https://lore.kernel.org/git/ZxLI06smvMuf%2FcT2@nand.local/\n"},{"id":"506124","messageId":"D5572ICCKQXT.3UQ8AJ2GSUZIP@pm.me","threadId":"62407","inReplyTo":"ZxwIEcUKMELmxeMh@nand.local","subject":"Re: [PATCH v3 0/5] Optionally link worktrees with relative paths","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T21:11:30Z","receivedAt":"2024-10-25T21:11:34Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"On Fri Oct 25, 2024 at 4:05 PM CDT, Taylor Blau wrote:\n> On Fri, Oct 25, 2024 at 08:57:17PM +0000, Caleb White wrote:\n>> Caleb White (5):\n>>       worktree: refactor infer_backlink() to use strbuf*\n>>       worktree: support worktrees linked with relative paths\n>>       worktree: optionally link worktrees with relative paths\n>>       worktree: add test for path handling in linked worktrees\n>>       worktree: add `relativeWorktrees` extension\n>\n> The previous round was already merged to 'master' a few days ago[1],\n> after merging it to 'next' and saying so in this[2] WC report.\n>\n> I'm not sure if you intended to send this series as a follow-up to the\n> state that was already merged to 'master', or if you had intended to\n> send a new round of changes not knowing it had already been merged.\n>\n> In either case, can you please send a new round based on the current tip\n> of 'master'?\n>\n> Thanks,\n> Taylor\n>\n> [1]: 8e08668322 (Merge branch 'cw/worktree-relative', 2024-10-22).\n> [2]: https://lore.kernel.org/git/ZxLI06smvMuf%2FcT2@nand.local/\n\nAh, I must've missed that---I was in the process of working on v4 and\ndidn't realize that it had already been merged to master.\n\nI'll send a new round based on the current tip of master.\n\nThanks!\nCaleb\n\n"},{"id":"506130","messageId":"ZxwPwfJnEJ8C/rkz@nand.local","threadId":"62407","inReplyTo":"D5572ICCKQXT.3UQ8AJ2GSUZIP@pm.me","subject":"Re: [PATCH v3 0/5] Optionally link worktrees with relative paths","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-25T21:38:09Z","receivedAt":"2024-10-25T21:38:11Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Oct 25, 2024 at 09:11:30PM +0000, Caleb White wrote:\n> Ah, I must've missed that---I was in the process of working on v4 and\n> didn't realize that it had already been merged to master.\n>\n> I'll send a new round based on the current tip of master.\n\nThanks.\n\nLooking at the dates, I should have held the existing round in 'next'\nfor a few days longer. But I figured that the existing v3 was already in\na good state, and hadn't heard otherwise since the original thread[1]\nwas quiet.\n\nThanks,\nTaylor\n\n[1]: https://lore.kernel.org/git/20241007-wt_relative_paths-v3-0-622cf18c45eb@pm.me/\n"},{"id":"506134","messageId":"D558UCES3M9N.2UUO7C08Y49DG@pm.me","threadId":"62407","inReplyTo":"ZxwPwfJnEJ8C/rkz@nand.local","subject":"Re: [PATCH v3 0/5] Optionally link worktrees with relative paths","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T22:34:54Z","receivedAt":"2024-10-25T22:35:04Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"On Fri Oct 25, 2024 at 4:38 PM CDT, Taylor Blau wrote:\n> On Fri, Oct 25, 2024 at 09:11:30PM +0000, Caleb White wrote:\n>> Ah, I must've missed that---I was in the process of working on v4 and\n>> didn't realize that it had already been merged to master.\n>>\n>> I'll send a new round based on the current tip of master.\n>\n> Thanks.\n>\n> Looking at the dates, I should have held the existing round in 'next'\n> for a few days longer. But I figured that the existing v3 was already in\n> a good state, and hadn't heard otherwise since the original thread[1]\n> was quiet.\n>\n> Thanks,\n> Taylor\n>\n> [1]: https://lore.kernel.org/git/20241007-wt_relative_paths-v3-0-622cf18c45eb@pm.me/\n\nNo worries! I had a busy week and didn't complete v4 as soon I would've\nliked. Here is the new round:\n\nhttps://lore.kernel.org/git/20241025-wt_relative_options-v1-0-c3005df76bf9@pm.me\n\nBest,\nCaleb\n\n"}]}