Test rewind and rewind and continue even though we don't allow them.
[git-central.git] / tests / t2301-server-update-prefer-rebase-even-if-merges.sh
1 #!/bin/sh
2
3 test_description='server update prefer rebase (with incoming merges)'
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 ./. server &&
12         rm -fr server/.git/hooks &&
13         git remote add origin ./server &&
14         git config --add branch.master.remote origin &&
15         git config --add branch.master.merge refs/heads/master &&
16         git fetch &&
17
18         # Specifically, setup a stable that we will merge and check for rebase
19         git checkout -b stable master &&
20         echo "setup.stable" >a &&
21         git commit -a -m "stable" &&
22         git push origin stable
23 '
24
25 install_server_hook 'update-prefer-rebase' 'update'
26
27 test_expect_success 'merging in stable does not fool the script' '
28         # start our branch, and share it
29         git checkout -b topic1 stable &&
30         git config --add branch.topic1.remote origin &&
31         git config --add branch.topic1.merge refs/heads/topic1 &&
32         echo "topic1" >a.topic1 &&
33         git add a.topic1 &&
34         git commit -m "topic1" &&
35         git push origin topic1 &&
36
37         # now, separately, move ahead stable, and share it
38         git checkout stable
39         echo "setup.stable.moved" >a &&
40         git commit -a -m "stable moved" &&
41         git push origin stable &&
42
43         # have another client commit (in this case, it is the server, but close enough) move topic1
44         cd server &&
45         git checkout topic1 &&
46         echo "$test_name" >a.client2 &&
47         git add a.client2 &&
48         git commit -m "topic1 changed by client2" &&
49         cd .. &&
50
51         # now locally try and merge in stable (even though we are out of date)
52         git checkout topic1 &&
53         git merge stable &&
54
55         # We are shutdown for being a rewind
56         ! git push 2>push.err &&
57         cat push.err | grep "[rejected]        topic1 -> topic1 (non-fast forward)"
58
59         # Make a new merge commit
60         git pull &&
61         ! git push 2>push.err &&
62         cat push.err | grep "It looks like you should rebase instead of merging"
63 '
64
65 #
66 # A --C------            stable
67 #  \  |      \
68 #   B -- D -- E -- F     topic2
69 #    \|             \
70 #     G -- H ------- I   attempted push
71 #
72 # Trying to push F..I
73 #
74 # merge-base(F, H) has two options: B and C
75 #
76 test_expect_success 'merging in stable with tricky double baserev does not fool the script' '
77         # start our branch, and share it--commit B
78         git checkout -b topic2 stable &&
79         git config --add branch.topic2.remote origin &&
80         git config --add branch.topic2.merge refs/heads/topic2 &&
81         echo "commit B" >a.topic2 &&
82         git add a.topic2 &&
83         git commit -m "commit B created topic2" &&
84         git push origin topic2 &&
85
86         # now, separately, move ahead stable, and share it--commit C
87         git checkout stable
88         echo "commit C" >a &&
89         git commit -a -m "commit C moved stable" &&
90         git push origin stable &&
91
92         # have another client commit (in this case, it is the server, but close enough) moves topic2
93         cd server &&
94         git checkout topic2 &&
95         echo "commit D continuing topic2" >a.client2 &&
96         git add a.client2 &&
97         git commit -m "commit D by client2" &&
98
99         # Go ahead and merge in stable by the other client--commit E
100         git merge stable &&
101
102         # Then move topic2 put to--commit F
103         echo "commit F" >a.client2 &&
104         git commit -a -m "commit F by client2" &&
105         cd .. &&
106
107         # now locally try and merge in stable (even though we are out of date)--commit G
108         git checkout topic2 &&
109         git merge stable &&
110
111         # Go ahead and move our local topic2
112         echo "commit H" >a.topic2 &&
113         git commit -a -m "commit H continues local fork" &&
114
115         # Make a new merge commit
116         git pull &&
117         ! git push origin topic2
118         cat push.err | grep "It looks like you should rebase instead of merging"
119 '
120
121 test_done
122