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