t1500: avoid setting configuration options 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 "-b <value>" option to allow callers to set "core.bare" explicitly or undefine it. Take advantage of this new option to avoid setting "core.bare" outside of tests. Under the hood, "-b <value>" invokes "test_config -C <dir>" (or "test_unconfig -C <dir>"), thus git-config knows explicitly where to find its configuration file. Consequently, the global GIT_CONFIG environment variable required by the manual git-config invocations outside of tests is no longer needed, and is thus dropped. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed May 18, 2016 at 16:15 UTC 1dea0dc9e0965e2581cdf64fc9eb072e8d6a88d3
1 file changed +20 -19
t/t1500-rev-parse.sh
+20 -19
@@ -6,10 +6,15 @@ test_description='test git rev-parse'
6 # usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir
7 test_rev_parse () {
8 d=
9 + bare=
10 while :
11 do
12 case "$1" in
13 -C) d="$2"; shift; shift ;;
14 + -b) case "$2" in
15 + [tfu]*) bare="$2"; shift; shift ;;
16 + *) error "test_rev_parse: bogus core.bare value '$2'" ;;
17 + esac ;;
18 -*) error "test_rev_parse: unrecognized option '$1'" ;;
19 *) break ;;
20 esac
@@ -27,6 +32,12 @@ test_rev_parse () {
32 test $# -eq 0 && break
33 expect="$1"
34 test_expect_success "$name: $o" '
35 + case "$bare" in
36 + t*) test_config ${d:+-C} ${d:+"$d"} core.bare true ;;
37 + f*) test_config ${d:+-C} ${d:+"$d"} core.bare false ;;
38 + u*) test_unconfig ${d:+-C} ${d:+"$d"} core.bare ;;
39 + esac &&
40 +
41 echo "$expect" >expect &&
42 git ${d:+-C} ${d:+"$d"} rev-parse $o >actual &&
43 test_cmp expect actual
@@ -49,35 +60,25 @@ test_rev_parse -C .git/objects .git/objects/ false true false '' "$ROOT/.git"
60
61 test_rev_parse -C sub/dir subdirectory false false true sub/dir/ "$ROOT/.git"
62
52 -git config core.bare true
53 -test_rev_parse 'core.bare = true' true false false
63 +test_rev_parse -b t 'core.bare = true' true false false
64
55 -git config --unset core.bare
56 -test_rev_parse 'core.bare undefined' false false true
65 +test_rev_parse -b u 'core.bare undefined' false false true
66
67 GIT_DIR=../.git
59 -GIT_CONFIG="$(pwd)/work/../.git/config"
60 -export GIT_DIR GIT_CONFIG
68 +export GIT_DIR
69
62 -git config core.bare false
63 -test_rev_parse -C work 'GIT_DIR=../.git, core.bare = false' false false true ''
70 +test_rev_parse -C work -b f 'GIT_DIR=../.git, core.bare = false' false false true ''
71
65 -git config core.bare true
66 -test_rev_parse -C work 'GIT_DIR=../.git, core.bare = true' true false false ''
72 +test_rev_parse -C work -b t 'GIT_DIR=../.git, core.bare = true' true false false ''
73
68 -git config --unset core.bare
69 -test_rev_parse -C work 'GIT_DIR=../.git, core.bare undefined' false false true ''
74 +test_rev_parse -C work -b u 'GIT_DIR=../.git, core.bare undefined' false false true ''
75
76 GIT_DIR=../repo.git
72 -GIT_CONFIG="$(pwd)/work/../repo.git/config"
77
74 -git config core.bare false
75 -test_rev_parse -C work 'GIT_DIR=../repo.git, core.bare = false' false false true ''
78 +test_rev_parse -C work -b f 'GIT_DIR=../repo.git, core.bare = false' false false true ''
79
77 -git config core.bare true
78 -test_rev_parse -C work 'GIT_DIR=../repo.git, core.bare = true' true false false ''
80 +test_rev_parse -C work -b t 'GIT_DIR=../repo.git, core.bare = true' true false false ''
81
80 -git config --unset core.bare
81 -test_rev_parse -C work 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
82 +test_rev_parse -C work -b u 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
83
84 test_done