3 test_description='server update stable enforcer'
7 test_expect_success 'setup' '
8 echo This is a test. >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
20 # setup the update hook
21 install_server_hook 'update-stable' 'update'
23 test_expect_success 'reject commit directly to stable' '
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^
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 &&
37 git commit -m "$test_name topic1" &&
38 git push origin topic1 &&
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
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 &&
53 git commit -m "$test_name topic2" &&
54 git push origin topic2 &&
56 # move ahead stable by topic3
57 git checkout -b topic3 stable &&
58 echo $test_name >topic3 &&
60 git commit -m "$test_name topic3" &&
61 git push origin topic3 &&
62 git checkout stable &&
63 git merge --no-ff topic3 &&
66 # back to topic2, merge in stable, and try to push it out as the new stable
67 git checkout topic2 &&
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" &&
72 # Go ahead and push topic2 itself
75 # but merging into stable should still work fine
76 git checkout stable &&
77 git merge --no-ff topic2 &&
81 test_expect_success 'reject merge with changes' '
82 # make one topic branch
83 git checkout -b topic4 stable &&
84 echo $test_name >topic4 &&
86 git commit -m "$test_name topic4" &&
87 git push origin topic4 &&
89 # move ahead stable by topic5
90 git checkout -b topic5 stable &&
91 echo $test_name >topic5 &&
93 git commit -m "$test_name topic5" &&
94 git push origin topic5 &&
95 git checkout stable &&
96 git merge --no-ff topic5 &&
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 &&
103 ! git push 2>push.err &&
104 cat push.err | grep "Moving stable must not result in any changes"