{"thread":{"id":"34711","subject":"[PATCH] bash prompt: test the prompt with newline in repository path","startedAt":"2013-08-16T10:36:35Z","lastAt":"2013-08-17T09:01:58Z","messageCount":4,"participants":["SZEDER Gábor","Johannes Sixt","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"225329","messageId":"1376649395-24363-1-git-send-email-szeder@ira.uka.de","threadId":"34711","inReplyTo":null,"subject":"[PATCH] bash prompt: test the prompt with newline in repository path","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-08-16T10:36:35Z","receivedAt":"2013-08-16T10:36:35Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Newlines in the path to a git repository were not an issue for the\ngit-specific bash prompt before commit efaa0c1532 (bash prompt:\ncombine 'git rev-parse' executions in the main code path, 2013-06-17),\nbecause the path returned by 'git rev-parse --git-dir' was directly\nstored in a variable, and this variable was later always accessed\ninside double quotes.\n\nNewlines are not an issue after commit efaa0c1532 either, but it's\nmore subtle.  Since efaa0c1532 we use the following single 'git\nrev-parse' execution to query various info about the repository:\n\n  git rev-parse --git-dir --is-inside-git-dir \\\n          --is-bare-repository --is-inside-work-tree\n\nThe results to these queries are separated by a newline character in\nthe output, e.g.:\n\n  /home/szeder/src/git/.git\n  false\n  false\n  true\n\nA newline in the path to the git repository could potentially break\nthe parsing of these results and ultimately the bash prompt, unless\nthe parsing is done right.  Commit efaa0c1532 got it right, as I\nconsciously started parsing 'git rev-parse's output from the end,\nwhere each record is a single line containing either 'true' or 'false'\nor, after e3e0b9378b (bash prompt: combine 'git rev-parse' for\ndetached head, 2013-06-24), the abbreviated commit object name, and\nall what remains at the beginning is the path to the git repository,\nno matter how many lines it is.\n\nThis subtlety really warrants its own test, especially since I didn't\nexplait it in the log message or in an in-code comment back then, so\nadd a test to excercise the prompt with newline characters in the path\nto the repository.  Note that 'git rev-parse --git-dir' prints '.git'\nor '.' when at the top of the worktree or the repository,\nrespectively, and only prints the full path to the repository when in\na subdirectory, hence the need for changing into a subdir in the test.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n t/t9903-bash-prompt.sh | 16 ++++++++++++++++\n 1 file changed, 16 insertions(+)\n\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 3c3e4e8c38..dfe2088ef4 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -61,6 +61,22 @@ test_expect_success 'prompt - unborn branch' '\n \ttest_cmp expected \"$actual\"\n '\n \n+repo_with_newline='repo\n+with\n+newline'\n+\n+test_expect_success 'prompt - with newline in path' '\n+\tprintf \" (master)\" >expected &&\n+\tgit init \"$repo_with_newline\" &&\n+\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n+\tmkdir \"$repo_with_newline\"/subdir &&\n+\t(\n+\t\tcd \"$repo_with_newline/subdir\" &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_expect_success 'prompt - detached head' '\n \tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n \ttest_config core.abbrev 13 &&\n-- \n1.8.3.3.824.gb0ea0e3\n"},{"id":"225358","messageId":"520E7A81.5080302@kdbg.org","threadId":"34711","inReplyTo":"1376649395-24363-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH] bash prompt: test the prompt with newline in repository path","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2013-08-16T19:16:17Z","receivedAt":"2013-08-16T19:16:17Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 16.08.2013 12:36, schrieb SZEDER Gábor:\n> +repo_with_newline='repo\n> +with\n> +newline'\n> +\n> +test_expect_success 'prompt - with newline in path' '\n\nThis test must be skipped when the filesystem does not support LF in file \nnames. Cf. the FUNNYNAMES prerequisite in t3600-rm.sh.\n\n> +\tprintf \" (master)\" >expected &&\n> +\tgit init \"$repo_with_newline\" &&\n> +\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n> +\tmkdir \"$repo_with_newline\"/subdir &&\n> +\t(\n> +\t\tcd \"$repo_with_newline/subdir\" &&\n> +\t\t__git_ps1 >\"$actual\"\n> +\t) &&\n> +\ttest_cmp expected \"$actual\"\n> +'\n\n-- Hannes\n"},{"id":"225362","messageId":"CAPig+cTRKs8_f4Acg6=Le=_ePb1MroL61XUXa9bZG0HKYgrL7w@mail.gmail.com","threadId":"34711","inReplyTo":"1376649395-24363-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH] bash prompt: test the prompt with newline in repository path","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2013-08-16T23:44:07Z","receivedAt":"2013-08-16T23:44:07Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Aug 16, 2013 at 6:36 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> This subtlety really warrants its own test, especially since I didn't\n> explait it in the log message or in an in-code comment back then, so\n\ns/explait/explain/\n\n> add a test to excercise the prompt with newline characters in the path\n> to the repository.  Note that 'git rev-parse --git-dir' prints '.git'\n> or '.' when at the top of the worktree or the repository,\n> respectively, and only prints the full path to the repository when in\n> a subdirectory, hence the need for changing into a subdir in the test.\n>\n> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>\n"},{"id":"225368","messageId":"1376730118-11102-1-git-send-email-szeder@ira.uka.de","threadId":"34711","inReplyTo":"520E7A81.5080302@kdbg.org","subject":"[PATCH v2] bash prompt: test the prompt with newline in repository path","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-08-17T09:01:58Z","receivedAt":"2013-08-17T09:01:58Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Newlines in the path to a git repository were not an issue for the\ngit-specific bash prompt before commit efaa0c1532 (bash prompt:\ncombine 'git rev-parse' executions in the main code path, 2013-06-17),\nbecause the path returned by 'git rev-parse --git-dir' was directly\nstored in a variable, and this variable was later always accessed\ninside double quotes.\n\nNewlines are not an issue after commit efaa0c1532 either, but it's\nmore subtle.  Since efaa0c1532 we use the following single 'git\nrev-parse' execution to query various info about the repository:\n\n  git rev-parse --git-dir --is-inside-git-dir \\\n          --is-bare-repository --is-inside-work-tree\n\nThe results to these queries are separated by a newline character in\nthe output, e.g.:\n\n  /home/szeder/src/git/.git\n  false\n  false\n  true\n\nA newline in the path to the git repository could potentially break\nthe parsing of these results and ultimately the bash prompt, unless\nthe parsing is done right.  Commit efaa0c1532 got it right, as I\nconsciously started parsing 'git rev-parse's output from the end,\nwhere each record is a single line containing either 'true' or 'false'\nor, after e3e0b9378b (bash prompt: combine 'git rev-parse' for\ndetached head, 2013-06-24), the abbreviated commit object name, and\nall what remains at the beginning is the path to the git repository,\nno matter how many lines it is.\n\nThis subtlety really warrants its own test, especially since I didn't\nexplain it in the log message or in an in-code comment back then, so\nadd a test to excercise the prompt with newline characters in the path\nto the repository.  Guard this test with the FUNNYNAMES prerequisite,\nbecause not all filesystems support newlines in filenames.  Note that\n'git rev-parse --git-dir' prints '.git' or '.' when at the top of the\nworktree or the repository, respectively, and only prints the full\npath to the repository when in a subdirectory, hence the need for\nchanging into a subdir in the test.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n\nAdded FUNNYNAMES prerequisite and Eric's typofix.\n\n t/t9903-bash-prompt.sh | 23 +++++++++++++++++++++++\n 1 file changed, 23 insertions(+)\n\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 3c3e4e8c38..59f875e830 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -61,6 +61,29 @@ test_expect_success 'prompt - unborn branch' '\n \ttest_cmp expected \"$actual\"\n '\n \n+repo_with_newline='repo\n+with\n+newline'\n+\n+if mkdir \"$repo_with_newline\" 2>/dev/null\n+then\n+\ttest_set_prereq FUNNYNAMES\n+else\n+\tsay 'Your filesystem does not allow newlines in filenames.'\n+fi\n+\n+test_expect_success FUNNYNAMES 'prompt - with newline in path' '\n+\tprintf \" (master)\" >expected &&\n+\tgit init \"$repo_with_newline\" &&\n+\ttest_when_finished \"rm -rf \\\"$repo_with_newline\\\"\" &&\n+\tmkdir \"$repo_with_newline\"/subdir &&\n+\t(\n+\t\tcd \"$repo_with_newline/subdir\" &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_expect_success 'prompt - detached head' '\n \tprintf \" ((%s...))\" $(git log -1 --format=\"%h\" --abbrev=13 b1^) >expected &&\n \ttest_config core.abbrev 13 &&\n-- \n1.8.4.rc3.31.g0f99442\n"}]}