Merge branch 'sk/mingw-tests-workaround'
[git/mingw/4msysgit.git] / t / t1500-rev-parse.sh
blob48ee07779d64147c3eb8325a3b3f9579f8ec41d8
1 #!/bin/sh
3 test_description='test git rev-parse'
4 . ./test-lib.sh
6 test_rev_parse() {
7 name=$1
8 shift
10 test_expect_success "$name: is-bare-repository" \
11 "test '$1' = \"\$(git rev-parse --is-bare-repository)\""
12 shift
13 [ $# -eq 0 ] && return
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
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
25 test_expect_success "$name: prefix" \
26 "test '$1' = \"\$(git rev-parse --show-prefix)\""
27 shift
28 [ $# -eq 0 ] && return
30 test_expect_success "$name: git-dir" \
31 "test '$1' = \"\$(git rev-parse --git-dir)\""
32 shift
33 [ $# -eq 0 ] && return
36 # label is-bare is-inside-git is-inside-work prefix git-dir
38 ROOT=$(pwd)
40 test_rev_parse toplevel false false true '' .git
42 cd .git || exit 1
43 test_rev_parse .git/ false true false '' .
44 cd objects || exit 1
45 test_rev_parse .git/objects/ false true false '' "$ROOT/.git"
46 cd ../.. || exit 1
48 mkdir -p sub/dir || exit 1
49 cd sub/dir || exit 1
50 test_rev_parse subdirectory false false true sub/dir/ "$ROOT/.git"
51 cd ../.. || exit 1
53 git config core.bare true
54 test_rev_parse 'core.bare = true' true false false
56 git config --unset core.bare
57 test_rev_parse 'core.bare undefined' false false true
59 mkdir work || exit 1
60 cd work || exit 1
61 GIT_DIR=../.git
62 GIT_CONFIG="$(pwd)"/../.git/config
63 export GIT_DIR GIT_CONFIG
65 git config core.bare false
66 test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true ''
68 git config core.bare true
69 test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false ''
71 git config --unset core.bare
72 test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true ''
74 mv ../.git ../repo.git || exit 1
75 GIT_DIR=../repo.git
76 GIT_CONFIG="$(pwd)"/../repo.git/config
78 git config core.bare false
79 test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true ''
81 git config core.bare true
82 test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false ''
84 git config --unset core.bare
85 test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
87 test_done