Skip to content

Commit 1dea0dc

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1e043cf commit 1dea0dc

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

t/t1500-rev-parse.sh

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ test_description='test git rev-parse'
66
# usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir
77
test_rev_parse () {
88
d=
9+
bare=
910
while :
1011
do
1112
case "$1" in
1213
-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 ;;
1318
-*) error "test_rev_parse: unrecognized option '$1'" ;;
1419
*) break ;;
1520
esac
@@ -27,6 +32,12 @@ test_rev_parse () {
2732
test $# -eq 0 && break
2833
expect="$1"
2934
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+
3041
echo "$expect" >expect &&
3142
git ${d:+-C} ${d:+"$d"} rev-parse $o >actual &&
3243
test_cmp expect actual
@@ -49,35 +60,25 @@ test_rev_parse -C .git/objects .git/objects/ false true false '' "$ROOT/.git"
4960

5061
test_rev_parse -C sub/dir subdirectory false false true sub/dir/ "$ROOT/.git"
5162

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
5464

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
5766

5867
GIT_DIR=../.git
59-
GIT_CONFIG="$(pwd)/work/../.git/config"
60-
export GIT_DIR GIT_CONFIG
68+
export GIT_DIR
6169

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 ''
6471

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 ''
6773

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 ''
7075

7176
GIT_DIR=../repo.git
72-
GIT_CONFIG="$(pwd)/work/../repo.git/config"
7377

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 ''
7679

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 ''
7981

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 ''
8283

8384
test_done

0 commit comments

Comments
 (0)