aboutsummaryrefslogtreecommitdiff
path: root/t/t5900-repo-selection.sh
blob: 3d5b418bb48ae9fa50411d1c88bc19b3404f1da1 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh

test_description='selecting remote repo in ambiguous cases'
. ./test-lib.sh

reset() {
	rm -rf foo foo.git fetch clone
}

make_tree() {
	git init "$1" &&
	(cd "$1" && test_commit "$1")
}

make_bare() {
	git init --bare "$1" &&
	(cd "$1" &&
	 tree=`git hash-object -w -t tree /dev/null` &&
	 commit=$(echo "$1" | git commit-tree $tree) &&
	 git update-ref HEAD $commit
	)
}

get() {
	git init --bare fetch &&
	(cd fetch && git fetch "../$1") &&
	git clone "$1" clone
}

check() {
	echo "$1" >expect &&
	(cd fetch && git log -1 --format=%s FETCH_HEAD) >actual.fetch &&
	(cd clone && git log -1 --format=%s HEAD) >actual.clone &&
	test_cmp expect actual.fetch &&
	test_cmp expect actual.clone
}

test_expect_success 'find .git dir in worktree' '
	reset &&
	make_tree foo &&
	get foo &&
	check foo
'

test_expect_success 'automagically add .git suffix' '
	reset &&
	make_bare foo.git &&
	get foo &&
	check foo.git
'

test_expect_success 'automagically add .git suffix to worktree' '
	reset &&
	make_tree foo.git &&
	get foo &&
	check foo.git
'

test_expect_success 'prefer worktree foo over bare foo.git' '
	reset &&
	make_tree foo &&
	make_bare foo.git &&
	get foo &&
	check foo
'

test_expect_success 'prefer bare foo over bare foo.git' '
	reset &&
	make_bare foo &&
	make_bare foo.git &&
	get foo &&
	check foo
'

test_expect_success 'disambiguate with full foo.git' '
	reset &&
	make_bare foo &&
	make_bare foo.git &&
	get foo.git &&
	check foo.git
'

test_expect_success 'we are not fooled by non-git foo directory' '
	reset &&
	make_bare foo.git &&
	mkdir foo &&
	get foo &&
	check foo.git
'

test_expect_success 'prefer inner .git over outer bare' '
	reset &&
	make_tree foo &&
	make_bare foo.git &&
	mv foo/.git foo.git &&
	get foo.git &&
	check foo
'

test_done