summaryrefslogtreecommitdiff
path: root/t/t5408-send-pack-stdin.sh
blob: e8737df6f95cde09b97bddba1425253039e58dbc (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
#!/bin/sh

test_description='send-pack --stdin tests'
. ./test-lib.sh

create_ref () {
	tree=$(git write-tree) &&
	test_tick &&
	commit=$(echo "$1" | git commit-tree $tree) &&
	git update-ref "$1" $commit
}

clear_remote () {
	rm -rf remote.git &&
	git init --bare remote.git
}

verify_push () {
	git rev-parse "$1" >expect &&
	git --git-dir=remote.git rev-parse "${2:-$1}" >actual &&
	test_cmp expect actual
}

test_expect_success 'setup refs' '
	cat >refs <<-\EOF &&
	refs/heads/A
	refs/heads/C
	refs/tags/D
	refs/heads/B
	refs/tags/E
	EOF
	for i in $(cat refs); do
		create_ref $i || return 1
	done
'

# sanity check our setup
test_expect_success 'refs on cmdline' '
	clear_remote &&
	git send-pack remote.git $(cat refs) &&
	for i in $(cat refs); do
		verify_push $i || return 1
	done
'

test_expect_success 'refs over stdin' '
	clear_remote &&
	git send-pack remote.git --stdin <refs &&
	for i in $(cat refs); do
		verify_push $i || return 1
	done
'

test_expect_success 'stdin lines are full refspecs' '
	clear_remote &&
	echo "A:other" >input &&
	git send-pack remote.git --stdin <input &&
	verify_push refs/heads/A refs/heads/other
'

test_expect_success 'stdin mixed with cmdline' '
	clear_remote &&
	echo A >input &&
	git send-pack remote.git --stdin B <input &&
	verify_push A &&
	verify_push B
'

test_expect_success 'cmdline refs written in order' '
	clear_remote &&
	test_must_fail git send-pack remote.git A:foo B:foo &&
	verify_push A foo
'

test_expect_success '--stdin refs come after cmdline' '
	clear_remote &&
	echo A:foo >input &&
	test_must_fail git send-pack remote.git --stdin B:foo <input &&
	verify_push B foo
'

test_expect_success 'refspecs and --mirror do not mix (cmdline)' '
	clear_remote &&
	test_must_fail git send-pack remote.git --mirror $(cat refs)
'

test_expect_success 'refspecs and --mirror do not mix (stdin)' '
	clear_remote &&
	test_must_fail git send-pack remote.git --mirror --stdin <refs
'

test_done