File: t0035-safe-bare-repository.sh

package info (click to toggle)
git 1%3A2.39.5-0%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 56,868 kB
  • sloc: ansic: 276,518; sh: 234,536; perl: 30,909; tcl: 22,191; makefile: 4,185; python: 3,412; javascript: 772; csh: 45; ruby: 43; lisp: 12
file content (63 lines) | stat: -rwxr-xr-x 1,617 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh

test_description='verify safe.bareRepository checks'

TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh

pwd="$(pwd)"

expect_accepted () {
	git "$@" rev-parse --git-dir
}

expect_rejected () {
	test_must_fail git "$@" rev-parse --git-dir 2>err &&
	grep -F "cannot use bare repository" err
}

test_expect_success 'setup bare repo in worktree' '
	git init outer-repo &&
	git init --bare outer-repo/bare-repo
'

test_expect_success 'safe.bareRepository unset' '
	expect_accepted -C outer-repo/bare-repo
'

test_expect_success 'safe.bareRepository=all' '
	test_config_global safe.bareRepository all &&
	expect_accepted -C outer-repo/bare-repo
'

test_expect_success 'safe.bareRepository=explicit' '
	test_config_global safe.bareRepository explicit &&
	expect_rejected -C outer-repo/bare-repo
'

test_expect_success 'safe.bareRepository in the repository' '
	# safe.bareRepository must not be "explicit", otherwise
	# git config fails with "fatal: not in a git directory" (like
	# safe.directory)
	test_config -C outer-repo/bare-repo safe.bareRepository \
		all &&
	test_config_global safe.bareRepository explicit &&
	expect_rejected -C outer-repo/bare-repo
'

test_expect_success 'safe.bareRepository on the command line' '
	test_config_global safe.bareRepository explicit &&
	expect_accepted -C outer-repo/bare-repo \
		-c safe.bareRepository=all
'

test_expect_success 'safe.bareRepository in included file' '
	cat >gitconfig-include <<-\EOF &&
	[safe]
		bareRepository = explicit
	EOF
	git config --global --add include.path "$(pwd)/gitconfig-include" &&
	expect_rejected -C outer-repo/bare-repo
'

test_done