3 test_description='server update prefer rebase (with incoming merges)'
7 test_expect_success 'setup' '
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 &&
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
25 install_update_hook 'update-prefer-rebase'
28 # A -- B <-- origin/stable
30 # C -- D <-- origin/topic1
34 # Nope: should rebase e ontop of D
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 &&
43 git commit -m "topic1" &&
44 git push origin topic1 &&
46 # now, separately, move ahead stable, and share it
48 echo "setup.stable.moved" >a &&
49 git commit -a -m "stable moved" &&
50 git push origin stable &&
52 # have another client commit (in this case, it is the server, but close enough) move topic1
54 git checkout topic1 &&
55 echo "$test_name" >a.client2 &&
57 git commit -m "topic1 changed by client2" &&
60 # now locally try and merge in stable (even though topic1 is out of date)
61 git checkout topic1 &&
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)"
68 # Make a new merge commit
70 ! git push 2>push.err &&
71 cat push.err | grep "It looks like you should rebase instead of merging" &&
74 git reset --hard ORIG_HEAD &&
75 GIT_EDITOR=: git rebase -i -p origin/topic1 &&
77 git branch -r --contains stable | grep origin/topic
81 # A --C------ <-- origin/stable
83 # B -- D -- E -- F <-- origin/topic2
85 # g -- h ------- i <-- topic2
89 # merge-base(F, h) has two options: B and C
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 &&
98 git commit -m "commit B created topic2" &&
99 git push origin topic2 &&
101 # C: now, separately, move ahead stable, and share it
103 echo "commit C" >a &&
104 git commit -a -m "commit C moved stable" &&
105 git push origin stable &&
107 # D: have another client commit (in this case, it is the server, but close enough) moves topic2
109 git checkout topic2 &&
110 # We might have cruft from the previous test
112 echo "commit D continuing topic2" >a.client2 &&
114 git commit -m "commit D by client2" &&
116 # E: another client merges stable
119 # F: another client moves topic2 again
120 echo "commit F" >a.client2 &&
121 git commit -a -m "commit F by client2" &&
124 # g: now locally try and merge in stable (even though topic2 is out of date)
125 git checkout topic2 &&
128 # h: advance local topic2
129 echo "commit H" >a.topic2 &&
130 git commit -a -m "commit H continues local fork" &&
132 # i: make a new merge commit
134 ! git push origin topic2 2>push.err &&
135 cat push.err | grep "It looks like you should rebase instead of merging"
138 # git reset --hard ORIG_HEAD &&
139 # GIT_EDITOR=: git rebase -i -p origin/topic2 &&
141 # git branch -r --contains stable | grep origin/topic2