]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0035-safe-bare-repository.sh
Merge branch 'jc/bisect-doc' into maint-2.43
[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
32test_expect_success 'setup bare repo in worktree' '
33 git init outer-repo &&
34 git init --bare outer-repo/bare-repo
35'
36
37test_expect_success 'safe.bareRepository unset' '
e35f202b
GC
38 test_unconfig --global safe.bareRepository &&
39 expect_accepted_implicit -C outer-repo/bare-repo
8d1a7448
GC
40'
41
42test_expect_success 'safe.bareRepository=all' '
43 test_config_global safe.bareRepository all &&
e35f202b 44 expect_accepted_implicit -C outer-repo/bare-repo
8d1a7448
GC
45'
46
47test_expect_success 'safe.bareRepository=explicit' '
48 test_config_global safe.bareRepository explicit &&
49 expect_rejected -C outer-repo/bare-repo
50'
51
52test_expect_success 'safe.bareRepository in the repository' '
53 # safe.bareRepository must not be "explicit", otherwise
54 # git config fails with "fatal: not in a git directory" (like
55 # safe.directory)
56 test_config -C outer-repo/bare-repo safe.bareRepository \
57 all &&
58 test_config_global safe.bareRepository explicit &&
59 expect_rejected -C outer-repo/bare-repo
60'
61
62test_expect_success 'safe.bareRepository on the command line' '
63 test_config_global safe.bareRepository explicit &&
e35f202b 64 expect_accepted_implicit -C outer-repo/bare-repo \
8d1a7448
GC
65 -c safe.bareRepository=all
66'
67
ecec57b3
GC
68test_expect_success 'safe.bareRepository in included file' '
69 cat >gitconfig-include <<-\EOF &&
70 [safe]
71 bareRepository = explicit
72 EOF
73 git config --global --add include.path "$(pwd)/gitconfig-include" &&
74 expect_rejected -C outer-repo/bare-repo
75'
76
e35f202b
GC
77test_expect_success 'no trace when GIT_DIR is explicitly provided' '
78 expect_accepted_explicit "$pwd/outer-repo/bare-repo"
79'
80
8d1a7448 81test_done