test git rev-parse
[git/git.git] / t / t1500-rev-parse.sh
1 #!/bin/sh
2
3 test_description='test git rev-parse'
4 . ./test-lib.sh
5
6 test_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
20 test_expect_success "$name: prefix" \
21 "test '$1' = \"\$(git rev-parse --show-prefix)\""
22 shift
23 [ $# -eq 0 ] && return
24 }
25
26 test_rev_parse toplevel false false ''
27
28 cd .git || exit 1
29 test_rev_parse .git/ false true .git/
30 cd objects || exit 1
31 test_rev_parse .git/objects/ false true .git/objects/
32 cd ../.. || exit 1
33
34 mkdir -p sub/dir || exit 1
35 cd sub/dir || exit 1
36 test_rev_parse subdirectory false false sub/dir/
37 cd ../.. || exit 1
38
39 git config core.bare true
40 test_rev_parse 'core.bare = true' true
41
42 git config --unset core.bare
43 test_rev_parse 'core.bare undefined' false
44
45 mkdir work || exit 1
46 cd work || exit 1
47 export GIT_DIR=../.git
48 export GIT_CONFIG="$GIT_DIR"/config
49
50 git config core.bare false
51 test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false ''
52
53 git config core.bare true
54 test_rev_parse 'GIT_DIR=../.git, core.bare = true' true
55
56 git config --unset core.bare
57 test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false ''
58
59 mv ../.git ../repo.git || exit 1
60 export GIT_DIR=../repo.git
61 export GIT_CONFIG="$GIT_DIR"/config
62
63 git config core.bare false
64 test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false ''
65
66 git config core.bare true
67 test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true
68
69 git config --unset core.bare
70 test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' true
71
72 test_done