@matheusbsbs / matheus-bagliano / commits / 02b3566003
Fork 0

test-lib.sh: Add a test_set_editor function to safely set $VISUAL

In particular, this function correctly handles cases where the pwd contains spaces, quotes, and other troublesome metacharacters. Signed-off-by: Bryan Donlan <bdonlan@fushizen.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Bryan Donlan committed May 4, 2008 at 01:37 UTC 02b35660031e1da4036559fb928589ca8c3844bd
1 file changed +16
t/test-lib.sh
+16
@@ -160,6 +160,22 @@ die () {
160
161 trap 'die' exit
162
163 +# The semantics of the editor variables are that of invoking
164 +# sh -c "$EDITOR \"$@\"" files ...
165 +#
166 +# If our trash directory contains shell metacharacters, they will be
167 +# interpreted if we just set $EDITOR directly, so do a little dance with
168 +# environment variables to work around this.
169 +#
170 +# In particular, quoting isn't enough, as the path may contain the same quote
171 +# that we're using.
172 +test_set_editor () {
173 + FAKE_EDITOR="$1"
174 + export FAKE_EDITOR
175 + VISUAL='"$FAKE_EDITOR"'
176 + export VISUAL
177 +}
178 +
179 test_tick () {
180 if test -z "${test_tick+set}"
181 then