t1500: avoid changing working directory outside of tests
commit1e043cff7815786b3d1a4c07bac63b3d8e1e30ef
authorEric Sunshine <sunshine@sunshineco.com>
Wed, 18 May 2016 20:15:43 +0000 (18 16:15 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 May 2016 21:14:31 +0000 (18 14:14 -0700)
tree9449561f4a8013fa80c3fcd04fb667a473ab4738
parent12f7526c66547ced1b670f5c0faeec5120fc9c7a
t1500: avoid changing working directory outside of tests

Ideally, each test should be responsible for setting up state it needs
rather than relying upon transient global state. Toward this end, teach
test_rev_parse() to accept a "-C <dir>" option to allow callers to
instruct it explicitly in which directory its tests should be run. Take
advantage of this new option to avoid changing the working directory
outside of tests.

Implementation note: test_rev_parse() passes "-C <dir>" along to
git-rev-parse with <dir> properly quoted. The natural and POSIX way to
do so is via ${dir:+-C "$dir"}, however, with some older broken shells,
this expression evaluates incorrectly to a single argument ("-C <dir>")
rather than the expected two (-C and "<dir>"). Work around this problem
with the slightly ungainly expression: ${dir:+-C} ${dir:+"$dir"}

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t1500-rev-parse.sh