]>
Commit | Line | Data |
---|---|---|
8d1a7448 GC |
1 | #!/bin/sh |
2 | ||
3 | test_description='verify safe.bareRepository checks' | |
4 | ||
5 | TEST_PASSES_SANITIZE_LEAK=true | |
6 | . ./test-lib.sh | |
7 | ||
8 | pwd="$(pwd)" | |
9 | ||
e35f202b GC |
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" | |
16 | } | |
17 | ||
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" | |
8d1a7448 GC |
22 | } |
23 | ||
24 | expect_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 | 32 | test_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 | ||
48 | test_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 | ||
53 | test_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 | ||
58 | test_expect_success 'safe.bareRepository=explicit' ' | |
59 | test_config_global safe.bareRepository explicit && | |
60 | expect_rejected -C outer-repo/bare-repo | |
61 | ' | |
62 | ||
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) | |
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 | ||
72 | test_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 |
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 | |
85 | ' | |
86 | ||
e35f202b GC |
87 | test_expect_success 'no trace when GIT_DIR is explicitly provided' ' |
88 | expect_accepted_explicit "$pwd/outer-repo/bare-repo" | |
89 | ' | |
90 | ||
45bb9162 KL |
91 | test_expect_success 'no trace when "bare repository" is .git' ' |
92 | expect_accepted_implicit -C outer-repo/.git | |
93 | ' | |
94 | ||
95 | test_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 |
99 | test_expect_success 'no trace in $GIT_DIR of secondary worktree' ' |
100 | expect_accepted_implicit -C outer-repo/.git/worktrees/outer-secondary | |
101 | ' | |
102 | ||
103 | test_expect_success 'no trace in $GIT_DIR of a submodule' ' | |
104 | expect_accepted_implicit -C outer-repo/.git/modules/subn | |
105 | ' | |
106 | ||
8d1a7448 | 107 | test_done |