{"thread":{"id":"9235","subject":"[PATCH 5/5] With work-trees possibly inside git-dir, be more generous","startedAt":"2007-07-26T06:32:49Z","lastAt":"2007-07-26T06:32:49Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"48654","messageId":"Pine.LNX.4.64.0707260732360.14781@racer.site","threadId":"9235","inReplyTo":null,"subject":"[PATCH 5/5] With work-trees possibly inside git-dir, be more generous","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-26T06:32:49Z","receivedAt":"2007-07-26T06:32:49Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThe earlier work-tree behaviour was seriously bogus.  For regular working\ntree operations, it checked if inside git dir.  That makes no sense, of\ncourse, since the check should be for a work tree, and nothing else.\n\nFix that.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tPlease consider giving this a real hard beating.  I think the\n\told series was so bad only because nobody cared (including me).\n\n builtin-ls-files.c  |    8 +++++---\n builtin-rev-parse.c |    6 ++++++\n git-sh-setup.sh     |    3 +--\n git.c               |    7 +++++--\n 4 files changed, 17 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin-ls-files.c b/builtin-ls-files.c\nindex 61577ea..d36181a 100644\n--- a/builtin-ls-files.c\n+++ b/builtin-ls-files.c\n@@ -469,9 +469,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)\n \t\tbreak;\n \t}\n \n-\tif (require_work_tree &&\n-\t\t\t(!is_inside_work_tree() || is_inside_git_dir()))\n-\t\tdie(\"This operation must be run in a work tree\");\n+\tif (require_work_tree && !is_inside_work_tree()) {\n+\t\tconst char *work_tree = get_git_work_tree();\n+\t\tif (!work_tree || chdir(work_tree))\n+\t\t\tdie(\"This operation must be run in a work tree\");\n+\t}\n \n \tpathspec = get_pathspec(prefix, argv + i);\n \ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex 497903a..3804541 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -320,7 +320,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--show-cdup\")) {\n+\t\t\t\tconst char *work_tree = get_git_work_tree();\n \t\t\t\tconst char *pfx = prefix;\n+\n+\t\t\t\tif (work_tree) {\n+\t\t\t\t\tprintf(\"%s\\n\", work_tree);\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n \t\t\t\twhile (pfx) {\n \t\t\t\t\tpfx = strchr(pfx, '/');\n \t\t\t\t\tif (pfx) {\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex c51985e..7bef43f 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -59,8 +59,7 @@ cd_to_toplevel () {\n }\n \n require_work_tree () {\n-\ttest $(git rev-parse --is-inside-work-tree) = true &&\n-\ttest $(git rev-parse --is-inside-git-dir) = false ||\n+\ttest $(git rev-parse --is-inside-work-tree) = true ||\n \tdie \"fatal: $0 cannot be used without a working tree.\"\n }\n \ndiff --git a/git.c b/git.c\nindex 5df10d3..03ce3bb 100644\n--- a/git.c\n+++ b/git.c\n@@ -273,8 +273,11 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)\n \tif (p->option & USE_PAGER)\n \t\tsetup_pager();\n \tif ((p->option & NEED_WORK_TREE) &&\n-\t    (!is_inside_work_tree() || is_inside_git_dir()))\n-\t\tdie(\"%s must be run in a work tree\", p->cmd);\n+\t    !is_inside_work_tree()) {\n+\t\tconst char *work_tree = get_git_work_tree();\n+\t\tif (!work_tree || chdir(work_tree))\n+\t\t\tdie(\"%s must be run in a work tree\", p->cmd);\n+\t}\n \ttrace_argv_printf(argv, argc, \"trace: built-in: git\");\n \n \tstatus = p->fn(argc, argv, prefix);\n-- \n1.5.3.rc2.42.gda8d-dirty\n"}]}