It's unlikely, but warn the user to update first before telling them they need to...
[git-central.git] / tests / t2300-server-update-prefer-rebase.sh
1 #!/bin/sh
2
3 test_description='server update prefer rebase'
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
19 install_update_hook 'update-prefer-rebase'
20
21 test_expect_success 'merge local changes is caught' '
22         # make an outstanding change for us--but do not push
23         echo "$test_name" >a.client1 &&
24         git add a.client1 &&
25         git commit -m "$test_name on client1" &&
26
27         # have another client commit (in this case, it is the server, but close enough)
28         cd server &&
29         echo "$test_name" >a.client2 &&
30         git add a.client2 &&
31         git commit -m "$test_name on client2" &&
32
33         # go back to our client and it will merge in our changes
34         cd .. &&
35         git pull &&
36         merge=$(git rev-parse HEAD) &&
37
38         ! git push 2>push.err &&
39         cat push.err | grep "It looks like you should rebase instead of merging $merge" &&
40         git reset --hard origin/master
41 '
42
43 test_expect_success 'merge local changes followed by more commits is caught' '
44         # make an outstanding change for us--but do not push
45         echo "$test_name" >a.client1 &&
46         git add a.client1 &&
47         git commit -m "$test_name on client1" &&
48
49         # have another client commit (in this case, it is the server, but close enough)
50         cd server &&
51         echo "$test_name" >a.client2 &&
52         git add a.client2 &&
53         git commit -m "$test_name on client2" &&
54
55         # go back to our client and it will merge in our changes
56         cd .. &&
57         git pull &&
58         merge=$(git rev-parse HEAD) &&
59
60         # To complicate things, have them add another change
61         echo "$test_name again" >a.client1 &&
62         git commit -a -m "$test_name on client1 again" &&
63
64         ! git push 2>push.err &&
65         cat push.err | grep "It looks like you should rebase instead of merging $merge" &&
66         git reset --hard origin/master
67 '
68
69 test_expect_success 'merge shared changes from another topic is okay' '
70         # make a change on topic for us and share it
71         git checkout -b topic master &&
72         echo "$test_name" >a.client1 &&
73         git add a.client1 &&
74         git commit -m "$test_name on client1 and topic" &&
75         git push origin topic &&
76
77         # make an outstanding on topic that is not pushed
78         echo "$test_name again" >>a.client1 &&
79         git commit -a -m "$test_name on client1 and topic again" &&
80
81         # have another client commit to master (in this case, it is the server, but close enough)
82         cd server &&
83         echo "$test_name" >a.client2 &&
84         git add a.client2 &&
85         git commit -m "$test_name on client2" &&
86
87         # go back to our client and it will merge in our changes
88         cd .. &&
89         git checkout master &&
90         # this should fast fwd
91         git pull &&
92         # this pulls in the shared branch+its new tip
93         git merge topic &&
94
95         git push
96 '
97
98 test_expect_success 'simple commit' '
99         # go back to topic and make a simple commit/push as a sanity check
100         git checkout topic &&
101         echo "$test_name" >>a.client1 &&
102         git commit -a -m "$test_name on client1 and topic" &&
103         git push
104 '
105
106 test_done
107