Git fork
1#!/bin/sh
2
3test_description='send-pack --stdin tests'
4
5. ./test-lib.sh
6
7create_ref () {
8 tree=$(git write-tree) &&
9 test_tick &&
10 commit=$(echo "$1" | git commit-tree $tree) &&
11 git update-ref "$1" $commit
12}
13
14clear_remote () {
15 rm -rf remote.git &&
16 git init --bare remote.git
17}
18
19verify_push () {
20 git rev-parse "$1" >expect &&
21 git --git-dir=remote.git rev-parse "${2:-$1}" >actual &&
22 test_cmp expect actual
23}
24
25test_expect_success 'setup refs' '
26 cat >refs <<-\EOF &&
27 refs/heads/A
28 refs/heads/C
29 refs/tags/D
30 refs/heads/B
31 refs/tags/E
32 EOF
33 for i in $(cat refs); do
34 create_ref $i || return 1
35 done
36'
37
38# sanity check our setup
39test_expect_success 'refs on cmdline' '
40 clear_remote &&
41 git send-pack remote.git $(cat refs) &&
42 for i in $(cat refs); do
43 verify_push $i || return 1
44 done
45'
46
47test_expect_success 'refs over stdin' '
48 clear_remote &&
49 git send-pack remote.git --stdin <refs &&
50 for i in $(cat refs); do
51 verify_push $i || return 1
52 done
53'
54
55test_expect_success 'stdin lines are full refspecs' '
56 clear_remote &&
57 echo "A:other" >input &&
58 git send-pack remote.git --stdin <input &&
59 verify_push refs/heads/A refs/heads/other
60'
61
62test_expect_success 'stdin mixed with cmdline' '
63 clear_remote &&
64 echo A >input &&
65 git send-pack remote.git --stdin B <input &&
66 verify_push A &&
67 verify_push B
68'
69
70test_expect_success 'cmdline refs written in order' '
71 clear_remote &&
72 test_must_fail git send-pack remote.git A:foo B:foo 2>err &&
73 test_grep "multiple updates for ref ${SQ}refs/heads/foo${SQ} not allowed" err &&
74 test_must_fail git --git-dir=remote.git rev-parse foo
75'
76
77test_expect_success 'cmdline refs with multiple duplicates' '
78 clear_remote &&
79 test_must_fail git send-pack remote.git A:foo B:foo C:foo 2>err &&
80 test_grep "multiple updates for ref ${SQ}refs/heads/foo${SQ} not allowed" err &&
81 test_must_fail git --git-dir=remote.git rev-parse foo
82'
83
84test_expect_success '--stdin refs come after cmdline' '
85 clear_remote &&
86 echo A:foo >input &&
87 test_must_fail git send-pack remote.git --stdin B:foo <input &&
88 test_grep "multiple updates for ref ${SQ}refs/heads/foo${SQ} not allowed" err &&
89 test_must_fail git --git-dir=remote.git rev-parse foo
90'
91
92test_expect_success 'refspecs and --mirror do not mix (cmdline)' '
93 clear_remote &&
94 test_must_fail git send-pack remote.git --mirror $(cat refs)
95'
96
97test_expect_success 'refspecs and --mirror do not mix (stdin)' '
98 clear_remote &&
99 test_must_fail git send-pack remote.git --mirror --stdin <refs
100'
101
102test_done