@@ -119,4 +119,182 @@ test_expect_success 'local clone of unowned repo accepted in safe directory' '
119119 test_path_is_dir target
120120'
121121
122+ test_expect_success SYMLINKS ' checked paths are normalized' '
123+ test_when_finished "rm -rf repository; rm -f repo" &&
124+ (
125+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
126+ git config --global --unset-all safe.directory
127+ ) &&
128+ git init repository &&
129+ ln -s repository repo &&
130+ (
131+ cd repository &&
132+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
133+ test_commit sample
134+ ) &&
135+
136+ (
137+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
138+ git config --global safe.directory "$(pwd)/repository"
139+ ) &&
140+ git -C repository for-each-ref &&
141+ git -C repository/ for-each-ref &&
142+ git -C repo for-each-ref &&
143+ git -C repo/ for-each-ref &&
144+ test_must_fail git -C repository/.git for-each-ref &&
145+ test_must_fail git -C repository/.git/ for-each-ref &&
146+ test_must_fail git -C repo/.git for-each-ref &&
147+ test_must_fail git -C repo/.git/ for-each-ref
148+ '
149+
150+ test_expect_success SYMLINKS ' checked leading paths are normalized' '
151+ test_when_finished "rm -rf repository; rm -f repo" &&
152+ (
153+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
154+ git config --global --unset-all safe.directory
155+ ) &&
156+ mkdir -p repository &&
157+ git init repository/s &&
158+ ln -s repository repo &&
159+ (
160+ cd repository/s &&
161+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
162+ test_commit sample
163+ ) &&
164+
165+ (
166+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
167+ git config --global safe.directory "$(pwd)/repository/*"
168+ ) &&
169+ git -C repository/s for-each-ref &&
170+ git -C repository/s/ for-each-ref &&
171+ git -C repo/s for-each-ref &&
172+ git -C repo/s/ for-each-ref &&
173+ git -C repository/s/.git for-each-ref &&
174+ git -C repository/s/.git/ for-each-ref &&
175+ git -C repo/s/.git for-each-ref &&
176+ git -C repo/s/.git/ for-each-ref
177+ '
178+
179+ test_expect_success SYMLINKS ' configured paths are normalized' '
180+ test_when_finished "rm -rf repository; rm -f repo" &&
181+ (
182+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
183+ git config --global --unset-all safe.directory
184+ ) &&
185+ git init repository &&
186+ ln -s repository repo &&
187+ (
188+ cd repository &&
189+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
190+ test_commit sample
191+ ) &&
192+
193+ (
194+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
195+ git config --global safe.directory "$(pwd)/repo"
196+ ) &&
197+ git -C repository for-each-ref &&
198+ git -C repository/ for-each-ref &&
199+ git -C repo for-each-ref &&
200+ git -C repo/ for-each-ref &&
201+ test_must_fail git -C repository/.git for-each-ref &&
202+ test_must_fail git -C repository/.git/ for-each-ref &&
203+ test_must_fail git -C repo/.git for-each-ref &&
204+ test_must_fail git -C repo/.git/ for-each-ref
205+ '
206+
207+ test_expect_success SYMLINKS ' configured leading paths are normalized' '
208+ test_when_finished "rm -rf repository; rm -f repo" &&
209+ (
210+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
211+ git config --global --unset-all safe.directory
212+ ) &&
213+ mkdir -p repository &&
214+ git init repository/s &&
215+ ln -s repository repo &&
216+ (
217+ cd repository/s &&
218+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
219+ test_commit sample
220+ ) &&
221+
222+ (
223+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
224+ git config --global safe.directory "$(pwd)/repo/*"
225+ ) &&
226+ git -C repository/s for-each-ref &&
227+ git -C repository/s/ for-each-ref &&
228+ git -C repository/s/.git for-each-ref &&
229+ git -C repository/s/.git/ for-each-ref &&
230+ git -C repo/s for-each-ref &&
231+ git -C repo/s/ for-each-ref &&
232+ git -C repo/s/.git for-each-ref &&
233+ git -C repo/s/.git/ for-each-ref
234+ '
235+
236+ test_expect_success ' safe.directory set to a dot' '
237+ test_when_finished "rm -rf repository" &&
238+ (
239+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
240+ git config --global --unset-all safe.directory
241+ ) &&
242+ mkdir -p repository/subdir &&
243+ git init repository &&
244+ (
245+ cd repository &&
246+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
247+ test_commit sample
248+ ) &&
249+
250+ (
251+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
252+ git config --global safe.directory "."
253+ ) &&
254+ git -C repository for-each-ref &&
255+ git -C repository/ for-each-ref &&
256+ git -C repository/.git for-each-ref &&
257+ git -C repository/.git/ for-each-ref &&
258+
259+ # What is allowed is repository/subdir but the repository
260+ # path is repository.
261+ test_must_fail git -C repository/subdir for-each-ref &&
262+
263+ # Likewise, repository .git/refs is allowed with "." but
264+ # repository/.git that is accessed is not allowed.
265+ test_must_fail git -C repository/.git/refs for-each-ref
266+ '
267+
268+ test_expect_success ' safe.directory set to asterisk' '
269+ test_when_finished "rm -rf repository" &&
270+ (
271+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
272+ git config --global --unset-all safe.directory
273+ ) &&
274+ mkdir -p repository/subdir &&
275+ git init repository &&
276+ (
277+ cd repository &&
278+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
279+ test_commit sample
280+ ) &&
281+
282+ (
283+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
284+ git config --global safe.directory "*"
285+ ) &&
286+ # these are trivial
287+ git -C repository for-each-ref &&
288+ git -C repository/ for-each-ref &&
289+ git -C repository/.git for-each-ref &&
290+ git -C repository/.git/ for-each-ref &&
291+
292+ # With "*", everything is allowed, and the repository is
293+ # discovered, which is different behaviour from "." above.
294+ git -C repository/subdir for-each-ref &&
295+
296+ # Likewise.
297+ git -C repository/.git/refs for-each-ref
298+ '
299+
122300test_done
0 commit comments