fca8c3045a65d6f33e0ce8e0c1cfad6f6a8bfccd
[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_update_hook 'update-prefer-rebase'
26
27 #
28 # A -- B         <-- origin/stable
29 #  \   |
30 #   C -- D       <-- origin/topic1
31 #    \ |  \
32 #      e - f     <-- topic1
33 #
34 # Nope: should rebase e ontop of D
35 #
36 test_expect_success 'merging in stable does not fool the script' '
37         # start our branch, and share it
38         git checkout -b topic1 stable &&
39         git config --add branch.topic1.remote origin &&
40         git config --add branch.topic1.merge refs/heads/topic1 &&
41         echo "topic1" >a.topic1 &&
42         git add a.topic1 &&
43         git commit -m "topic1" &&
44         git push origin topic1 &&
45
46         # now, separately, move ahead stable, and share it
47         git checkout stable
48         echo "setup.stable.moved" >a &&
49         git commit -a -m "stable moved" &&
50         git push origin stable &&
51
52         # have another client commit (in this case, it is the server, but close enough) move topic1
53         cd server &&
54         git checkout topic1 &&
55         echo "$test_name" >a.client2 &&
56         git add a.client2 &&
57         git commit -m "topic1 changed by client2" &&
58         cd .. &&
59
60         # now locally try and merge in stable (even though topic1 is out of date)
61         git checkout topic1 &&
62         git merge stable &&
63
64         # We are shutdown for being a rewind
65         ! git push 2>push.err &&
66         cat push.err | grep "[rejected]        topic1 -> topic1 (non-fast forward)"
67
68         # Make a new merge commit
69         git pull &&
70         ! git push 2>push.err &&
71         cat push.err | grep "It looks like you should rebase instead of merging" &&
72
73         # Now fix it
74         git reset --hard ORIG_HEAD &&
75         GIT_EDITOR=: git rebase -i -p origin/topic1 &&
76         git push &&
77         git branch -r --contains stable | grep origin/topic
78 '
79
80 #
81 # A --C------            <-- origin/stable
82 #  \  |      \
83 #   B -- D -- E -- F     <-- origin/topic2
84 #    \|             \
85 #     g -- h ------- i   <-- topic2
86 #
87 # Trying to push F..i
88 #
89 # merge-base(F, h) has two options: B and C
90 #
91 test_expect_success 'merging in stable with tricky double baserev does not fool the script' '
92         # B: start our branch, and share it
93         git checkout -b topic2 stable &&
94         git config --add branch.topic2.remote origin &&
95         git config --add branch.topic2.merge refs/heads/topic2 &&
96         echo "commit B" >a.topic2 &&
97         git add a.topic2 &&
98         git commit -m "commit B created topic2" &&
99         git push origin topic2 &&
100
101         # C: now, separately, move ahead stable, and share it
102         git checkout stable
103         echo "commit C" >a &&
104         git commit -a -m "commit C moved stable" &&
105         git push origin stable &&
106
107         # D: have another client commit (in this case, it is the server, but close enough) moves topic2
108         cd server &&
109         git checkout topic2 &&
110         # We might have cruft from the previous test
111         git reset --hard &&
112         echo "commit D continuing topic2" >a.client2 &&
113         git add a.client2 &&
114         git commit -m "commit D by client2" &&
115
116         # E: another client merges stable
117         git merge stable &&
118
119         # F: another client moves topic2 again
120         echo "commit F" >a.client2 &&
121         git commit -a -m "commit F by client2" &&
122         cd .. &&
123
124         # g: now locally try and merge in stable (even though topic2 is out of date)
125         git checkout topic2 &&
126         git merge stable &&
127
128         # h: advance local topic2
129         echo "commit H" >a.topic2 &&
130         git commit -a -m "commit H continues local fork" &&
131
132         # i: make a new merge commit
133         git pull &&
134         ! git push origin topic2 2>push.err &&
135         cat push.err | grep "It looks like you should rebase instead of merging"
136
137         # Now fix it
138         # git reset --hard ORIG_HEAD &&
139         # GIT_EDITOR=: git rebase -i -p origin/topic2 &&
140         # git push &&
141         # git branch -r --contains stable | grep origin/topic2
142 '
143
144 test_done
145