Use the new install_update_hook function.
[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 'all local changes do not need a merge' '
22         # server is on "setup"
23
24         # make an outstanding change for us--but do not push
25         echo "$test_name" >a.client1 &&
26         git add a.client1 &&
27         git commit -m "$test_name on client1" &&
28
29         # have another client commit (in this case, it is the server, but close enough)
30         cd server &&
31         echo "$test_name" >a.client2 &&
32         git add a.client2 &&
33         git commit -m "$test_name on client2" &&
34
35         # go back to our client and it will merge in our changes
36         cd .. &&
37         git pull &&
38         merge=$(git rev-parse HEAD) &&
39
40         ! git push 2>push.err &&
41         cat push.err | grep "It looks like you should rebase instead of merging $merge" &&
42         git reset --hard origin/master
43 '
44
45 test_expect_success 'all local changes do not need a merge even with more commits after' '
46         # server is on "setup"
47
48         # make an outstanding change for us--but do not push
49         echo "$test_name" >a.client1 &&
50         git add a.client1 &&
51         git commit -m "$test_name on client1" &&
52
53         # have another client commit (in this case, it is the server, but close enough)
54         cd server &&
55         echo "$test_name" >a.client2 &&
56         git add a.client2 &&
57         git commit -m "$test_name on client2" &&
58
59         # go back to our client and it will merge in our changes
60         cd .. &&
61         git pull &&
62         merge=$(git rev-parse HEAD) &&
63
64         # To complicate things, have them add another change
65         echo "$test_name again" >a.client1 &&
66         git commit -a -m "$test_name on client1 again" &&
67
68         ! git push 2>push.err &&
69         cat push.err | grep "It looks like you should rebase instead of merging $merge" &&
70         git reset --hard origin/master
71 '
72
73 test_expect_success 'already shared topic changes do warrant a merge' '
74         # server is on "setup"
75
76         # make a change on topic for us and share it
77         git checkout -b topic master &&
78         echo "$test_name" >a.client1 &&
79         git add a.client1 &&
80         git commit -m "$test_name on client1 and topic" &&
81         git push origin topic &&
82
83         # make an outstanding change that we will have to merge later
84         echo "$test_name again" >>a.client1 &&
85         git commit -a -m "$test_name on client1 and topic again" &&
86
87         # have another client commit to master (in this case, it is the server, but close enough)
88         cd server &&
89         echo "$test_name" >a.client2 &&
90         git add a.client2 &&
91         git commit -m "$test_name on client2" &&
92
93         # go back to our client and it will merge in our changes
94         cd .. &&
95         git checkout master &&
96         git pull &&
97         git merge topic &&
98
99         git push
100 '
101
102 test_expect_success 'simple commit' '
103         # go back to topic and make a simple commit/push as a sanity check
104         git checkout topic &&
105         echo "$test_name" >>a.client1 &&
106         git commit -a -m "$test_name on client1 and topic" &&
107         git push
108 '
109
110 test_done
111