Rewrite of stable protection with the 'no-ff' strategy.
[git-central.git] / tests / t2100-server-update-stable.sh
1 #!/bin/sh
2
3 test_description='server update stable enforcer'
4
5 . ./test-lib.sh
6
7 test_expect_success 'setup' '
8         echo This is a test. >a &&
9         git add a &&
10         git commit -m "a" &&
11         git clone ./. server &&
12         rm -fr server/.git/hooks &&
13         git checkout -b stable &&
14         git remote add origin ./server &&
15         git push origin stable &&
16         git config --add branch.stable.remote origin &&
17         git config --add branch.stable.merge refs/heads/stable
18 '
19
20 # setup the update hook
21 install_server_hook 'update-stable' 'update'
22
23 test_expect_success 'reject commit directly to stable' '
24         echo $test_name >a &&
25         git commit -a -m "$test_name going onto stable" &&
26         head=$(git rev-parse HEAD) &&
27         ! git push 2>push.err &&
28         cat push.err | grep "Moving stable must entail a merge commit" &&
29         git reset --hard HEAD^
30 '
31
32 test_expect_success 'reject fast-forward to candidate branch' '
33         # make one topic branch
34         git checkout -b topic1 stable &&
35         echo $test_name >topic1 &&
36         git add topic1 &&
37         git commit -m "$test_name topic1" &&
38         git push origin topic1 &&
39
40         git checkout stable &&
41         git merge topic1 >merge.out &&
42         cat merge.out | grep "Fast forward" &&
43         ! git push 2>push.err &&
44         cat push.err | grep "Moving stable must entail a single commit" &&
45         git reset --hard ORIG_HEAD
46 '
47
48 test_expect_success 'reject merge with wrong first-parent' '
49         # make one topic branch
50         git checkout -b topic2 stable &&
51         echo $test_name >topic2 &&
52         git add topic2 &&
53         git commit -m "$test_name topic2" &&
54         git push origin topic2 &&
55
56         # move ahead stable by topic3
57         git checkout -b topic3 stable &&
58         echo $test_name >topic3 &&
59         git add topic3 &&
60         git commit -m "$test_name topic3" &&
61         git push origin topic3 &&
62         git checkout stable &&
63         git merge --no-ff topic3 &&
64         git push &&
65
66         # back to topic2, merge in stable, and try to push it out as the new stable
67         git checkout topic2 &&
68         git merge stable &&
69         ! git push origin topic2:refs/heads/stable 2>push.err &&
70         cat push.err | grep "Moving stable must have the previous stable as the first parent" &&
71
72         # Go ahead and push topic2 itself
73         git push &&
74
75         # but merging into stable should still work fine
76         git checkout stable &&
77         git merge --no-ff topic2 &&
78         git push
79 '
80
81 test_expect_success 'reject merge with changes' '
82         # make one topic branch
83         git checkout -b topic4 stable &&
84         echo $test_name >topic4 &&
85         git add topic4 &&
86         git commit -m "$test_name topic4" &&
87         git push origin topic4 &&
88
89         # move ahead stable by topic5
90         git checkout -b topic5 stable &&
91         echo $test_name >topic5 &&
92         git add topic5 &&
93         git commit -m "$test_name topic5" &&
94         git push origin topic5 &&
95         git checkout stable &&
96         git merge --no-ff topic5 &&
97         git push &&
98
99         # try merging topic4 into stable, which will get a merge commit, but
100         # it should have changes involved and so get rejected
101         git checkout stable &&
102         git merge topic4 &&
103         ! git push 2>push.err &&
104         cat push.err | grep "Moving stable must not result in any changes"
105 '
106
107 test_done
108