blob: 11c15a48aab57ee81245a933f5dfdab5210103a5 [file] [log] [blame]
Glen Choo8d1a7442022-07-14 21:28:01 +00001#!/bin/sh
2
3test_description='verify safe.bareRepository checks'
4
5TEST_PASSES_SANITIZE_LEAK=true
6. ./test-lib.sh
7
8pwd="$(pwd)"
9
10expect_accepted () {
11 git "$@" rev-parse --git-dir
12}
13
14expect_rejected () {
15 test_must_fail git "$@" rev-parse --git-dir 2>err &&
16 grep -F "cannot use bare repository" err
17}
18
19test_expect_success 'setup bare repo in worktree' '
20 git init outer-repo &&
21 git init --bare outer-repo/bare-repo
22'
23
24test_expect_success 'safe.bareRepository unset' '
25 expect_accepted -C outer-repo/bare-repo
26'
27
28test_expect_success 'safe.bareRepository=all' '
29 test_config_global safe.bareRepository all &&
30 expect_accepted -C outer-repo/bare-repo
31'
32
33test_expect_success 'safe.bareRepository=explicit' '
34 test_config_global safe.bareRepository explicit &&
35 expect_rejected -C outer-repo/bare-repo
36'
37
38test_expect_success 'safe.bareRepository in the repository' '
39 # safe.bareRepository must not be "explicit", otherwise
40 # git config fails with "fatal: not in a git directory" (like
41 # safe.directory)
42 test_config -C outer-repo/bare-repo safe.bareRepository \
43 all &&
44 test_config_global safe.bareRepository explicit &&
45 expect_rejected -C outer-repo/bare-repo
46'
47
48test_expect_success 'safe.bareRepository on the command line' '
49 test_config_global safe.bareRepository explicit &&
50 expect_accepted -C outer-repo/bare-repo \
51 -c safe.bareRepository=all
52'
53
Glen Chooecec57b2022-10-13 17:43:47 +000054test_expect_success 'safe.bareRepository in included file' '
55 cat >gitconfig-include <<-\EOF &&
56 [safe]
57 bareRepository = explicit
58 EOF
59 git config --global --add include.path "$(pwd)/gitconfig-include" &&
60 expect_rejected -C outer-repo/bare-repo
61'
62
Glen Choo8d1a7442022-07-14 21:28:01 +000063test_done