Clean up work-tree handling
[git/git.git] / t / t1500-rev-parse.sh
CommitLineData
dace6e44
ML
1#!/bin/sh
2
3test_description='test git rev-parse'
4. ./test-lib.sh
5
6test_rev_parse() {
7 name=$1
8 shift
9
10 test_expect_success "$name: is-bare-repository" \
11 "test '$1' = \"\$(git rev-parse --is-bare-repository)\""
12 shift
13 [ $# -eq 0 ] && return
14
15 test_expect_success "$name: is-inside-git-dir" \
16 "test '$1' = \"\$(git rev-parse --is-inside-git-dir)\""
17 shift
18 [ $# -eq 0 ] && return
19
6c56049f
ML
20 test_expect_success "$name: is-inside-work-tree" \
21 "test '$1' = \"\$(git rev-parse --is-inside-work-tree)\""
22 shift
23 [ $# -eq 0 ] && return
24
dace6e44
ML
25 test_expect_success "$name: prefix" \
26 "test '$1' = \"\$(git rev-parse --show-prefix)\""
27 shift
28 [ $# -eq 0 ] && return
29}
30
6c56049f 31test_rev_parse toplevel false false true ''
dace6e44
ML
32
33cd .git || exit 1
e90fdc39 34test_rev_parse .git/ true true false ''
dace6e44 35cd objects || exit 1
e90fdc39 36test_rev_parse .git/objects/ true true false ''
dace6e44
ML
37cd ../.. || exit 1
38
39mkdir -p sub/dir || exit 1
40cd sub/dir || exit 1
6c56049f 41test_rev_parse subdirectory false false true sub/dir/
dace6e44
ML
42cd ../.. || exit 1
43
44git config core.bare true
e90fdc39 45test_rev_parse 'core.bare = true' true false false
dace6e44
ML
46
47git config --unset core.bare
6c56049f 48test_rev_parse 'core.bare undefined' false false true
dace6e44
ML
49
50mkdir work || exit 1
51cd work || exit 1
52export GIT_DIR=../.git
e90fdc39 53export GIT_CONFIG="$(pwd)"/../.git/config
dace6e44
ML
54
55git config core.bare false
e90fdc39 56test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true work/
dace6e44
ML
57
58git config core.bare true
e90fdc39 59test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false ''
dace6e44
ML
60
61git config --unset core.bare
e90fdc39 62test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true work/
dace6e44
ML
63
64mv ../.git ../repo.git || exit 1
65export GIT_DIR=../repo.git
e90fdc39 66export GIT_CONFIG="$(pwd)"/../repo.git/config
dace6e44
ML
67
68git config core.bare false
6c56049f 69test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true ''
dace6e44
ML
70
71git config core.bare true
e90fdc39 72test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false ''
dace6e44
ML
73
74git config --unset core.bare
e90fdc39 75test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
dace6e44
ML
76
77test_done