3 test_description='test git rev-parse'
6 # usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir absolute-git-dir
14 -C) d="$2"; shift; shift ;;
16 [tfu]*) bare="$2"; shift; shift ;;
17 *) error "test_rev_parse: bogus core.bare value '$2'" ;;
19 -g) gitdir="$2"; shift; shift ;;
20 -*) error "test_rev_parse: unrecognized option '$1'" ;;
28 for o in --is-bare-repository \
30 --is-inside-work-tree \
35 test $# -eq 0 && break
37 test_expect_success "$name: $o" '
40 test_when_finished "unset GIT_DIR" &&
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 ;;
51 echo "$expect" >expect &&
52 git ${d:+-C} ${d:+"$d"} rev-parse $o >actual &&
53 test_cmp expect actual
61 test_expect_success 'setup' '
62 mkdir -p sub/dir work &&
66 test_rev_parse toplevel false false true '' .git "$ROOT/.git"
68 test_rev_parse -C .git .git/ false true false '' . "$ROOT/.git"
69 test_rev_parse -C .git/objects .git/objects/ false true false '' "$ROOT/.git" "$ROOT/.git"
71 test_rev_parse -C sub/dir subdirectory false false true sub/dir/ "$ROOT/.git" "$ROOT/.git"
73 test_rev_parse -b t 'core.bare = true' true false false
75 test_rev_parse -b u 'core.bare undefined' false false true
78 test_rev_parse -C work -g ../.git -b f 'GIT_DIR=../.git, core.bare = false' false false true '' "../.git" "$ROOT/.git"
80 test_rev_parse -C work -g ../.git -b t 'GIT_DIR=../.git, core.bare = true' true false false ''
82 test_rev_parse -C work -g ../.git -b u 'GIT_DIR=../.git, core.bare undefined' false false true ''
85 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"
87 test_rev_parse -C work -g ../repo.git -b t 'GIT_DIR=../repo.git, core.bare = true' true false false ''
89 test_rev_parse -C work -g ../repo.git -b u 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
91 test_expect_success 'git-common-dir from worktree root' '
93 git rev-parse --git-common-dir >actual &&
94 test_cmp expect actual
97 test_expect_success 'git-common-dir inside sub-dir' '
98 mkdir -p path/to/child &&
99 test_when_finished "rm -rf path" &&
100 echo "$(git -C path/to/child rev-parse --show-cdup).git" >expect &&
101 git -C path/to/child rev-parse --git-common-dir >actual &&
102 test_cmp expect actual
105 test_expect_success 'git-path from worktree root' '
106 echo .git/objects >expect &&
107 git rev-parse --git-path objects >actual &&
108 test_cmp expect actual
111 test_expect_success 'git-path inside sub-dir' '
112 mkdir -p path/to/child &&
113 test_when_finished "rm -rf path" &&
114 echo "$(git -C path/to/child rev-parse --show-cdup).git/objects" >expect &&
115 git -C path/to/child rev-parse --git-path objects >actual &&
116 test_cmp expect actual
119 test_expect_success 'rev-parse --is-shallow-repository in shallow repo' '
120 test_commit test_commit &&
122 git clone --depth 1 --no-local . shallow &&
123 test_when_finished "rm -rf shallow" &&
124 git -C shallow rev-parse --is-shallow-repository >actual &&
125 test_cmp expect actual
128 test_expect_success 'rev-parse --is-shallow-repository in non-shallow repo' '
129 echo false >expect &&
130 git rev-parse --is-shallow-repository >actual &&
131 test_cmp expect actual
134 test_expect_success 'rev-parse --show-object-format in repo' '
135 echo "$(test_oid algo)" >expect &&
136 git rev-parse --show-object-format >actual &&
137 test_cmp expect actual &&
138 git rev-parse --show-object-format=storage >actual &&
139 test_cmp expect actual &&
140 git rev-parse --show-object-format=input >actual &&
141 test_cmp expect actual &&
142 git rev-parse --show-object-format=output >actual &&
143 test_cmp expect actual &&
144 test_must_fail git rev-parse --show-object-format=squeamish-ossifrage 2>err &&
145 grep "unknown mode for --show-object-format: squeamish-ossifrage" err
148 test_expect_success '--show-toplevel from subdir of working tree' '
150 git -C sub/dir rev-parse --show-toplevel >actual &&
151 test_cmp expect actual
154 test_expect_success '--show-toplevel from inside .git' '
155 test_must_fail git -C .git rev-parse --show-toplevel
158 test_expect_success 'showing the superproject correctly' '
159 git rev-parse --show-superproject-working-tree >out &&
160 test_must_be_empty out &&
162 test_create_repo super &&
163 test_commit -C super test_commit &&
164 test_create_repo sub &&
165 test_commit -C sub test_commit &&
166 git -C super submodule add ../sub dir/sub &&
167 echo $(pwd)/super >expect &&
168 git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&
169 test_cmp expect out &&
171 test_commit -C super submodule_add &&
172 git -C super checkout -b branch1 &&
173 git -C super/dir/sub checkout -b branch1 &&
174 test_commit -C super/dir/sub branch1_commit &&
175 git -C super add dir/sub &&
176 test_commit -C super branch1_commit &&
177 git -C super checkout -b branch2 master &&
178 git -C super/dir/sub checkout -b branch2 master &&
179 test_commit -C super/dir/sub branch2_commit &&
180 git -C super add dir/sub &&
181 test_commit -C super branch2_commit &&
182 test_must_fail git -C super merge branch1 &&
184 git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&