{"thread":{"id":"25367","subject":"[PATCH] worktree: provide better prefix to go back to original cwd","startedAt":"2010-10-06T13:59:38Z","lastAt":"2010-10-07T03:14:45Z","messageCount":6,"participants":["Nguyễn Thái Ngọc Duy","Chris Packham","Jonathan Nieder","Junio C Hamano","Nguyen Thai Ngoc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"152761","messageId":"1286373578-2484-1-git-send-email-pclouds@gmail.com","threadId":"25367","inReplyTo":null,"subject":"[PATCH] worktree: provide better prefix to go back to original cwd","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-10-06T13:59:38Z","receivedAt":"2010-10-06T13:59:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"When both GIT_DIR and GIT_WORK_TREE are set, if cwd is outside worktree,\nprefix (the one passed to every builtin commands) will be set to NULL,\nwhich means \"user stays at worktree topdir\".\n\nAs a consequence, command line arguments are supposed to be relative\nto worktree topdir, not current working directory. Not very intuitive.\nMoreover, output from such situation is (again) relative to worktree\ntopdir. Users are expected to understand that.\n\nThis patch allows builtin commands access to original cwd even if it's\noutside worktree, via cwd_to_worktree and worktree_to_cwd fields. As\nthe name implies, if you stay at original cwd, \"cd $(cwd_to_worktree)\"\nwould take you to worktree topdir and vice versa.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n startup_info->cwd_to_worktree would be as same as opt.submodule_prefix\n in your 2/3 patch.\n\n builtin/rev-parse.c        |   10 ++++\n cache.h                    |    2 +\n setup.c                    |  108 ++++++++++++++++++++++++++++++++++++++++++--\n t/t1510-worktree-prefix.sh |   52 +++++++++++++++++++++\n 4 files changed, 168 insertions(+), 4 deletions(-)\n create mode 100755 t/t1510-worktree-prefix.sh\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex a5a1c86..525610e 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -623,6 +623,16 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tputs(prefix);\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--cwd-to-worktree\")) {\n+\t\t\t\tif (startup_info->cwd_to_worktree)\n+\t\t\t\t\tputs(startup_info->cwd_to_worktree);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (!strcmp(arg, \"--worktree-to-cwd\")) {\n+\t\t\t\tif (startup_info->worktree_to_cwd)\n+\t\t\t\t\tputs(startup_info->worktree_to_cwd);\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--show-cdup\")) {\n \t\t\t\tconst char *pfx = prefix;\n \t\t\t\tif (!is_inside_work_tree()) {\ndiff --git a/cache.h b/cache.h\nindex 2ef2fa3..8256e1c 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1110,6 +1110,8 @@ const char *split_cmdline_strerror(int cmdline_errno);\n /* git.c */\n struct startup_info {\n \tint have_repository;\n+\tchar *cwd_to_worktree; /* chdir(\"this\"); from cwd would return to worktree */\n+\tchar *worktree_to_cwd; /* chdir(\"this\"); from worktree would return to cwd */\n };\n extern struct startup_info *startup_info;\n \ndiff --git a/setup.c b/setup.c\nindex a3b76de..413703b 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -313,10 +313,109 @@ const char *read_gitfile_gently(const char *path)\n \treturn path;\n }\n \n+/*\n+ * Given \"foo/bar\" and \"hey/hello/world\", return \"../../hey/hello/world/\"\n+ * Either path1 or path2 can be NULL\n+ */\n+static char *make_path_to_path(const char *path1, const char *path2)\n+{\n+\tint nr_back = 0;\n+\tint i, pathlen = path2 ? strlen(path2) : 0;\n+\tchar *buf, *p;\n+\n+\tif (path1 && *path1) {\n+\t\tnr_back = 1;\n+\t\twhile (*path1) {\n+\t\t\tif (*path1 == '/')\n+\t\t\t\tnr_back++;\n+\t\t\tpath1++;\n+\t\t}\n+\t}\n+\n+\tif (!nr_back && !pathlen)\n+\t\treturn NULL;\n+\n+\tp = buf = xmalloc(3*nr_back + pathlen + 2); /* \"../\"^nr_back + path2 + '/' + NULL */\n+\tfor (i = 0; i < nr_back; i++) {\n+\t\tmemcpy(p, \"../\", 3);\n+\t\tp += 3;\n+\t}\n+\tif (pathlen) {\n+\t\tmemcpy(p, path2, pathlen);\n+\t\tp += pathlen;\n+\t\t*p++ = '/';\n+\t}\n+\t*p = '\\0';\n+\treturn buf;\n+}\n+\n+/*\n+ * Return a prefix if cwd inside worktree, or NULL otherwise.\n+ * Also fill startup_info struct.\n+ */\n+static const char *setup_prefix(const char *cwd)\n+{\n+\tconst char *worktree = get_git_work_tree();\n+\tint len = 0, cwd_len = strlen(cwd), worktree_len = strlen(worktree);\n+\n+\twhile (worktree[len] && worktree[len] == cwd[len])\n+\t\tlen++;\n+\n+\tif (!worktree[len] && !cwd[len]) {\n+\t\tif (startup_info) {\n+\t\t\tstartup_info->cwd_to_worktree = NULL;\n+\t\t\tstartup_info->worktree_to_cwd = NULL;\n+\t\t}\n+\t\treturn NULL;\n+\t}\n+\t/* get /foo/, not /foo/baa if /foo/baa1 and /foo/baa2 are given */\n+\telse if (worktree[len] && cwd[len]) {\n+\t\twhile (len && worktree[len] != '/')\n+\t\t\tlen--;\n+\t\tlen++;\n+\t}\n+\telse {\n+\t\tif (worktree[len]) {\n+\t\t\tif (worktree[len] != '/') {\n+\t\t\t\twhile (len && worktree[len] != '/')\n+\t\t\t\t\tlen--;\n+\t\t\t}\n+\t\t}\n+\t\telse {\n+\t\t\tif (cwd[len] != '/') {\n+\t\t\t\twhile (len && cwd[len] != '/')\n+\t\t\t\t\tlen--;\n+\t\t\t}\n+\t\t}\n+\t\tlen++;\t\t/* must be a slash here, skip it */\n+\t}\n+\n+\tif (len < cwd_len && len < worktree_len) {\n+\t\tif (startup_info) {\n+\t\t\tstartup_info->cwd_to_worktree = make_path_to_path(cwd+len, worktree+len);\n+\t\t\tstartup_info->worktree_to_cwd = make_path_to_path(worktree+len, cwd+len);\n+\t\t}\n+\t\treturn NULL;\n+\t}\n+\n+\tif (startup_info) {\n+\t\tif (len < cwd_len) { /* cwd inside worktree */\n+\t\t\tstartup_info->cwd_to_worktree = make_path_to_path(cwd+len, NULL);\n+\t\t\tstartup_info->worktree_to_cwd = make_path_to_path(NULL, cwd+len);\n+\t\t}\n+\t\telse {\n+\t\t\tstartup_info->cwd_to_worktree = make_path_to_path(NULL, worktree+len);\n+\t\t\tstartup_info->worktree_to_cwd = make_path_to_path(worktree+len, NULL);\n+\t\t}\n+\t}\n+\n+\treturn len < cwd_len ? cwd+len : NULL;\n+}\n+\n static const char *setup_explicit_git_dir(const char *gitdirenv,\n \t\t\t\tconst char *work_tree_env, int *nongit_ok)\n {\n-\tstatic char buffer[1024 + 1];\n+\tstatic char buffer[PATH_MAX];\n \tconst char *retval;\n \n \tif (PATH_MAX - 40 < strlen(gitdirenv))\n@@ -337,9 +436,10 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,\n \t}\n \tif (check_repository_format_gently(nongit_ok))\n \t\treturn NULL;\n-\tretval = get_relative_cwd(buffer, sizeof(buffer) - 1,\n-\t\t\tget_git_work_tree());\n-\tif (!retval || !*retval)\n+\tif (!getcwd(buffer, sizeof(buffer)))\n+\t\tdie_errno(\"can't find the current directory\");\n+\tretval = setup_prefix(buffer);\n+\tif (!retval)\n \t\treturn NULL;\n \tset_git_dir(make_absolute_path(gitdirenv));\n \tif (chdir(work_tree_env) < 0)\ndiff --git a/t/t1510-worktree-prefix.sh b/t/t1510-worktree-prefix.sh\nnew file mode 100755\nindex 0000000..3839493\n--- /dev/null\n+++ b/t/t1510-worktree-prefix.sh\n@@ -0,0 +1,52 @@\n+#!/bin/sh\n+\n+test_description='test rev-parse --cwd-to-worktree and --worktree-to-cwd'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'setup' '\n+\tmkdir foo bar &&\n+\tmv .git foo &&\n+\tmkdir foo/bar &&\n+\tGIT_DIR=`pwd`/foo/.git &&\n+\tGIT_WORK_TREE=`pwd`/foo &&\n+\texport GIT_DIR GIT_WORK_TREE\n+'\n+\n+test_expect_success 'at root' '\n+\t(\n+\tcd foo &&\n+\tgit rev-parse --cwd-to-worktree --worktree-to-cwd >result &&\n+\t: >expected &&\n+\ttest_cmp expected result\n+\t)\n+'\n+\n+test_expect_success 'cwd inside worktree' '\n+\t(\n+\tcd foo/bar &&\n+\tgit rev-parse --cwd-to-worktree --worktree-to-cwd >result &&\n+\techo ../ >expected &&\n+\techo bar/ >>expected &&\n+\ttest_cmp expected result\n+\t)\n+'\n+\n+test_expect_success 'cwd outside worktree' '\n+\tgit rev-parse --cwd-to-worktree --worktree-to-cwd >result &&\n+\techo foo/ >expected &&\n+\techo ../ >>expected &&\n+\ttest_cmp expected result\n+'\n+\n+test_expect_success 'cwd outside worktree (2)' '\n+\t(\n+\tcd bar &&\n+\tgit rev-parse --cwd-to-worktree --worktree-to-cwd >result &&\n+\techo ../foo/ >expected &&\n+\techo ../bar/ >>expected &&\n+\ttest_cmp expected result\n+\t)\n+'\n+\n+test_done\n-- \n1.7.0.2.445.gcbdb3\n"},{"id":"152767","messageId":"4CAC9A21.7030401@gmail.com","threadId":"25367","inReplyTo":"1286373578-2484-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] worktree: provide better prefix to go back to original cwd","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2010-10-06T15:47:45Z","receivedAt":"2010-10-06T15:47:45Z","isPatch":true,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"On 06/10/10 06:59, Nguyễn Thái Ngọc Duy wrote:\n> When both GIT_DIR and GIT_WORK_TREE are set, if cwd is outside worktree,\n> prefix (the one passed to every builtin commands) will be set to NULL,\n> which means \"user stays at worktree topdir\".\n> \n> As a consequence, command line arguments are supposed to be relative\n> to worktree topdir, not current working directory. Not very intuitive.\n> Moreover, output from such situation is (again) relative to worktree\n> topdir. Users are expected to understand that.\n> \n> This patch allows builtin commands access to original cwd even if it's\n> outside worktree, via cwd_to_worktree and worktree_to_cwd fields. As\n> the name implies, if you stay at original cwd, \"cd $(cwd_to_worktree)\"\n> would take you to worktree topdir and vice versa.\n> \n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  startup_info->cwd_to_worktree would be as same as opt.submodule_prefix\n>  in your 2/3 patch.\n\nThanks. I must admit I was struggling a little with implementing this\npart. I'll be sending out a re-roll of my series shortly and I'll\ninclude your patch if Junio doesn't pick it up on its own. I was also\nplanning on re-basing my patches on top of next or pu so more people can\nactually compile it.\n"},{"id":"152772","messageId":"20101006180727.GA2118@burratino","threadId":"25367","inReplyTo":"1286373578-2484-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] worktree: provide better prefix to go back to original cwd","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-06T18:07:28Z","receivedAt":"2010-10-06T18:07:28Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Nguyễn Thái Ngọc Duy wrote:\n\n> This patch allows builtin commands access to original cwd even if it's\n> outside worktree, via cwd_to_worktree and worktree_to_cwd fields.\n> --- a/builtin/rev-parse.c\n> +++ b/builtin/rev-parse.c\n> @@ -623,6 +623,16 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n>  \t\t\t\t\tputs(prefix);\n>  \t\t\t\tcontinue;\n>  \t\t\t}\n> +\t\t\tif (!strcmp(arg, \"--cwd-to-worktree\")) {\n> +\t\t\t\tif (startup_info->cwd_to_worktree)\n> +\t\t\t\t\tputs(startup_info->cwd_to_worktree);\n> +\t\t\t\tcontinue;\n> +\t\t\t}\n> +\t\t\tif (!strcmp(arg, \"--worktree-to-cwd\")) {\n> +\t\t\t\tif (startup_info->worktree_to_cwd)\n> +\t\t\t\t\tputs(startup_info->worktree_to_cwd);\n> +\t\t\t\tcontinue;\n> +\t\t\t}\n\nNice.\n\nI wonder if this should use something like\n\n\telse\n\t\tputs(\".\");\n\nor\n\n\telse\n\t\tputchar('\\n');\n\n.  What would be most convenient for scripted callers?\n\nWhat do these commands do when run from a bare repository?  Is the\nworktree the .git dir in that case, do they fail, or does something\nelse happen?\n\nAre there any examples to illustrate whether teaching --show-prefix to\ndo what your --worktree-to-cwd does would be a good or bad idea?\n(Just curious.)\n\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -1110,6 +1110,8 @@ const char *split_cmdline_strerror(int cmdline_errno);\n>  /* git.c */\n>  struct startup_info {\n>  \tint have_repository;\n> +\tchar *cwd_to_worktree; /* chdir(\"this\"); from cwd would return to worktree */\n> +\tchar *worktree_to_cwd; /* chdir(\"this\"); from worktree would return to cwd */\n\nComment nit: would\n\n\t\t\t\t/* path from original cwd to worktree */\n\t\t\t\t/* path from worktree to original cwd */\n\nbe clearer?  But presumably any confused people should be able to find\nyour log message.\n\n> --- a/setup.c\n> +++ b/setup.c\n> @@ -313,10 +313,109 @@ const char *read_gitfile_gently(const char *path)\n>  \treturn path;\n>  }\n>  \n> +/*\n> + * Given \"foo/bar\" and \"hey/hello/world\", return \"../../hey/hello/world/\"\n> + * Either path1 or path2 can be NULL\n> + */\n> +static char *make_path_to_path(const char *path1, const char *path2)\n\nNice.  Do we need to worry about:\n\n - alternate directory separators? (hey\\hello\\world)\n - DOS drive prefix? (c:\\foo\\bar, d:\\hey\\hello\\world)\n - relative paths with DOS drive? (c:\\foo\\bar, d:hello)\n - doubled-up directory separators? (hey//hello/world, //foo/bar)\n - non-canonical paths? (hey/./hello/../hello/world)\n\nI'm guessing some of the answers are \"no\", depending on where these\npaths come from.  Compare make_relative_path().\n[...]\n\n>  static const char *setup_explicit_git_dir(const char *gitdirenv,\n>  \t\t\t\tconst char *work_tree_env, int *nongit_ok)\n>  {\n> -\tstatic char buffer[1024 + 1];\n> +\tstatic char buffer[PATH_MAX];\n\nWhy?\n\nIt might make sense to error out a little before PATH_MAX (though\nlater than 1024), to account for subdirs (e.g., objects/).  Not sure.\n"},{"id":"152774","messageId":"7v4ocz18az.fsf@alter.siamese.dyndns.org","threadId":"25367","inReplyTo":"20101006180727.GA2118@burratino","subject":"Re: [PATCH] worktree: provide better prefix to go back to original cwd","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-10-06T18:32:20Z","receivedAt":"2010-10-06T18:32:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> Are there any examples to illustrate whether teaching --show-prefix to\n> do what your --worktree-to-cwd does would be a good or bad idea?\n> (Just curious.)\n\nDo these additions interact well with the notion of \"we are in the working\ntree\" vs \"we are outside the working tree\"?  Even when we happen to know\nvia GIT_WORK_TREE that the root of the working tree is /var/tmp/junk, we\nshould correctly diagnse that we are outside the working tree when we are\nin /var/tmp/, and require_work_tree should say \"no you are not allowed to\ndo this\", no?\n\n>> --- a/cache.h\n>> +++ b/cache.h\n>> @@ -1110,6 +1110,8 @@ const char *split_cmdline_strerror(int cmdline_errno);\n>>  /* git.c */\n>>  struct startup_info {\n>>  \tint have_repository;\n>> +\tchar *cwd_to_worktree; /* chdir(\"this\"); from cwd would return to worktree */\n>> +\tchar *worktree_to_cwd; /* chdir(\"this\"); from worktree would return to cwd */\n>\n> Comment nit: would\n>\n> \t\t\t\t/* path from original cwd to worktree */\n> \t\t\t\t/* path from worktree to original cwd */\n>\n> be clearer?\n\nMuch better.\n"},{"id":"152836","messageId":"AANLkTin8zFb9mP7A4=hWV-9SkFqqYLbMQxUw=diW6Vbf@mail.gmail.com","threadId":"25367","inReplyTo":"20101006180727.GA2118@burratino","subject":"Re: [PATCH] worktree: provide better prefix to go back to original cwd","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-10-07T03:08:55Z","receivedAt":"2010-10-07T03:08:55Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2010/10/7 Jonathan Nieder <jrnieder@gmail.com>:\n> Nguyễn Thái Ngọc Duy wrote:\n>\n>> This patch allows builtin commands access to original cwd even if it's\n>> outside worktree, via cwd_to_worktree and worktree_to_cwd fields.\n>> --- a/builtin/rev-parse.c\n>> +++ b/builtin/rev-parse.c\n>> @@ -623,6 +623,16 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n>>                                       puts(prefix);\n>>                               continue;\n>>                       }\n>> +                     if (!strcmp(arg, \"--cwd-to-worktree\")) {\n>> +                             if (startup_info->cwd_to_worktree)\n>> +                                     puts(startup_info->cwd_to_worktree);\n>> +                             continue;\n>> +                     }\n>> +                     if (!strcmp(arg, \"--worktree-to-cwd\")) {\n>> +                             if (startup_info->worktree_to_cwd)\n>> +                                     puts(startup_info->worktree_to_cwd);\n>> +                             continue;\n>> +                     }\n>\n> Nice.\n>\n> I wonder if this should use something like\n>\n>        else\n>                puts(\".\");\n>\n> or\n>\n>        else\n>                putchar('\\n');\n>\n> .  What would be most convenient for scripted callers?\n\nI followed the convention in rev-parse.c, specifically --show-prefix\ncode. Don't know if it's good or bad for scripts though.\n\n> What do these commands do when run from a bare repository?  Is the\n> worktree the .git dir in that case, do they fail, or does something\n> else happen?\n\nThese two new fields are only set when both GIT_DIR and GIT_WORK_TREE\nare set, which means non-bare repository. I'll need to handle other\nsetup cases as well, but for subproject-aware grep, this should be\nenough.\n\n> Are there any examples to illustrate whether teaching --show-prefix to\n> do what your --worktree-to-cwd does would be a good or bad idea?\n> (Just curious.)\n\nI think it's a bad idea. --show-prefix traditionally never returns\n\"../(something)\" and scripts (even builtin commands) depend on that.\nIt's better to slowly migrate over the new prefix(es) when it makes\nsense.\n\n>> --- a/setup.c\n>> +++ b/setup.c\n>> @@ -313,10 +313,109 @@ const char *read_gitfile_gently(const char *path)\n>>       return path;\n>>  }\n>>\n>> +/*\n>> + * Given \"foo/bar\" and \"hey/hello/world\", return \"../../hey/hello/world/\"\n>> + * Either path1 or path2 can be NULL\n>> + */\n>> +static char *make_path_to_path(const char *path1, const char *path2)\n>\n> Nice.  Do we need to worry about:\n>\n>  - alternate directory separators? (hey\\hello\\world)\n>  - DOS drive prefix? (c:\\foo\\bar, d:\\hey\\hello\\world)\n>  - relative paths with DOS drive? (c:\\foo\\bar, d:hello)\n>  - doubled-up directory separators? (hey//hello/world, //foo/bar)\n>  - non-canonical paths? (hey/./hello/../hello/world)\n>\n> I'm guessing some of the answers are \"no\", depending on where these\n> paths come from.  Compare make_relative_path().\n\nThe two last ones are OK. Paths passed to this function come from\neither getcwd or make_absolute_path(). I'm sure they are\ncanonicalized. But I'll add a comment to note that.\n\nI'll look into backslashes and DOS drives (hmm and UNC path too).\n\n> [...]\n>\n>>  static const char *setup_explicit_git_dir(const char *gitdirenv,\n>>                               const char *work_tree_env, int *nongit_ok)\n>>  {\n>> -     static char buffer[1024 + 1];\n>> +     static char buffer[PATH_MAX];\n>\n> Why?\n>\n> It might make sense to error out a little before PATH_MAX (though\n> later than 1024), to account for subdirs (e.g., objects/).  Not sure.\n\nI'm not really POSIX-fluent to tell. But I'm sure in this function\nthere won't be any subdirs.\n-- \nDuy\n"},{"id":"152837","messageId":"AANLkTim7=8ALxBKWhYcZRSqAcxi0O-T-pxmYpG8_N8v7@mail.gmail.com","threadId":"25367","inReplyTo":"7v4ocz18az.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] worktree: provide better prefix to go back to original cwd","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2010-10-07T03:14:45Z","receivedAt":"2010-10-07T03:14:45Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Oct 7, 2010 at 1:32 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Jonathan Nieder <jrnieder@gmail.com> writes:\n>\n>> Are there any examples to illustrate whether teaching --show-prefix to\n>> do what your --worktree-to-cwd does would be a good or bad idea?\n>> (Just curious.)\n>\n> Do these additions interact well with the notion of \"we are in the working\n> tree\" vs \"we are outside the working tree\"?  Even when we happen to know\n> via GIT_WORK_TREE that the root of the working tree is /var/tmp/junk, we\n> should correctly diagnse that we are outside the working tree when we are\n> in /var/tmp/, and require_work_tree should say \"no you are not allowed to\n> do this\", no?\n\nIt should work as it does now. I don't change prefix calculation and\nchdir() behavior. So when you're at /var/tmp, require_work_tree should\nsay no.\n-- \nDuy\n"}]}