{"thread":{"id":"62408","subject":"[PATCH 0/2] Allow relative worktree linking to be configured by the user","startedAt":"2024-10-25T22:29:32Z","lastAt":"2024-10-28T23:36:47Z","messageCount":14,"participants":["Caleb White","Taylor Blau"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"506131","messageId":"20241025-wt_relative_options-v1-0-c3005df76bf9@pm.me","threadId":"62408","inReplyTo":null,"subject":"[PATCH 0/2] Allow relative worktree linking to be configured by the user","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T22:29:25Z","receivedAt":"2024-10-25T22:29:32Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"This patch introduces the `--[no-]relative-paths` CLI option for\n`git worktree {add, move, repair}` commands, as well as the\n`worktree.useRelativePaths` configuration setting. When enabled,\nthese options allow worktrees to be linked using relative paths,\nenhancing portability across environments where absolute paths\nmay differ (e.g., containerized setups, shared network drives).\n\nUsing the `--relative-paths` option with `worktree {move, repair}`\nwill convert absolute paths to relative ones, if possible, while\n`--no-relative-paths` does the reverse. For cases where users want\nconsistency in path handling, the config option\n`worktree.useRelativePaths` provides a persistent setting.\n\nA 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\nSigned-off-by: Caleb White <cdwhite3@pm.me>\n---\nThe base for this patch series is obtained by applying the following\npatch onto 6a11438f43:\n- cw/config-extensions topic (doc: consolidate extensions in git-config\n  documentation, 2024-10-22, <20241021-cleanup-extension-docs-v1-1-ab02cece3132@pm.me>)\n\nLink to original patch series:\nhttps://lore.kernel.org/git/20241007-wt_relative_paths-v3-0-622cf18c45eb@pm.me\n\n---\nCaleb White (2):\n      worktree: add CLI/config options for relative path linking\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                  |  20 ++---\n repository.c                        |   1 +\n repository.h                        |   1 +\n setup.c                             |   7 ++\n setup.h                             |   1 +\n t/t0001-init.sh                     |  17 ++++-\n t/t2400-worktree-add.sh             |  54 ++++++++++++++\n t/t2401-worktree-prune.sh           |   3 +-\n t/t2402-worktree-list.sh            |  22 ++++++\n t/t2403-worktree-move.sh            |  22 ++++++\n t/t2406-worktree-repair.sh          |  26 +++++++\n worktree.c                          | 143 ++++++++++++++++++++----------------\n worktree.h                          |  14 ++++\n 16 files changed, 272 insertions(+), 79 deletions(-)\n---\nbase-commit: 6a11438f43469f3815f2f0fc997bd45792ff04c0\nchange-id: 20241025-wt_relative_options-afa41987bc32\nprerequisite-change-id: 20241020-cleanup-extension-docs-f365868711bf:v1\nprerequisite-patch-id: 60a443b24e92938b9b6f4a016a7bab87e13bf3ea\n\nBest regards,\n-- \nCaleb White <cdwhite3@pm.me>\n\n\n"},{"id":"506132","messageId":"20241025-wt_relative_options-v1-1-c3005df76bf9@pm.me","threadId":"62408","inReplyTo":"20241025-wt_relative_options-v1-0-c3005df76bf9@pm.me","subject":"[PATCH 1/2] worktree: add CLI/config options for relative path linking","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T22:29:37Z","receivedAt":"2024-10-25T22:29:46Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"This patch introduces the `--[no-]relative-paths` CLI option for\n`git worktree {add, move, repair}` commands, as well as the\n`worktree.useRelativePaths` configuration setting. When enabled,\nthese options allow worktrees to be linked using relative paths,\nenhancing portability across environments where absolute paths\nmay differ (e.g., containerized setups, shared network drives).\n\nUsing the `--relative-paths` option with `worktree {move, repair}`\nwill convert absolute paths to relative ones, while `--no-relative-paths`\ndoes the reverse. For cases where users want consistency in path\nhandling, the config option `worktree.useRelativePaths` provides\na persistent setting.\n\nA new helper function, `write_worktree_linking_files()`, centralizes\nthe logic for computing and writing either relative or absolute\npaths, based on the provided configuration. This function accepts\n`strbuf` pointers to both the worktree’s `.git` link and the\nrepository’s `gitdir`, and then writes the appropriate path to each.\n\nIn response to reviewer feedback from the initial patch series[1],\nthis revision includes slight refactoring for improved\nmaintainability and clarity in the code base.\n\n[1]: https://lore.kernel.org/git/20241007-wt_relative_paths-v3-0-622cf18c45eb@pm.me\n\nSuggested-by: Junio C Hamano <gitster@pobox.com>\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                |  20 +++---\n t/t0001-init.sh                   |  17 +++--\n t/t2400-worktree-add.sh           |  41 ++++++++++++\n t/t2401-worktree-prune.sh         |   3 +-\n t/t2402-worktree-list.sh          |  22 +++++++\n t/t2403-worktree-move.sh          |  22 +++++++\n t/t2406-worktree-repair.sh        |  26 ++++++++\n worktree.c                        | 135 ++++++++++++++++++++------------------\n worktree.h                        |  14 ++++\n 11 files changed, 235 insertions(+), 79 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 dae63dedf4cac2621f51f95a39aa456b33acd894..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,8 +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, sb_tmp = STRBUF_INIT;\n-\tstruct strbuf sb_path_realpath = STRBUF_INIT, sb_repo_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@@ -491,10 +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(&sb_path_realpath, path, 1);\n-\tstrbuf_realpath(&sb_repo_realpath, sb_repo.buf, 1);\n-\twrite_file(sb.buf, \"%s/.git\", relative_path(sb_path_realpath.buf, sb_repo_realpath.buf, &sb_tmp));\n-\twrite_file(sb_git.buf, \"gitdir: %s\", relative_path(sb_repo_realpath.buf, sb_path_realpath.buf, &sb_tmp));\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@@ -578,12 +577,9 @@ static int add_worktree(const char *path, const char *refname,\n \n \tstrvec_clear(&child_env);\n \tstrbuf_release(&sb);\n-\tstrbuf_release(&sb_tmp);\n \tstrbuf_release(&symref);\n \tstrbuf_release(&sb_repo);\n-\tstrbuf_release(&sb_repo_realpath);\n \tstrbuf_release(&sb_git);\n-\tstrbuf_release(&sb_path_realpath);\n \tstrbuf_release(&sb_name);\n \tfree_worktree(wt);\n \treturn ret;\n@@ -796,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@@ -1189,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@@ -1382,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/t/t0001-init.sh b/t/t0001-init.sh\nindex 0178aa62a41f1606f2382a4a10ab593ccf11e0e8..e21b9aa5e7f4599af8b20165b50896c9a49ba7ea 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -435,6 +435,7 @@ 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 config worktree.useRelativePaths \"$([ \"$2\" = \"relative\" ] && echo true || echo false)\" &&\n \tgit -C mainwt worktree add --detach ../linkwt &&\n \tgit -C \"$1\" init --separate-git-dir ../seprepo &&\n \tgit -C mainwt rev-parse --git-common-dir >expect &&\n@@ -442,12 +443,20 @@ sep_git_dir_worktree ()  {\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 mainwt absolute\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 linkwt absolute\n+'\n+\n+test_expect_success 're-init to move gitdir with linked worktrees (relative)' '\n+\tsep_git_dir_worktree mainwt relative\n+'\n+\n+test_expect_success 're-init to move gitdir within linked worktree (relative)' '\n+\tsep_git_dir_worktree linkwt relative\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/t2401-worktree-prune.sh b/t/t2401-worktree-prune.sh\nindex 976d048e3efc74be9cd909ce76d552b3944d2e10..5eb52b9abbf29514dc082c260ebb7a5e8e63aae0 100755\n--- a/t/t2401-worktree-prune.sh\n+++ b/t/t2401-worktree-prune.sh\n@@ -120,11 +120,12 @@ test_expect_success 'prune duplicate (main/linked)' '\n \t! test -d .git/worktrees/wt\n '\n \n-test_expect_success 'not prune proper worktrees when run inside linked worktree' '\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 &&\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 77ff484d3ec48c547ee4e3d958dfa28a52c1eaa7..f4cee73d7a1edecafdff30b6d5e2d9dd1365b93e 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@@ -111,9 +113,9 @@ struct worktree *get_linked_worktree(const char *id,\n \tstrbuf_strip_suffix(&worktree_path, \"/.git\");\n \n \tif (!is_absolute_path(worktree_path.buf)) {\n-\t    strbuf_strip_suffix(&path, \"gitdir\");\n-\t    strbuf_addbuf(&path, &worktree_path);\n-\t    strbuf_realpath_forgiving(&worktree_path, path.buf, 0);\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@@ -379,29 +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 repo = STRBUF_INIT;\n-\tstruct strbuf file = STRBUF_INIT;\n-\tstruct strbuf tmp = 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(&repo, git_common_path(\"worktrees/%s\", wt->id), 1);\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\tstrbuf_addf(&file, \"%s/gitdir\", repo.buf);\n-\t\twrite_file(file.buf, \"%s/.git\", relative_path(path.buf, repo.buf, &tmp));\n-\t\tstrbuf_reset(&file);\n-\t\tstrbuf_addf(&file, \"%s/.git\", path.buf);\n-\t\twrite_file(file.buf, \"gitdir: %s\", relative_path(repo.buf, path.buf, &tmp));\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(&repo);\n-\tstrbuf_release(&file);\n-\tstrbuf_release(&tmp);\n+\tstrbuf_release(&dotgit);\n+\tstrbuf_release(&gitdir);\n }\n \n int is_worktree_being_rebased(const struct worktree *wt,\n@@ -580,9 +577,9 @@ 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-\tstruct strbuf tmp = STRBUF_INIT;\n \tchar *dotgit_contents = NULL;\n \tconst char *repair = NULL;\n \tint err;\n@@ -598,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@@ -615,18 +613,20 @@ 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\", relative_path(repo.buf, wt->path, &tmp));\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-\tstrbuf_release(&tmp);\n }\n \n static void repair_noop(int iserr UNUSED,\n@@ -651,45 +651,30 @@ void repair_worktrees(worktree_repair_fn fn, void *cb_data)\n \n void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path)\n {\n-\tstruct strbuf path = STRBUF_INIT;\n-\tstruct strbuf repo = STRBUF_INIT;\n \tstruct strbuf gitdir = STRBUF_INIT;\n \tstruct strbuf dotgit = STRBUF_INIT;\n-\tstruct strbuf olddotgit = STRBUF_INIT;\n-\tstruct strbuf tmp = STRBUF_INIT;\n \n \tif (is_main_worktree(wt))\n \t\tgoto done;\n \n-\tstrbuf_realpath(&repo, git_common_path(\"worktrees/%s\", wt->id), 1);\n-\tstrbuf_addf(&gitdir, \"%s/gitdir\", repo.buf);\n+\tstrbuf_realpath(&gitdir, git_common_path(\"worktrees/%s/gitdir\", wt->id), 1);\n \n-\tif (strbuf_read_file(&olddotgit, gitdir.buf, 0) < 0)\n+\tif (strbuf_read_file(&dotgit, gitdir.buf, 0) < 0)\n \t\tgoto done;\n \n-\tstrbuf_rtrim(&olddotgit);\n-\tif (is_absolute_path(olddotgit.buf)) {\n-\t\tstrbuf_addbuf(&dotgit, &olddotgit);\n-\t} else {\n-\t\tstrbuf_addf(&dotgit, \"%s/worktrees/%s/%s\", old_path, wt->id, olddotgit.buf);\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-\tstrbuf_addbuf(&path, &dotgit);\n-\tstrbuf_strip_suffix(&path, \"/.git\");\n-\n-\twrite_file(dotgit.buf, \"gitdir: %s\", relative_path(repo.buf, path.buf, &tmp));\n-\twrite_file(gitdir.buf, \"%s\", relative_path(dotgit.buf, repo.buf, &tmp));\n+\twrite_worktree_linking_files(dotgit, gitdir);\n done:\n-\tstrbuf_release(&path);\n-\tstrbuf_release(&repo);\n \tstrbuf_release(&gitdir);\n \tstrbuf_release(&dotgit);\n-\tstrbuf_release(&olddotgit);\n-\tstrbuf_release(&tmp);\n }\n \n void repair_worktrees_after_gitdir_move(const char *old_path)\n@@ -725,12 +710,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 int infer_backlink(const char *gitfile, struct strbuf *inferred)\n {\n \tstruct strbuf actual = 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@@ -741,18 +729,16 @@ static int infer_backlink(const char *gitfile, struct strbuf *inferred)\n \tid++; /* advance past '/' to point at <id> */\n \tif (!*id)\n \t\tgoto error;\n-\tstrbuf_reset(inferred);\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 1;\n-\n+\treturn inferred->len;\n error:\n \tstrbuf_release(&actual);\n \tstrbuf_reset(inferred); /* clear invalid path */\n-\treturn 0;\n+\treturn -1;\n }\n \n /*\n@@ -763,13 +749,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-\tstruct strbuf tmp = STRBUF_INIT;\n \tchar *dotgit_contents = NULL;\n \tconst char *repair = NULL;\n \tint err;\n@@ -781,25 +764,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@@ -812,11 +795,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@@ -838,39 +821,35 @@ 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.len && fspathcmp(backlink.buf, inferred_backlink.buf)) {\n+\tif (inferred_backlink.len && fspathcmp(backlink.buf, inferred_backlink.buf))\n \t\tstrbuf_swap(&backlink, &inferred_backlink);\n-\t}\n \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\", relative_path(realdotgit.buf, backlink.buf, &tmp));\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-\tstrbuf_release(&tmp);\n }\n \n int should_prune_worktree(const char *id, struct strbuf *reason, char **wtpath, timestamp_t expire)\n@@ -1031,3 +1010,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 e96118621638667d87c5d7e0452ed10bd1ddf606..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@@ -215,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":"506133","messageId":"20241025-wt_relative_options-v1-2-c3005df76bf9@pm.me","threadId":"62408","inReplyTo":"20241025-wt_relative_options-v1-0-c3005df76bf9@pm.me","subject":"[PATCH 2/2] worktree: add `relativeWorktrees` extension","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-25T22:29:47Z","receivedAt":"2024-10-25T22:29:53Z","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 f4cee73d7a1edecafdff30b6d5e2d9dd1365b93e..0ae4a5f796f10c017ef90413e969e1622b54a897 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -1024,6 +1024,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":"506182","messageId":"Zx7YFPE5tjr/bn2s@nand.local","threadId":"62408","inReplyTo":"20241025-wt_relative_options-v1-1-c3005df76bf9@pm.me","subject":"Re: [PATCH 1/2] worktree: add CLI/config options for relative path linking","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-28T00:17:24Z","receivedAt":"2024-10-28T00:17:28Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Oct 25, 2024 at 10:29:37PM +0000, Caleb White wrote:\n> This patch introduces the `--[no-]relative-paths` CLI option for\n> `git worktree {add, move, repair}` commands, as well as the\n> `worktree.useRelativePaths` configuration setting. When enabled,\n> these options allow worktrees to be linked using relative paths,\n> enhancing portability across environments where absolute paths\n> may differ (e.g., containerized setups, shared network drives).\n>\n> Using the `--relative-paths` option with `worktree {move, repair}`\n> will convert absolute paths to relative ones, while `--no-relative-paths`\n> does the reverse. For cases where users want consistency in path\n> handling, the config option `worktree.useRelativePaths` provides\n> a persistent setting.\n>\n> A new helper function, `write_worktree_linking_files()`, centralizes\n> the logic for computing and writing either relative or absolute\n> paths, based on the provided configuration. This function accepts\n> `strbuf` pointers to both the worktree’s `.git` link and the\n> repository’s `gitdir`, and then writes the appropriate path to each.\n\nLooking at the patch below, it is quite large, and I wonder if it would\nbenefit from being split into smaller pieces. Perhaps factoring out\nwrite_worktree_linking_files() in a separate patch would be a good start\nhere?\n\nThanks,\nTaylor\n"},{"id":"506183","messageId":"Zx7YxLPItxvFJK62@nand.local","threadId":"62408","inReplyTo":"20241025-wt_relative_options-v1-2-c3005df76bf9@pm.me","subject":"Re: [PATCH 2/2] worktree: add `relativeWorktrees` extension","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-28T00:20:20Z","receivedAt":"2024-10-28T00:20:23Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Oct 25, 2024 at 10:29:47PM +0000, Caleb White wrote:\n> A new extension, `relativeWorktrees`, is added to indicate that at least\n> one worktree in the repository has been linked with relative paths. This\n> extension is automatically set when a worktree is created or repaired\n> using the `--relative-paths` option, or when the\n> `worktree.useRelativePaths` config is set to `true`.\n\nThis approach feels like a very heavy hammer. I wonder if writing\nworktrees with relative paths by default was too aggressive of a step,\nand if we should instead make the new behavior opt-in rather than\nopt-out.\n\nSaying that new worktrees are written with relative paths, and that\ncreating a worktree with a new version of Git breaks reading the\nrepository on older versions feels very unsatisfying to me.\n\n> The `relativeWorktrees` extension ensures older Git versions do not\n> attempt to automatically prune worktrees with relative paths, as they\n> would not not recognize the paths as being valid.\n\nThis is the piece of information that I was missing in the earlier round\nwhen I merged that down. I think we need to take a step back and think\nabout how to make this change safely in a way that doesn't break\ncompatibility with older versions of Git.\n\nThanks,\nTaylor\n"},{"id":"506185","messageId":"Zx7cKN9X56GrHrU/@nand.local","threadId":"62408","inReplyTo":"Zx7YFPE5tjr/bn2s@nand.local","subject":"Re: [PATCH 1/2] worktree: add CLI/config options for relative path linking","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-28T00:34:48Z","receivedAt":"2024-10-28T00:34:52Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sun, Oct 27, 2024 at 08:17:24PM -0400, Taylor Blau wrote:\n> On Fri, Oct 25, 2024 at 10:29:37PM +0000, Caleb White wrote:\n> > This patch introduces the `--[no-]relative-paths` CLI option for\n> > `git worktree {add, move, repair}` commands, as well as the\n> > `worktree.useRelativePaths` configuration setting. When enabled,\n> > these options allow worktrees to be linked using relative paths,\n> > enhancing portability across environments where absolute paths\n> > may differ (e.g., containerized setups, shared network drives).\n> >\n> > Using the `--relative-paths` option with `worktree {move, repair}`\n> > will convert absolute paths to relative ones, while `--no-relative-paths`\n> > does the reverse. For cases where users want consistency in path\n> > handling, the config option `worktree.useRelativePaths` provides\n> > a persistent setting.\n> >\n> > A new helper function, `write_worktree_linking_files()`, centralizes\n> > the logic for computing and writing either relative or absolute\n> > paths, based on the provided configuration. This function accepts\n> > `strbuf` pointers to both the worktree’s `.git` link and the\n> > repository’s `gitdir`, and then writes the appropriate path to each.\n>\n> Looking at the patch below, it is quite large, and I wonder if it would\n> benefit from being split into smaller pieces. Perhaps factoring out\n> write_worktree_linking_files() in a separate patch would be a good start\n> here?\n\nAdditionally, it appears that this patch breaks at least t0001-init.sh,\nbut others as well. The relevant portion of -vx from t0001.46 is:\n\n    --- 8< ---\n    + git -C mainwt config worktree.useRelativePaths true\n    + git -C mainwt worktree add --detach ../linkwt\n    Preparing worktree (detached HEAD 89e2b84)\n    HEAD is now at 89e2b84 gumby\n    + git -C mainwt init --separate-git-dir ../seprepo\n    Reinitialized existing Git repository in /home/ttaylorr/src/git/t/trash directory.t0001-init/seprepo/\n    + git -C mainwt rev-parse --git-common-dir\n    fatal: repo version is 0, but v1-only extension found:\n      relativeworktrees\n    --- >8 ---\n\nLet's please fix this breakage, and then decide what we are going to do\nwith the extension in the second patch relatively soon, as I worry that\nputting the original topic on master may have been a mistake if it is\ngoing to break worktree pruning on earlier Git versions.\n\nThanks,\nTaylor\n"},{"id":"506186","messageId":"D571HWYAD4MM.28JAS7D0Y6OI3@pm.me","threadId":"62408","inReplyTo":"Zx7YxLPItxvFJK62@nand.local","subject":"Re: [PATCH 2/2] worktree: add `relativeWorktrees` extension","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-28T01:14:51Z","receivedAt":"2024-10-28T01:14:56Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"On Sun Oct 27, 2024 at 7:20 PM CDT, Taylor Blau wrote:\n> On Fri, Oct 25, 2024 at 10:29:47PM +0000, Caleb White wrote:\n>> A new extension, `relativeWorktrees`, is added to indicate that at least\n>> one worktree in the repository has been linked with relative paths. This\n>> extension is automatically set when a worktree is created or repaired\n>> using the `--relative-paths` option, or when the\n>> `worktree.useRelativePaths` config is set to `true`.\n>\n> This approach feels like a very heavy hammer. I wonder if writing\n> worktrees with relative paths by default was too aggressive of a step,\n> and if we should instead make the new behavior opt-in rather than\n> opt-out.\n\nThe v4 series of the original round added the cli options and updated\nthe relative worktrees to be opt-in. This patch keeps the git default\nbehavior of writing worktrees with absolute paths, and users can opt-in\nvia the `--relative-paths` cli option or the `worktree.useRelativePaths`\nconfig.\n\n> Saying that new worktrees are written with relative paths, and that\n> creating a worktree with a new version of Git breaks reading the\n> repository on older versions feels very unsatisfying to me.\n>\n>> The `relativeWorktrees` extension ensures older Git versions do not\n>> attempt to automatically prune worktrees with relative paths, as they\n>> would not not recognize the paths as being valid.\n>\n> This is the piece of information that I was missing in the earlier round\n> when I merged that down. I think we need to take a step back and think\n> about how to make this change safely in a way that doesn't break\n> compatibility with older versions of Git.\n\nAdding the extension was the direction suggested by Junio in the\nprevious round. Git did not account for the possibility of the linking\nfiles containing relative paths, so there's really no way to make this\nchange without breaking compatibility with older versions of Git. Git\nhad to be taught how to handle files that could contain either absolute\nor relative paths.\n\nBest,\nCaleb\n\n"},{"id":"506187","messageId":"D571JAIAQYRE.2KDSYJ5EXL31C@pm.me","threadId":"62408","inReplyTo":"Zx7YFPE5tjr/bn2s@nand.local","subject":"Re: [PATCH 1/2] worktree: add CLI/config options for relative path linking","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-28T01:16:38Z","receivedAt":"2024-10-28T01:16:47Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"On Sun Oct 27, 2024 at 7:17 PM CDT, Taylor Blau wrote:\n> Looking at the patch below, it is quite large, and I wonder if it would\n> benefit from being split into smaller pieces. Perhaps factoring out\n> write_worktree_linking_files() in a separate patch would be a good start\n> here?\n\nI can try to break it up into smaller patches. I'll start with the one\nyou suggested and can likely split the tests into their own patch as\nwell.\n\nBest,\nCaleb\n\n"},{"id":"506228","messageId":"D57L2P544W08.2MHA3Q38UBPEO@pm.me","threadId":"62408","inReplyTo":"Zx7cKN9X56GrHrU/@nand.local","subject":"Re: [PATCH 1/2] worktree: add CLI/config options for relative path linking","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-28T16:35:22Z","receivedAt":"2024-10-28T16:35:30Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"On Sun Oct 27, 2024 at 7:34 PM CDT, Taylor Blau wrote:\n> Additionally, it appears that this patch breaks at least t0001-init.sh,\n> but others as well. The relevant portion of -vx from t0001.46 is:\n>\n>     --- 8< ---\n>     + git -C mainwt config worktree.useRelativePaths true\n>     + git -C mainwt worktree add --detach ../linkwt\n>     Preparing worktree (detached HEAD 89e2b84)\n>     HEAD is now at 89e2b84 gumby\n>     + git -C mainwt init --separate-git-dir ../seprepo\n>     Reinitialized existing Git repository in /home/ttaylorr/src/git/t/trash directory.t0001-init/seprepo/\n>     + git -C mainwt rev-parse --git-common-dir\n>     fatal: repo version is 0, but v1-only extension found:\n>       relativeworktrees\n>     --- >8 ---\n>\n> Let's please fix this breakage, and then decide what we are going to do\n> with the extension in the second patch relatively soon, as I worry that\n> putting the original topic on master may have been a mistake if it is\n> going to break worktree pruning on earlier Git versions.\n\nThanks for catching this, the issue is that there's a bug in the\n`initialize_repository_version()` function when reinitializing a\nrepository---the function doesn't check if there are other extensions\nin use before downgrading the repository version to 0.\n\nThis is a rare edge case, but I'll work on a fix.\n\nBest,\nCaleb\n\n"},{"id":"506232","messageId":"Zx/B3caIgAeAv6Kz@nand.local","threadId":"62408","inReplyTo":"D57L2P544W08.2MHA3Q38UBPEO@pm.me","subject":"Re: [PATCH 1/2] worktree: add CLI/config options for relative path linking","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-28T16:54:53Z","receivedAt":"2024-10-28T16:54:57Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Mon, Oct 28, 2024 at 04:35:22PM +0000, Caleb White wrote:\n> On Sun Oct 27, 2024 at 7:34 PM CDT, Taylor Blau wrote:\n> > Additionally, it appears that this patch breaks at least t0001-init.sh,\n> > but others as well. The relevant portion of -vx from t0001.46 is:\n> >\n> >     --- 8< ---\n> >     + git -C mainwt config worktree.useRelativePaths true\n> >     + git -C mainwt worktree add --detach ../linkwt\n> >     Preparing worktree (detached HEAD 89e2b84)\n> >     HEAD is now at 89e2b84 gumby\n> >     + git -C mainwt init --separate-git-dir ../seprepo\n> >     Reinitialized existing Git repository in /home/ttaylorr/src/git/t/trash directory.t0001-init/seprepo/\n> >     + git -C mainwt rev-parse --git-common-dir\n> >     fatal: repo version is 0, but v1-only extension found:\n> >       relativeworktrees\n> >     --- >8 ---\n> >\n> > Let's please fix this breakage, and then decide what we are going to do\n> > with the extension in the second patch relatively soon, as I worry that\n> > putting the original topic on master may have been a mistake if it is\n> > going to break worktree pruning on earlier Git versions.\n>\n> Thanks for catching this, the issue is that there's a bug in the\n> `initialize_repository_version()` function when reinitializing a\n> repository---the function doesn't check if there are other extensions\n> in use before downgrading the repository version to 0.\n>\n> This is a rare edge case, but I'll work on a fix.\n\nI am confused... are you saying t0001.46 is flaky? I don't think that\nit is, as it fails consistently for me with your patches applied when\nran in a loop.\n\nI am definitely guilty of having sent broken patches to the list before\nthat fail CI, usually when I have amended something I thought was\ntrivial after already running the test suite on all patches, only to\nrealize that it wasn't trivial after all and instead broken something.\n\nBut please do be careful to thoroughly vet your patches before sending\nthem to the list, as this sort of breakage can be disruptive.\n\nThanks,\nTaylor\n"},{"id":"506234","messageId":"Zx/FAoj2jcISsv0X@nand.local","threadId":"62408","inReplyTo":"D571HWYAD4MM.28JAS7D0Y6OI3@pm.me","subject":"Re: [PATCH 2/2] worktree: add `relativeWorktrees` extension","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-28T17:08:18Z","receivedAt":"2024-10-28T17:08:22Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Mon, Oct 28, 2024 at 01:14:51AM +0000, Caleb White wrote:\n> On Sun Oct 27, 2024 at 7:20 PM CDT, Taylor Blau wrote:\n> > On Fri, Oct 25, 2024 at 10:29:47PM +0000, Caleb White wrote:\n> >> A new extension, `relativeWorktrees`, is added to indicate that at least\n> >> one worktree in the repository has been linked with relative paths. This\n> >> extension is automatically set when a worktree is created or repaired\n> >> using the `--relative-paths` option, or when the\n> >> `worktree.useRelativePaths` config is set to `true`.\n> >\n> > This approach feels like a very heavy hammer. I wonder if writing\n> > worktrees with relative paths by default was too aggressive of a step,\n> > and if we should instead make the new behavior opt-in rather than\n> > opt-out.\n>\n> The v4 series of the original round added the cli options and updated\n> the relative worktrees to be opt-in. This patch keeps the git default\n> behavior of writing worktrees with absolute paths, and users can opt-in\n> via the `--relative-paths` cli option or the `worktree.useRelativePaths`\n> config.\n\nOK, I think the mistake here is mine. I did not see\n\n  https://lore.kernel.org/git/xmqqfrp4onjd.fsf@gitster.g/\n\nwhen triaging the list after Junio went offline for vacation. Had I not\nlost that email, I would not have merged the earlier round without more\ndiscussion.\n\nThat being said, it is still greatly appreciated when contributors can\nfollow the WC reports when they have patches that are moving through the\nvarious integration branches. That way you can see my \"Will merge to\n'next'\" comment and say \"please hold, I am working on a new round that\nis substantially different / uncovers some backwards incompatibility /\netc.\" and we can wait appropriately.\n\nNow we are in the rather unfortunate situation of having merged\nsomething to 'master' that (with the additional information that I\nmissed earlier) it is not clear that I would have merged in its existing\nform at the time.\n\nBut that's OK, and we can figure out a path forward here. I am just\ntrying to say that this highlights the importance of following the WC\nreports regularly to catch cases where the maintainer missed some\nimportant piece of information.\n\n> > Saying that new worktrees are written with relative paths, and that\n> > creating a worktree with a new version of Git breaks reading the\n> > repository on older versions feels very unsatisfying to me.\n> >\n> >> The `relativeWorktrees` extension ensures older Git versions do not\n> >> attempt to automatically prune worktrees with relative paths, as they\n> >> would not not recognize the paths as being valid.\n> >\n> > This is the piece of information that I was missing in the earlier round\n> > when I merged that down. I think we need to take a step back and think\n> > about how to make this change safely in a way that doesn't break\n> > compatibility with older versions of Git.\n>\n> Adding the extension was the direction suggested by Junio in the\n> previous round. Git did not account for the possibility of the linking\n> files containing relative paths, so there's really no way to make this\n> change without breaking compatibility with older versions of Git. Git\n> had to be taught how to handle files that could contain either absolute\n> or relative paths.\n\nYep, that makes sense. My preference here would be to make the new\nbehavior opt *in*, rather than opt-out, so that:\n\n  - Users who do not experience problems with writing worktrees that\n    have absolute paths can continue to do so without any changes.\n\n  - Users who use worktrees *and* do not write relative paths can\n    upgrade between successive versions without requiring a new\n    repository extension that would break older Git versions.\n\n  - That we only add that extension to the repository's configuration if\n    and when the user has opted into the new behavior.\n\nReading this new series, I *think* that is the behavior that you settled\non, which seems quite reasonable to me. Can you confirm that I'm reading\nthis all correctly? Assuming so, I think that we are in a reasonable\nposition[^1] to review this series instead of having to back out the new\nbehavior.\n\nThanks for bearing with me here, I am quite embarrassed to have missed\nJunio's mail that I mentioned earlier, but I appreciate your patience\nwhile we sort this out together.\n\nThanks,\nTaylor\n\n[^1]: Making sure that it gets in before 2.48, and is not dropped,\n  though we still have quite a lot of time on that front.\n"},{"id":"506243","messageId":"D57NXXVF7BEW.2JASTW8099JUI@pm.me","threadId":"62408","inReplyTo":"Zx/B3caIgAeAv6Kz@nand.local","subject":"Re: [PATCH 1/2] worktree: add CLI/config options for relative path linking","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-28T18:50:12Z","receivedAt":"2024-10-28T18:50:23Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"On Mon Oct 28, 2024 at 11:54 AM CDT, Taylor Blau wrote:\n> On Mon, Oct 28, 2024 at 04:35:22PM +0000, Caleb White wrote:\n>> Thanks for catching this, the issue is that there's a bug in the\n>> `initialize_repository_version()` function when reinitializing a\n>> repository---the function doesn't check if there are other extensions\n>> in use before downgrading the repository version to 0.\n>>\n>> This is a rare edge case, but I'll work on a fix.\n>\n> I am confused... are you saying t0001.46 is flaky? I don't think that\n> it is, as it fails consistently for me with your patches applied when\n> ran in a loop.\n\nNo, the test is not flaky. Adding the extension just revealed a bug in\nthe code that was not caught by the test suite. I've fixed the bug and\nwill push v2 here shortly.\n\n> I am definitely guilty of having sent broken patches to the list before\n> that fail CI, usually when I have amended something I thought was\n> trivial after already running the test suite on all patches, only to\n> realize that it wasn't trivial after all and instead broken something.\n>\n> But please do be careful to thoroughly vet your patches before sending\n> them to the list, as this sort of breakage can be disruptive.\n\nThe test suite was passing, I must've just forgotten to execute this\nagain test after I added the extension. I'll be more careful in the\nfuture.\n\nBest,\nCaleb\n\n"},{"id":"506244","messageId":"D57O5LHGRN1M.WHYPYUEOUOFM@pm.me","threadId":"62408","inReplyTo":"Zx/FAoj2jcISsv0X@nand.local","subject":"Re: [PATCH 2/2] worktree: add `relativeWorktrees` extension","fromName":"Caleb White","fromEmail":"cdwhite3@pm.me","sentAt":"2024-10-28T19:00:11Z","receivedAt":"2024-10-28T19:00:17Z","isPatch":true,"sender":{"key":"cdwhite3@pm.me","avatar":"https://avatars.githubusercontent.com/u/4176520?v=4"},"body":"On Mon Oct 28, 2024 at 12:08 PM CDT, Taylor Blau wrote:\n> OK, I think the mistake here is mine. I did not see\n>\n>   https://lore.kernel.org/git/xmqqfrp4onjd.fsf@gitster.g/\n>\n> when triaging the list after Junio went offline for vacation. Had I not\n> lost that email, I would not have merged the earlier round without more\n> discussion.\n>\n> That being said, it is still greatly appreciated when contributors can\n> follow the WC reports when they have patches that are moving through the\n> various integration branches. That way you can see my \"Will merge to\n> 'next'\" comment and say \"please hold, I am working on a new round that\n> is substantially different / uncovers some backwards incompatibility /\n> etc.\" and we can wait appropriately.\n>\n> Now we are in the rather unfortunate situation of having merged\n> something to 'master' that (with the additional information that I\n> missed earlier) it is not clear that I would have merged in its existing\n> form at the time.\n>\n> But that's OK, and we can figure out a path forward here. I am just\n> trying to say that this highlights the importance of following the WC\n> reports regularly to catch cases where the maintainer missed some\n> important piece of information.\n\nMy apologies, this was my first patch submission to Git and I was not\nexactly the process by which topics progressed from `seen` to `next` to\n`master`. I will be sure to follow the reports more closely in the future.\n\n>> Adding the extension was the direction suggested by Junio in the\n>> previous round. Git did not account for the possibility of the linking\n>> files containing relative paths, so there's really no way to make this\n>> change without breaking compatibility with older versions of Git. Git\n>> had to be taught how to handle files that could contain either absolute\n>> or relative paths.\n>\n> Yep, that makes sense. My preference here would be to make the new\n> behavior opt *in*, rather than opt-out, so that:\n>\n>   - Users who do not experience problems with writing worktrees that\n>     have absolute paths can continue to do so without any changes.\n>\n>   - Users who use worktrees *and* do not write relative paths can\n>     upgrade between successive versions without requiring a new\n>     repository extension that would break older Git versions.\n>\n>   - That we only add that extension to the repository's configuration if\n>     and when the user has opted into the new behavior.\n>\n> Reading this new series, I *think* that is the behavior that you settled\n> on, which seems quite reasonable to me. Can you confirm that I'm reading\n> this all correctly? Assuming so, I think that we are in a reasonable\n> position[^1] to review this series instead of having to back out the new\n> behavior.\n\nYes this is correct. The new behavior is opt-in and the extension is\nonly added to the repository configuration if the user creates\na worktree with relative paths.\n\n> Thanks for bearing with me here, I am quite embarrassed to have missed\n> Junio's mail that I mentioned earlier, but I appreciate your patience\n> while we sort this out together.\n\nNo worries! I appreciate your feedback and I'm glad we're able to\nsort this out.\n\nBest,\nCaleb\n\n"},{"id":"506269","messageId":"ZyAgC1dRXIiLX9Vn@nand.local","threadId":"62408","inReplyTo":"D57O5LHGRN1M.WHYPYUEOUOFM@pm.me","subject":"Re: [PATCH 2/2] worktree: add `relativeWorktrees` extension","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-10-28T23:36:43Z","receivedAt":"2024-10-28T23:36:47Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Mon, Oct 28, 2024 at 07:00:11PM +0000, Caleb White wrote:\n> > But that's OK, and we can figure out a path forward here. I am just\n> > trying to say that this highlights the importance of following the WC\n> > reports regularly to catch cases where the maintainer missed some\n> > important piece of information.\n>\n> My apologies, this was my first patch submission to Git and I was not\n> exactly the process by which topics progressed from `seen` to `next` to\n> `master`. I will be sure to follow the reports more closely in the future.\n\nIt's not a problem, and I am glad that you have found an interest in\ncontributing to the Git project. We'll figure this one out :-).\n\n> >> Adding the extension was the direction suggested by Junio in the\n> >> previous round. Git did not account for the possibility of the linking\n> >> files containing relative paths, so there's really no way to make this\n> >> change without breaking compatibility with older versions of Git. Git\n> >> had to be taught how to handle files that could contain either absolute\n> >> or relative paths.\n> >\n> > Yep, that makes sense. My preference here would be to make the new\n> > behavior opt *in*, rather than opt-out, so that:\n> >\n> >   - Users who do not experience problems with writing worktrees that\n> >     have absolute paths can continue to do so without any changes.\n> >\n> >   - Users who use worktrees *and* do not write relative paths can\n> >     upgrade between successive versions without requiring a new\n> >     repository extension that would break older Git versions.\n> >\n> >   - That we only add that extension to the repository's configuration if\n> >     and when the user has opted into the new behavior.\n> >\n> > Reading this new series, I *think* that is the behavior that you settled\n> > on, which seems quite reasonable to me. Can you confirm that I'm reading\n> > this all correctly? Assuming so, I think that we are in a reasonable\n> > position[^1] to review this series instead of having to back out the new\n> > behavior.\n>\n> Yes this is correct. The new behavior is opt-in and the extension is\n> only added to the repository configuration if the user creates\n> a worktree with relative paths.\n\nThat is great. I'm glad that we're on the same page here, and that my\nunderstanding matches reality.\n\n> > Thanks for bearing with me here, I am quite embarrassed to have missed\n> > Junio's mail that I mentioned earlier, but I appreciate your patience\n> > while we sort this out together.\n>\n> No worries! I appreciate your feedback and I'm glad we're able to\n> sort this out.\n\nNot a problem, and again, I very much appreciate your patience and\nwillingness to work on this.\n\nThanks,\nTaylor\n"}]}