parse-options: recognize abbreviated negated option with arg
[git.git] / t / t0035-safe-bare-repository.sh
blob804885637954a57ba85e139591e6a0f5a5167034
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 bare repo in worktree' '
33 git init outer-repo &&
34 git init --bare outer-repo/bare-repo
37 test_expect_success 'safe.bareRepository unset' '
38 test_unconfig --global safe.bareRepository &&
39 expect_accepted_implicit -C outer-repo/bare-repo
42 test_expect_success 'safe.bareRepository=all' '
43 test_config_global safe.bareRepository all &&
44 expect_accepted_implicit -C outer-repo/bare-repo
47 test_expect_success 'safe.bareRepository=explicit' '
48 test_config_global safe.bareRepository explicit &&
49 expect_rejected -C outer-repo/bare-repo
52 test_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
62 test_expect_success 'safe.bareRepository on the command line' '
63 test_config_global safe.bareRepository explicit &&
64 expect_accepted_implicit -C outer-repo/bare-repo \
65 -c safe.bareRepository=all
68 test_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
77 test_expect_success 'no trace when GIT_DIR is explicitly provided' '
78 expect_accepted_explicit "$pwd/outer-repo/bare-repo"
81 test_expect_success 'no trace when "bare repository" is .git' '
82 expect_accepted_implicit -C outer-repo/.git
85 test_expect_success 'no trace when "bare repository" is a subdir of .git' '
86 expect_accepted_implicit -C outer-repo/.git/objects
89 test_done