]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1500-rev-parse.sh
tests: mark tests relying on the current default for `init.defaultBranch`
[thirdparty/git.git] / t / t1500-rev-parse.sh
CommitLineData
dace6e44
ML
1#!/bin/sh
2
3test_description='test git rev-parse'
334afbc7
JS
4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
dace6e44
ML
7. ./test-lib.sh
8
a2f5a876 9# usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir absolute-git-dir
12f7526c 10test_rev_parse () {
1e043cff 11 d=
1dea0dc9 12 bare=
e6273f4d 13 gitdir=
1e043cff
ES
14 while :
15 do
16 case "$1" in
17 -C) d="$2"; shift; shift ;;
1dea0dc9
ES
18 -b) case "$2" in
19 [tfu]*) bare="$2"; shift; shift ;;
20 *) error "test_rev_parse: bogus core.bare value '$2'" ;;
21 esac ;;
e6273f4d 22 -g) gitdir="$2"; shift; shift ;;
1e043cff
ES
23 -*) error "test_rev_parse: unrecognized option '$1'" ;;
24 *) break ;;
25 esac
26 done
27
dace6e44
ML
28 name=$1
29 shift
30
12f7526c
ES
31 for o in --is-bare-repository \
32 --is-inside-git-dir \
33 --is-inside-work-tree \
34 --show-prefix \
a2f5a876
SG
35 --git-dir \
36 --absolute-git-dir
12f7526c
ES
37 do
38 test $# -eq 0 && break
39 expect="$1"
40 test_expect_success "$name: $o" '
e6273f4d
ES
41 if test -n "$gitdir"
42 then
43 test_when_finished "unset GIT_DIR" &&
44 GIT_DIR="$gitdir" &&
45 export GIT_DIR
46 fi &&
47
1dea0dc9
ES
48 case "$bare" in
49 t*) test_config ${d:+-C} ${d:+"$d"} core.bare true ;;
50 f*) test_config ${d:+-C} ${d:+"$d"} core.bare false ;;
51 u*) test_unconfig ${d:+-C} ${d:+"$d"} core.bare ;;
52 esac &&
53
12f7526c 54 echo "$expect" >expect &&
1e043cff 55 git ${d:+-C} ${d:+"$d"} rev-parse $o >actual &&
12f7526c
ES
56 test_cmp expect actual
57 '
58 shift
59 done
dace6e44
ML
60}
61
8fb3c00d 62ROOT=$(pwd)
7efeb8f0 63
d66f68ff
ES
64test_expect_success 'setup' '
65 mkdir -p sub/dir work &&
66 cp -R .git repo.git
67'
68
a2f5a876 69test_rev_parse toplevel false false true '' .git "$ROOT/.git"
dace6e44 70
a2f5a876
SG
71test_rev_parse -C .git .git/ false true false '' . "$ROOT/.git"
72test_rev_parse -C .git/objects .git/objects/ false true false '' "$ROOT/.git" "$ROOT/.git"
dace6e44 73
a2f5a876 74test_rev_parse -C sub/dir subdirectory false false true sub/dir/ "$ROOT/.git" "$ROOT/.git"
dace6e44 75
1dea0dc9 76test_rev_parse -b t 'core.bare = true' true false false
dace6e44 77
1dea0dc9 78test_rev_parse -b u 'core.bare undefined' false false true
dace6e44 79
dace6e44 80
a2f5a876 81test_rev_parse -C work -g ../.git -b f 'GIT_DIR=../.git, core.bare = false' false false true '' "../.git" "$ROOT/.git"
dace6e44 82
e6273f4d 83test_rev_parse -C work -g ../.git -b t 'GIT_DIR=../.git, core.bare = true' true false false ''
dace6e44 84
e6273f4d 85test_rev_parse -C work -g ../.git -b u 'GIT_DIR=../.git, core.bare undefined' false false true ''
dace6e44 86
dace6e44 87
a2f5a876 88test_rev_parse -C work -g ../repo.git -b f 'GIT_DIR=../repo.git, core.bare = false' false false true '' "../repo.git" "$ROOT/repo.git"
dace6e44 89
e6273f4d 90test_rev_parse -C work -g ../repo.git -b t 'GIT_DIR=../repo.git, core.bare = true' true false false ''
dace6e44 91
e6273f4d 92test_rev_parse -C work -g ../repo.git -b u 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
dace6e44 93
5de8a549
MR
94test_expect_success 'git-common-dir from worktree root' '
95 echo .git >expect &&
96 git rev-parse --git-common-dir >actual &&
97 test_cmp expect actual
98'
99
098aa867 100test_expect_success 'git-common-dir inside sub-dir' '
5de8a549
MR
101 mkdir -p path/to/child &&
102 test_when_finished "rm -rf path" &&
103 echo "$(git -C path/to/child rev-parse --show-cdup).git" >expect &&
104 git -C path/to/child rev-parse --git-common-dir >actual &&
105 test_cmp expect actual
106'
107
108test_expect_success 'git-path from worktree root' '
109 echo .git/objects >expect &&
110 git rev-parse --git-path objects >actual &&
111 test_cmp expect actual
112'
113
098aa867 114test_expect_success 'git-path inside sub-dir' '
5de8a549
MR
115 mkdir -p path/to/child &&
116 test_when_finished "rm -rf path" &&
117 echo "$(git -C path/to/child rev-parse --show-cdup).git/objects" >expect &&
118 git -C path/to/child rev-parse --git-path objects >actual &&
119 test_cmp expect actual
120'
121
417abfde
ØW
122test_expect_success 'rev-parse --is-shallow-repository in shallow repo' '
123 test_commit test_commit &&
124 echo true >expect &&
125 git clone --depth 1 --no-local . shallow &&
126 test_when_finished "rm -rf shallow" &&
127 git -C shallow rev-parse --is-shallow-repository >actual &&
128 test_cmp expect actual
129'
130
131test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' '
132 echo false >expect &&
133 git rev-parse --is-shallow-repository >actual &&
134 test_cmp expect actual
135'
136
2eabd383 137test_expect_success 'rev-parse --show-object-format in repo' '
138 echo "$(test_oid algo)" >expect &&
139 git rev-parse --show-object-format >actual &&
140 test_cmp expect actual &&
141 git rev-parse --show-object-format=storage >actual &&
142 test_cmp expect actual &&
143 git rev-parse --show-object-format=input >actual &&
144 test_cmp expect actual &&
145 git rev-parse --show-object-format=output >actual &&
146 test_cmp expect actual &&
147 test_must_fail git rev-parse --show-object-format=squeamish-ossifrage 2>err &&
148 grep "unknown mode for --show-object-format: squeamish-ossifrage" err
149'
150
2d92ab32
JK
151test_expect_success '--show-toplevel from subdir of working tree' '
152 pwd >expect &&
153 git -C sub/dir rev-parse --show-toplevel >actual &&
154 test_cmp expect actual
155'
156
157test_expect_success '--show-toplevel from inside .git' '
158 test_must_fail git -C .git rev-parse --show-toplevel
159'
160
bf0231c6
SB
161test_expect_success 'showing the superproject correctly' '
162 git rev-parse --show-superproject-working-tree >out &&
163 test_must_be_empty out &&
164
165 test_create_repo super &&
166 test_commit -C super test_commit &&
167 test_create_repo sub &&
168 test_commit -C sub test_commit &&
169 git -C super submodule add ../sub dir/sub &&
170 echo $(pwd)/super >expect &&
c5cbb27c
SM
171 git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&
172 test_cmp expect out &&
173
174 test_commit -C super submodule_add &&
175 git -C super checkout -b branch1 &&
176 git -C super/dir/sub checkout -b branch1 &&
177 test_commit -C super/dir/sub branch1_commit &&
178 git -C super add dir/sub &&
179 test_commit -C super branch1_commit &&
180 git -C super checkout -b branch2 master &&
181 git -C super/dir/sub checkout -b branch2 master &&
182 test_commit -C super/dir/sub branch2_commit &&
183 git -C super add dir/sub &&
184 test_commit -C super branch2_commit &&
185 test_must_fail git -C super merge branch1 &&
186
bf0231c6
SB
187 git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&
188 test_cmp expect out
189'
190
dace6e44 191test_done