]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0035-safe-bare-repository.sh
The third batch
[thirdparty/git.git] / t / t0035-safe-bare-repository.sh
CommitLineData
8d1a7448
GC
1#!/bin/sh
2
3test_description='verify safe.bareRepository checks'
4
5TEST_PASSES_SANITIZE_LEAK=true
6. ./test-lib.sh
7
8pwd="$(pwd)"
9
e35f202b
GC
10expect_accepted_implicit () {
11 test_when_finished 'rm "$pwd/trace.perf"' &&
12 GIT_TRACE2_PERF="$pwd/trace.perf" git "$@" rev-parse --git-dir &&
13 # Note: we're intentionally only checking that the bare repo has a
14 # directory *prefix* of $pwd
15 grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf"
16}
17
18expect_accepted_explicit () {
19 test_when_finished 'rm "$pwd/trace.perf"' &&
20 GIT_DIR="$1" GIT_TRACE2_PERF="$pwd/trace.perf" git rev-parse --git-dir &&
21 ! grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf"
8d1a7448
GC
22}
23
24expect_rejected () {
e35f202b
GC
25 test_when_finished 'rm "$pwd/trace.perf"' &&
26 test_env GIT_TRACE2_PERF="$pwd/trace.perf" \
27 test_must_fail git "$@" rev-parse --git-dir 2>err &&
28 grep -F "cannot use bare repository" err &&
29 grep -F "implicit-bare-repository:$pwd" "$pwd/trace.perf"
8d1a7448
GC
30}
31
30b7c4bd 32test_expect_success 'setup an embedded bare repo, secondary worktree and submodule' '
8d1a7448 33 git init outer-repo &&
30b7c4bd
JH
34 git init --bare --initial-branch=main outer-repo/bare-repo &&
35 git -C outer-repo worktree add ../outer-secondary &&
36 test_path_is_dir outer-secondary &&
37 (
38 cd outer-repo &&
39 test_commit A &&
40 git push bare-repo +HEAD:refs/heads/main &&
41 git -c protocol.file.allow=always \
42 submodule add --name subn -- ./bare-repo subd
43 ) &&
44 test_path_is_dir outer-repo/.git/worktrees/outer-secondary &&
45 test_path_is_dir outer-repo/.git/modules/subn
8d1a7448
GC
46'
47
48test_expect_success 'safe.bareRepository unset' '
e35f202b
GC
49 test_unconfig --global safe.bareRepository &&
50 expect_accepted_implicit -C outer-repo/bare-repo
8d1a7448
GC
51'
52
53test_expect_success 'safe.bareRepository=all' '
54 test_config_global safe.bareRepository all &&
e35f202b 55 expect_accepted_implicit -C outer-repo/bare-repo
8d1a7448
GC
56'
57
58test_expect_success 'safe.bareRepository=explicit' '
59 test_config_global safe.bareRepository explicit &&
60 expect_rejected -C outer-repo/bare-repo
61'
62
63test_expect_success 'safe.bareRepository in the repository' '
64 # safe.bareRepository must not be "explicit", otherwise
65 # git config fails with "fatal: not in a git directory" (like
66 # safe.directory)
30b7c4bd 67 test_config -C outer-repo/bare-repo safe.bareRepository all &&
8d1a7448
GC
68 test_config_global safe.bareRepository explicit &&
69 expect_rejected -C outer-repo/bare-repo
70'
71
72test_expect_success 'safe.bareRepository on the command line' '
73 test_config_global safe.bareRepository explicit &&
e35f202b 74 expect_accepted_implicit -C outer-repo/bare-repo \
8d1a7448
GC
75 -c safe.bareRepository=all
76'
77
ecec57b3
GC
78test_expect_success 'safe.bareRepository in included file' '
79 cat >gitconfig-include <<-\EOF &&
80 [safe]
81 bareRepository = explicit
82 EOF
83 git config --global --add include.path "$(pwd)/gitconfig-include" &&
84 expect_rejected -C outer-repo/bare-repo
85'
86
e35f202b
GC
87test_expect_success 'no trace when GIT_DIR is explicitly provided' '
88 expect_accepted_explicit "$pwd/outer-repo/bare-repo"
89'
90
45bb9162
KL
91test_expect_success 'no trace when "bare repository" is .git' '
92 expect_accepted_implicit -C outer-repo/.git
93'
94
95test_expect_success 'no trace when "bare repository" is a subdir of .git' '
96 expect_accepted_implicit -C outer-repo/.git/objects
97'
98
30b7c4bd
JH
99test_expect_success 'no trace in $GIT_DIR of secondary worktree' '
100 expect_accepted_implicit -C outer-repo/.git/worktrees/outer-secondary
101'
102
103test_expect_success 'no trace in $GIT_DIR of a submodule' '
104 expect_accepted_implicit -C outer-repo/.git/modules/subn
105'
106
8d1a7448 107test_done