Git 2.45
[git/gitster.git] / t / t0035-safe-bare-repository.sh
blobd3cb2a1cb9edb8f9ad7480be6ec3e02b464046bd
1 #!/bin/sh
3 test_description='verify safe.bareRepository checks'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 pwd="$(pwd)"
10 expect_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"
18 expect_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"
24 expect_rejected () {
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"
32 test_expect_success 'setup an embedded bare repo, secondary worktree and submodule' '
33 git init outer-repo &&
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 &&
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
48 test_expect_success 'safe.bareRepository unset' '
49 test_unconfig --global safe.bareRepository &&
50 expect_accepted_implicit -C outer-repo/bare-repo
53 test_expect_success 'safe.bareRepository=all' '
54 test_config_global safe.bareRepository all &&
55 expect_accepted_implicit -C outer-repo/bare-repo
58 test_expect_success 'safe.bareRepository=explicit' '
59 test_config_global safe.bareRepository explicit &&
60 expect_rejected -C outer-repo/bare-repo
63 test_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)
67 test_config -C outer-repo/bare-repo safe.bareRepository all &&
68 test_config_global safe.bareRepository explicit &&
69 expect_rejected -C outer-repo/bare-repo
72 test_expect_success 'safe.bareRepository on the command line' '
73 test_config_global safe.bareRepository explicit &&
74 expect_accepted_implicit -C outer-repo/bare-repo \
75 -c safe.bareRepository=all
78 test_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
87 test_expect_success 'no trace when GIT_DIR is explicitly provided' '
88 expect_accepted_explicit "$pwd/outer-repo/bare-repo"
91 test_expect_success 'no trace when "bare repository" is .git' '
92 expect_accepted_implicit -C outer-repo/.git
95 test_expect_success 'no trace when "bare repository" is a subdir of .git' '
96 expect_accepted_implicit -C outer-repo/.git/objects
99 test_expect_success 'no trace in $GIT_DIR of secondary worktree' '
100 expect_accepted_implicit -C outer-repo/.git/worktrees/outer-secondary
103 test_expect_success 'no trace in $GIT_DIR of a submodule' '
104 expect_accepted_implicit -C outer-repo/.git/modules/subn
107 test_done