Skip to content

Commit

Permalink
test-lib.sh: Add a test_set_editor function to safely set $VISUAL
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bryan Donlan authored and Junio C Hamano committed May 5, 2008
1 parent 065096c commit 02b3566
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions t/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ die () {

trap 'die' exit

# The semantics of the editor variables are that of invoking
# sh -c "$EDITOR \"$@\"" files ...
#
# If our trash directory contains shell metacharacters, they will be
# interpreted if we just set $EDITOR directly, so do a little dance with
# environment variables to work around this.
#
# In particular, quoting isn't enough, as the path may contain the same quote
# that we're using.
test_set_editor () {
FAKE_EDITOR="$1"
export FAKE_EDITOR
VISUAL='"$FAKE_EDITOR"'
export VISUAL
}

test_tick () {
if test -z "${test_tick+set}"
then
Expand Down

0 comments on commit 02b3566

Please sign in to comment.