0f9b8f99d3a993e015aff38985376edee9b57f12
[git-central.git] / tests / t2700-server-ensure-follows.sh
1 #!/bin/sh
2
3 test_description='server update ensure follows'
4
5 . ./test-lib.sh
6
7 test_expect_success 'setup' '
8         echo "setup" >a &&
9         git add a &&
10         git commit -m "setup" &&
11         git clone ./. server &&
12         rm -fr server/.git/hooks &&
13         git remote add origin ./server &&
14         git fetch
15 '
16
17 install_update_hook 'update-ensure-follows'
18
19 test_expect_success 'pushing stable works' '
20         git checkout -b stable &&
21         git push origin stable
22 '
23
24 test_expect_success 'branch with unmoved stable is okay' '
25         cd server &&
26         git config hooks.update-ensure-follows.branches stable &&
27         cd .. &&
28
29         git checkout -b topic1 &&
30         echo "$test_name" >a.topic1 &&
31         git add a.topic1 &&
32         git commit -m "Add on topic1." &&
33         git push origin topic1
34 '
35
36 test_expect_success 'branch with moved stable requires merge' '
37         git checkout stable &&
38         echo "$test_name" >a &&
39         git commit -a -m "Change on stable" &&
40         git push origin stable &&
41
42         git checkout topic1 &&
43         echo "$test_name" >a.topic1 &&
44         git commit -a -m "Change on topic1." &&
45         ! git push origin topic1 2>push.err &&
46         cat push.err | grep "You need to merge stable into topic1" &&
47
48         git merge stable &&
49         git push origin topic1
50 '
51
52 test_expect_success 'branch with moved stable is told to update first' '
53         git checkout stable &&
54         echo "$test_name" >a &&
55         git commit -a -m "Change on stable" &&
56         git push origin stable &&
57
58         # Someone fixes stable first
59         cd server &&
60         git checkout -f topic1 &&
61         git merge stable &&
62         cd .. &&
63
64         git checkout topic1 &&
65         echo "$test_name" >a.topic1 &&
66         git commit -a -m "Change on topic1." &&
67         ! git push --force origin topic1 2>push.err &&
68         cat push.err | grep "You need to update your local branch topic1" &&
69
70         # Now it will work as the teammate merged for us
71         git pull origin topic1 &&
72         git push origin topic1
73 '
74
75 test_expect_success 'branch with moved stable as second branch requires merge' '
76         cd server &&
77         git config hooks.update-ensure-follows.branches "foo stable" &&
78         cd .. &&
79
80         git checkout stable &&
81         echo "$test_name" >a &&
82         git commit -a -m "Change on stable" &&
83         git push origin stable &&
84
85         git checkout topic1 &&
86         echo "$test_name" >a.topic1 &&
87         git commit -a -m "Change on topic1." &&
88         ! git push origin topic1 2>push.err &&
89         cat push.err | grep "You need to merge stable into topic1" &&
90
91         git merge stable &&
92         git push origin topic1
93 '
94
95 test_expect_success 'tag with moved stable is okay' '
96         git checkout stable &&
97         echo "$test_name" >a &&
98         git commit -a -m "Change on stable" &&
99         git push origin stable &&
100
101         git checkout topic1 &&
102         git tag topic1-tag1
103         git push --tags
104 '
105
106 test_expect_success 'branch deletion with moved stable is okay' '
107         git checkout stable &&
108         echo "$test_name" >a &&
109         git commit -a -m "Change on stable" &&
110
111         git push origin :topic1
112 '
113
114 test_expect_success 'excused branch with moved stable is okay' '
115         git checkout -b topic2 stable &&
116         echo "$test_name" >a.topic2 &&
117         git add a.topic2 &&
118         git commit -m "Change on topic2" &&
119         git push origin topic2 &&
120
121         git checkout stable &&
122         echo "$test_name" >a &&
123         git commit -a -m "Change on stable" &&
124         git push origin stable &&
125
126         git checkout topic2 &&
127         echo "$test_name foo" >a.topic2 &&
128         git commit -a -m "Change on topic2 again" &&
129         ! git push origin topic2 &&
130
131         cd server &&
132         git config hooks.update-ensure-follows.excused topic2 &&
133         cd .. &&
134
135         git push origin topic2
136 '
137
138 test_done
139