f3b38673f01becbbfc1fb166a6d26ec36f8ceb70
[git-central.git] / tests / t2700-ensure-follows.sh
1 #!/bin/bash
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 -l . --bare server.git &&
12         rm -fr server.git/hooks &&
13         git remote add origin ./server.git &&
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         GIT_DIR=server.git git config hooks.update-ensure-follows.branches stable &&
26
27         git checkout -b topic1 &&
28         echo "$test_name" >a.topic1 &&
29         git add a.topic1 &&
30         git commit -m "Add on topic1." &&
31         git push origin topic1
32 '
33
34 test_expect_success 'branch with moved stable requires merge' '
35         git checkout stable &&
36         echo "$test_name" >a &&
37         git commit -a -m "Change on stable" &&
38         git push origin stable &&
39
40         git checkout topic1 &&
41         echo "$test_name" >a.topic1 &&
42         git commit -a -m "Change on topic1." &&
43         ! git push origin topic1 2>push.err &&
44         cat push.err | grep "You need to merge stable into topic1" &&
45
46         git merge stable &&
47         git push origin topic1
48 '
49
50 test_expect_success 'branch with moved stable is told to update first' '
51         git checkout stable &&
52         echo "$test_name" >a &&
53         git commit -a -m "Change on stable" &&
54         git push origin stable &&
55
56         # Someone fixes stable first
57         git clone server.git person2 &&
58         cd person2 &&
59         git checkout -f topic1 &&
60         git remote add server ../server.git &&
61         git merge origin/stable &&
62         git push server topic1 &&
63         cd .. &&
64
65         git checkout topic1 &&
66         echo "$test_name" >a.topic1 &&
67         git commit -a -m "Change on topic1." &&
68         ! git push --force origin topic1 2>push.err &&
69         cat push.err | grep "You need to update your local branch topic1" &&
70
71         # Now it will work as the teammate merged for us
72         git pull origin topic1 &&
73         git push origin topic1
74 '
75
76 test_expect_success 'branch with moved stable as second branch requires merge' '
77         GIT_DIR=server.git git config hooks.update-ensure-follows.branches "foo stable" &&
78
79         git checkout stable &&
80         echo "$test_name" >a &&
81         git commit -a -m "Change on stable" &&
82         git push origin stable &&
83
84         git checkout topic1 &&
85         echo "$test_name" >a.topic1 &&
86         git commit -a -m "Change on topic1." &&
87         ! git push origin topic1 2>push.err &&
88         cat push.err | grep "You need to merge stable into topic1" &&
89
90         git merge stable &&
91         git push origin topic1
92 '
93
94 test_expect_success 'tag with moved stable is okay' '
95         git checkout stable &&
96         echo "$test_name" >a &&
97         git commit -a -m "Change on stable" &&
98         git push origin stable &&
99
100         git checkout topic1 &&
101         git tag topic1-tag1
102         git push --tags
103 '
104
105 test_expect_success 'branch deletion with moved stable is okay' '
106         git checkout stable &&
107         echo "$test_name" >a &&
108         git commit -a -m "Change on stable" &&
109
110         git push origin :topic1
111 '
112
113 test_expect_success 'excused branch with moved stable is okay' '
114         git checkout -b topic2 stable &&
115         echo "$test_name" >a.topic2 &&
116         git add a.topic2 &&
117         git commit -m "Change on topic2" &&
118         git push origin topic2 &&
119
120         git checkout stable &&
121         echo "$test_name" >a &&
122         git commit -a -m "Change on stable" &&
123         git push origin stable &&
124
125         git checkout topic2 &&
126         echo "$test_name foo" >a.topic2 &&
127         git commit -a -m "Change on topic2 again" &&
128         ! git push origin topic2 &&
129
130         GIT_DIR=server.git git config hooks.update-ensure-follows.excused topic2 &&
131
132         git push origin topic2
133 '
134
135 test_expect_success 'new branch without stable gets nicer error' '
136         git checkout -b topic3 stable &&
137         echo "$test_name" >a.topic3 &&
138         git add a.topic3 &&
139         git commit -m "Change on topic3" &&
140
141         git checkout stable &&
142         echo "$test_name" >a &&
143         git commit -a -m "Change on stable" &&
144         git push origin stable &&
145
146         git checkout topic3 &&
147         ! git push origin topic3 2>push.err &&
148         grep "You need to merge stable into topic3" push.err &&
149
150         git merge stable &&
151         git push origin topic3
152 '
153
154 test_done
155