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