* [PATCH] bash prompt: test the prompt with newline in repository path
@ 2013-08-16 10:36 SZEDER Gábor
2013-08-16 19:16 ` Johannes Sixt
2013-08-16 23:44 ` [PATCH] " Eric Sunshine
0 siblings, 2 replies; 4+ messages in thread
From: SZEDER Gábor @ 2013-08-16 10:36 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, SZEDER Gábor
Newlines in the path to a git repository were not an issue for the
git-specific bash prompt before commit efaa0c1532 (bash prompt:
combine 'git rev-parse' executions in the main code path, 2013-06-17),
because the path returned by 'git rev-parse --git-dir' was directly
stored in a variable, and this variable was later always accessed
inside double quotes.
Newlines are not an issue after commit efaa0c1532 either, but it's
more subtle. Since efaa0c1532 we use the following single 'git
rev-parse' execution to query various info about the repository:
git rev-parse --git-dir --is-inside-git-dir \
--is-bare-repository --is-inside-work-tree
The results to these queries are separated by a newline character in
the output, e.g.:
/home/szeder/src/git/.git
false
false
true
A newline in the path to the git repository could potentially break
the parsing of these results and ultimately the bash prompt, unless
the parsing is done right. Commit efaa0c1532 got it right, as I
consciously started parsing 'git rev-parse's output from the end,
where each record is a single line containing either 'true' or 'false'
or, after e3e0b9378b (bash prompt: combine 'git rev-parse' for
detached head, 2013-06-24), the abbreviated commit object name, and
all what remains at the beginning is the path to the git repository,
no matter how many lines it is.
This subtlety really warrants its own test, especially since I didn't
explait it in the log message or in an in-code comment back then, so
add a test to excercise the prompt with newline characters in the path
to the repository. Note that 'git rev-parse --git-dir' prints '.git'
or '.' when at the top of the worktree or the repository,
respectively, and only prints the full path to the repository when in
a subdirectory, hence the need for changing into a subdir in the test.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
t/t9903-bash-prompt.sh | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 3c3e4e8c38..dfe2088ef4 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -61,6 +61,22 @@ test_expect_success 'prompt - unborn branch' '
test_cmp expected "$actual"
'
+repo_with_newline='repo
+with
+newline'
+
+test_expect_success 'prompt - with newline in path' '
+ printf " (master)" >expected &&
+ git init "$repo_with_newline" &&
+ test_when_finished "rm -rf \"$repo_with_newline\"" &&
+ mkdir "$repo_with_newline"/subdir &&
+ (
+ cd "$repo_with_newline/subdir" &&
+ __git_ps1 >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
test_expect_success 'prompt - detached head' '
printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected &&
test_config core.abbrev 13 &&
--
1.8.3.3.824.gb0ea0e3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] bash prompt: test the prompt with newline in repository path
2013-08-16 10:36 [PATCH] bash prompt: test the prompt with newline in repository path SZEDER Gábor
@ 2013-08-16 19:16 ` Johannes Sixt
2013-08-17 9:01 ` [PATCH v2] " SZEDER Gábor
2013-08-16 23:44 ` [PATCH] " Eric Sunshine
1 sibling, 1 reply; 4+ messages in thread
From: Johannes Sixt @ 2013-08-16 19:16 UTC (permalink / raw)
To: SZEDER Gábor; +Cc: Junio C Hamano, git
Am 16.08.2013 12:36, schrieb SZEDER Gábor:
> +repo_with_newline='repo
> +with
> +newline'
> +
> +test_expect_success 'prompt - with newline in path' '
This test must be skipped when the filesystem does not support LF in file
names. Cf. the FUNNYNAMES prerequisite in t3600-rm.sh.
> + printf " (master)" >expected &&
> + git init "$repo_with_newline" &&
> + test_when_finished "rm -rf \"$repo_with_newline\"" &&
> + mkdir "$repo_with_newline"/subdir &&
> + (
> + cd "$repo_with_newline/subdir" &&
> + __git_ps1 >"$actual"
> + ) &&
> + test_cmp expected "$actual"
> +'
-- Hannes
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] bash prompt: test the prompt with newline in repository path
2013-08-16 19:16 ` Johannes Sixt
@ 2013-08-17 9:01 ` SZEDER Gábor
0 siblings, 0 replies; 4+ messages in thread
From: SZEDER Gábor @ 2013-08-17 9:01 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Eric Sunshine, Johannes Sixt, git, SZEDER Gábor
Newlines in the path to a git repository were not an issue for the
git-specific bash prompt before commit efaa0c1532 (bash prompt:
combine 'git rev-parse' executions in the main code path, 2013-06-17),
because the path returned by 'git rev-parse --git-dir' was directly
stored in a variable, and this variable was later always accessed
inside double quotes.
Newlines are not an issue after commit efaa0c1532 either, but it's
more subtle. Since efaa0c1532 we use the following single 'git
rev-parse' execution to query various info about the repository:
git rev-parse --git-dir --is-inside-git-dir \
--is-bare-repository --is-inside-work-tree
The results to these queries are separated by a newline character in
the output, e.g.:
/home/szeder/src/git/.git
false
false
true
A newline in the path to the git repository could potentially break
the parsing of these results and ultimately the bash prompt, unless
the parsing is done right. Commit efaa0c1532 got it right, as I
consciously started parsing 'git rev-parse's output from the end,
where each record is a single line containing either 'true' or 'false'
or, after e3e0b9378b (bash prompt: combine 'git rev-parse' for
detached head, 2013-06-24), the abbreviated commit object name, and
all what remains at the beginning is the path to the git repository,
no matter how many lines it is.
This subtlety really warrants its own test, especially since I didn't
explain it in the log message or in an in-code comment back then, so
add a test to excercise the prompt with newline characters in the path
to the repository. Guard this test with the FUNNYNAMES prerequisite,
because not all filesystems support newlines in filenames. Note that
'git rev-parse --git-dir' prints '.git' or '.' when at the top of the
worktree or the repository, respectively, and only prints the full
path to the repository when in a subdirectory, hence the need for
changing into a subdir in the test.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
Added FUNNYNAMES prerequisite and Eric's typofix.
t/t9903-bash-prompt.sh | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index 3c3e4e8c38..59f875e830 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -61,6 +61,29 @@ test_expect_success 'prompt - unborn branch' '
test_cmp expected "$actual"
'
+repo_with_newline='repo
+with
+newline'
+
+if mkdir "$repo_with_newline" 2>/dev/null
+then
+ test_set_prereq FUNNYNAMES
+else
+ say 'Your filesystem does not allow newlines in filenames.'
+fi
+
+test_expect_success FUNNYNAMES 'prompt - with newline in path' '
+ printf " (master)" >expected &&
+ git init "$repo_with_newline" &&
+ test_when_finished "rm -rf \"$repo_with_newline\"" &&
+ mkdir "$repo_with_newline"/subdir &&
+ (
+ cd "$repo_with_newline/subdir" &&
+ __git_ps1 >"$actual"
+ ) &&
+ test_cmp expected "$actual"
+'
+
test_expect_success 'prompt - detached head' '
printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected &&
test_config core.abbrev 13 &&
--
1.8.4.rc3.31.g0f99442
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] bash prompt: test the prompt with newline in repository path
2013-08-16 10:36 [PATCH] bash prompt: test the prompt with newline in repository path SZEDER Gábor
2013-08-16 19:16 ` Johannes Sixt
@ 2013-08-16 23:44 ` Eric Sunshine
1 sibling, 0 replies; 4+ messages in thread
From: Eric Sunshine @ 2013-08-16 23:44 UTC (permalink / raw)
To: SZEDER Gábor; +Cc: Junio C Hamano, Git List
On Fri, Aug 16, 2013 at 6:36 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:
> This subtlety really warrants its own test, especially since I didn't
> explait it in the log message or in an in-code comment back then, so
s/explait/explain/
> add a test to excercise the prompt with newline characters in the path
> to the repository. Note that 'git rev-parse --git-dir' prints '.git'
> or '.' when at the top of the worktree or the repository,
> respectively, and only prints the full path to the repository when in
> a subdirectory, hence the need for changing into a subdir in the test.
>
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-08-17 9:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-16 10:36 [PATCH] bash prompt: test the prompt with newline in repository path SZEDER Gábor
2013-08-16 19:16 ` Johannes Sixt
2013-08-17 9:01 ` [PATCH v2] " SZEDER Gábor
2013-08-16 23:44 ` [PATCH] " Eric Sunshine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).