{"thread":{"id":"23875","subject":"[PATCH] get_cwd_relative(): do not misinterpret suffix as subdirectory","startedAt":"2010-05-22T11:13:05Z","lastAt":"2010-05-22T11:13:05Z","messageCount":1,"participants":["Clemens Buchacher"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"142089","messageId":"20100522111305.GA2888@localhost","threadId":"23875","inReplyTo":null,"subject":"[PATCH] get_cwd_relative(): do not misinterpret suffix as subdirectory","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2010-05-22T11:13:05Z","receivedAt":"2010-05-22T11:13:05Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"If the current working directory is the same as the work tree path\nplus a suffix, e.g. 'work' and 'work-xyz', then the suffix '-xyz'\nwould be interpreted as a subdirectory of 'work'.\n\nSigned-off-by: Clemens Buchacher <drizzd@aon.at>\n---\n\nHi Junio,\n\nI am not sure if the tests are really worth it. I do not mind you drop them.\n\nRegards,\nClemens\n\n dir.c               |    9 +++++++--\n t/t1501-worktree.sh |   12 ++++++++++--\n 2 files changed, 17 insertions(+), 4 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex cb83332..5615f33 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -958,9 +958,14 @@ char *get_relative_cwd(char *buffer, int size, const char *dir)\n \t}\n \tif (*dir)\n \t\treturn NULL;\n-\tif (*cwd == '/')\n+\tswitch (*cwd) {\n+\tcase '\\0':\n+\t\treturn cwd;\n+\tcase '/':\n \t\treturn cwd + 1;\n-\treturn cwd;\n+\tdefault:\n+\t\treturn NULL;\n+\t}\n }\n \n int is_inside_dir(const char *dir)\ndiff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh\nindex 9df3012..bd8b607 100755\n--- a/t/t1501-worktree.sh\n+++ b/t/t1501-worktree.sh\n@@ -30,6 +30,7 @@ test_rev_parse() {\n \n EMPTY_TREE=$(git write-tree)\n mkdir -p work/sub/dir || exit 1\n+mkdir -p work2 || exit 1\n mv .git repo.git || exit 1\n \n say \"core.worktree = relative path\"\n@@ -54,7 +55,9 @@ GIT_DIR=$(pwd)/repo.git\n GIT_CONFIG=$GIT_DIR/config\n git config core.worktree \"$(pwd)/work\"\n test_rev_parse 'outside'      false false false\n-cd work || exit 1\n+cd work2\n+test_rev_parse 'outside2'     false false false\n+cd ../work || exit 1\n test_rev_parse 'inside'       false false true ''\n cd sub/dir || exit 1\n test_rev_parse 'subdirectory' false false true sub/dir/\n@@ -67,7 +70,9 @@ git config core.worktree non-existent\n GIT_WORK_TREE=work\n export GIT_WORK_TREE\n test_rev_parse 'outside'      false false false\n-cd work || exit 1\n+cd work2\n+test_rev_parse 'outside'      false false false\n+cd ../work || exit 1\n GIT_WORK_TREE=.\n test_rev_parse 'inside'       false false true ''\n cd sub/dir || exit 1\n@@ -76,6 +81,7 @@ test_rev_parse 'subdirectory' false false true sub/dir/\n cd ../../.. || exit 1\n \n mv work repo.git/work\n+mv work2 repo.git/work2\n \n say \"GIT_WORK_TREE=absolute path, work tree below git dir\"\n GIT_DIR=$(pwd)/repo.git\n@@ -86,6 +92,8 @@ cd repo.git || exit 1\n test_rev_parse 'in repo.git'              false true  false\n cd objects || exit 1\n test_rev_parse 'in repo.git/objects'      false true  false\n+cd ../work2 || exit 1\n+test_rev_parse 'in repo.git/work2'      false true  false\n cd ../work || exit 1\n test_rev_parse 'in repo.git/work'         false true true ''\n cd sub/dir || exit 1\n-- \n1.7.0.5.3.ga76e\n"}]}