3 test_description='server update stable enforcer'
7 test_expect_success 'setup' '
11 git clone -l . --bare server.git &&
12 git remote add origin ./server.git &&
13 rm -fr server.git/hooks
16 # setup the update hook
17 install_update_hook 'update-stable'
19 test_expect_success 'initial stable commit works' '
20 # do one stable-less commit
22 git commit -a -m "$test_name" &&
23 git push origin master &&
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
31 test_expect_success 'reject commit directly to stable' '
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^
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 &&
45 git commit -m "$test_name topic1" &&
46 git push origin topic1 &&
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
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 &&
61 git commit -m "$test_name topic2" &&
62 git push origin topic2 &&
64 # move ahead stable by topic3
65 git checkout -b topic3 stable &&
66 echo $test_name >topic3 &&
68 git commit -m "$test_name topic3" &&
69 git push origin topic3 &&
70 git checkout stable &&
71 git merge --no-ff topic3 &&
74 # back to topic2, merge in stable, and try to push it out as the new stable
75 git checkout topic2 &&
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" &&
80 # Go ahead and push topic2 itself
83 # but merging into stable should still work fine
84 git checkout stable &&
85 git merge --no-ff topic2 &&
89 test_expect_success 'reject merge with changes' '
90 # make one topic branch
91 git checkout -b topic4 stable &&
92 echo $test_name >topic4 &&
94 git commit -m "$test_name topic4" &&
95 git push origin topic4 &&
97 # move ahead stable by topic5
98 git checkout -b topic5 stable &&
99 echo $test_name >topic5 &&
101 git commit -m "$test_name topic5" &&
102 git push origin topic5 &&
103 git checkout stable &&
104 git merge --no-ff topic5 &&
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) &&
112 ! git push 2>push.err &&
113 cat push.err | grep "Moving stable must not result in any changes from $topic4_hash"