]>
Commit | Line | Data |
---|---|---|
dace6e44 ML |
1 | #!/bin/sh |
2 | ||
3 | test_description='test git rev-parse' | |
4 | . ./test-lib.sh | |
5 | ||
12f7526c ES |
6 | # usage: label is-bare is-inside-git is-inside-work prefix git-dir |
7 | test_rev_parse () { | |
dace6e44 ML |
8 | name=$1 |
9 | shift | |
10 | ||
12f7526c ES |
11 | for o in --is-bare-repository \ |
12 | --is-inside-git-dir \ | |
13 | --is-inside-work-tree \ | |
14 | --show-prefix \ | |
15 | --git-dir | |
16 | do | |
17 | test $# -eq 0 && break | |
18 | expect="$1" | |
19 | test_expect_success "$name: $o" ' | |
20 | echo "$expect" >expect && | |
21 | git rev-parse $o >actual && | |
22 | test_cmp expect actual | |
23 | ' | |
24 | shift | |
25 | done | |
dace6e44 ML |
26 | } |
27 | ||
8fb3c00d | 28 | ROOT=$(pwd) |
7efeb8f0 | 29 | |
d66f68ff ES |
30 | test_expect_success 'setup' ' |
31 | mkdir -p sub/dir work && | |
32 | cp -R .git repo.git | |
33 | ' | |
34 | ||
db7fee87 | 35 | test_rev_parse toplevel false false true '' .git |
dace6e44 ML |
36 | |
37 | cd .git || exit 1 | |
db7fee87 | 38 | test_rev_parse .git/ false true false '' . |
dace6e44 | 39 | cd objects || exit 1 |
8fb3c00d | 40 | test_rev_parse .git/objects/ false true false '' "$ROOT/.git" |
dace6e44 ML |
41 | cd ../.. || exit 1 |
42 | ||
dace6e44 | 43 | cd sub/dir || exit 1 |
db7fee87 | 44 | test_rev_parse subdirectory false false true sub/dir/ "$ROOT/.git" |
dace6e44 ML |
45 | cd ../.. || exit 1 |
46 | ||
47 | git config core.bare true | |
e90fdc39 | 48 | test_rev_parse 'core.bare = true' true false false |
dace6e44 ML |
49 | |
50 | git config --unset core.bare | |
6c56049f | 51 | test_rev_parse 'core.bare undefined' false false true |
dace6e44 | 52 | |
dace6e44 | 53 | cd work || exit 1 |
0e46e704 BD |
54 | GIT_DIR=../.git |
55 | GIT_CONFIG="$(pwd)"/../.git/config | |
56 | export GIT_DIR GIT_CONFIG | |
dace6e44 ML |
57 | |
58 | git config core.bare false | |
7efeb8f0 | 59 | test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true '' |
dace6e44 ML |
60 | |
61 | git config core.bare true | |
e90fdc39 | 62 | test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false '' |
dace6e44 ML |
63 | |
64 | git config --unset core.bare | |
7efeb8f0 | 65 | test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true '' |
dace6e44 | 66 | |
0e46e704 BD |
67 | GIT_DIR=../repo.git |
68 | GIT_CONFIG="$(pwd)"/../repo.git/config | |
dace6e44 ML |
69 | |
70 | git config core.bare false | |
6c56049f | 71 | test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true '' |
dace6e44 ML |
72 | |
73 | git config core.bare true | |
e90fdc39 | 74 | test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false '' |
dace6e44 ML |
75 | |
76 | git config --unset core.bare | |
e90fdc39 | 77 | test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true '' |
dace6e44 ML |
78 | |
79 | test_done |