3 test_description
='test git rev-parse'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 # usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir absolute-git-dir
17 -C) d
="$2"; shift; shift ;;
19 [tfu
]*) bare
="$2"; shift; shift ;;
20 *) error
"test_rev_parse: bogus core.bare value '$2'" ;;
22 -g) gitdir
="$2"; shift; shift ;;
23 -*) error
"test_rev_parse: unrecognized option '$1'" ;;
31 for o
in --is-bare-repository \
33 --is-inside-work-tree \
38 test $# -eq 0 && break
40 test_expect_success
"$name: $o" '
43 test_when_finished "unset GIT_DIR" &&
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 ;;
54 echo "$expect" >expect &&
55 git ${d:+-C} ${d:+"$d"} rev-parse $o >actual &&
56 test_cmp expect actual
64 test_expect_success
'setup' '
65 mkdir -p sub/dir work &&
69 test_rev_parse toplevel false false true
'' .git
"$ROOT/.git"
71 test_rev_parse
-C .git .git
/ false true false
'' .
"$ROOT/.git"
72 test_rev_parse
-C .git
/objects .git
/objects
/ false true false
'' "$ROOT/.git" "$ROOT/.git"
74 test_rev_parse
-C sub
/dir subdirectory false false true sub
/dir
/ "$ROOT/.git" "$ROOT/.git"
76 test_rev_parse
-b t
'core.bare = true' true false false
78 test_rev_parse
-b u
'core.bare undefined' false false true
81 test_rev_parse
-C work
-g ..
/.git
-b f
'GIT_DIR=../.git, core.bare = false' false false true
'' "../.git" "$ROOT/.git"
83 test_rev_parse
-C work
-g ..
/.git
-b t
'GIT_DIR=../.git, core.bare = true' true false false
''
85 test_rev_parse
-C work
-g ..
/.git
-b u
'GIT_DIR=../.git, core.bare undefined' false false true
''
88 test_rev_parse
-C work
-g ..
/repo.git
-b f
'GIT_DIR=../repo.git, core.bare = false' false false true
'' "../repo.git" "$ROOT/repo.git"
90 test_rev_parse
-C work
-g ..
/repo.git
-b t
'GIT_DIR=../repo.git, core.bare = true' true false false
''
92 test_rev_parse
-C work
-g ..
/repo.git
-b u
'GIT_DIR=../repo.git, core.bare undefined' false false true
''
94 test_expect_success
'git-common-dir from worktree root' '
96 git rev-parse --git-common-dir >actual &&
97 test_cmp expect actual
100 test_expect_success
'git-common-dir inside sub-dir' '
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
108 test_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
114 test_expect_success
'git-path inside sub-dir' '
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
122 test_expect_success
'rev-parse --is-shallow-repository in shallow repo' '
123 test_commit test_commit &&
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
131 test_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
137 test_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
151 test_expect_success
'--show-toplevel from subdir of working tree' '
153 git -C sub/dir rev-parse --show-toplevel >actual &&
154 test_cmp expect actual
157 test_expect_success
'--show-toplevel from inside .git' '
158 test_must_fail git -C .git rev-parse --show-toplevel
161 test_expect_success
'showing the superproject correctly' '
162 git rev-parse --show-superproject-working-tree >out &&
163 test_must_be_empty out &&
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 &&
171 git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&
172 test_cmp expect out &&
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 main &&
181 git -C super/dir/sub checkout -b branch2 main &&
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 &&
187 git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&