Fix pull in the case when we have no local changes.
[git-central.git] / tests / t5200-pull.sh
1 #!/bin/sh
2
3 test_description='script pull'
4
5 . ./test-lib.sh
6
7 export PATH=$PATH:../../scripts
8
9 test_expect_success 'setup' '
10         echo "setup" >a &&
11         git add a &&
12         git commit -m "setup" &&
13         git clone ./. server &&
14         rm -fr server/.git/hooks &&
15         git remote add origin ./server &&
16         git checkout -b stable &&
17         git push origin stable
18 '
19
20 test_expect_success 'pull does a rebase' '
21         checkout topic1 &&
22         echo "$test_name" >a.topic1 &&
23         git add a.topic1 &&
24         git commit -m "move topic1" &&
25
26         # Move topic1 on the server
27         cd server &&
28         git checkout topic1 &&
29         echo "$test_name" >a &&
30         git commit -a -m "move topic1 on the server" &&
31         cd .. &&
32
33         # Only one parent
34         pull &&
35         test 1 = $(git cat-file commit $(git rev-parse HEAD) | grep parent | wc -l)
36 '
37
38 test_expect_success 'pull does a rebase but does not fuck up merges' '
39         checkout topic2 &&
40         echo "$test_name on topic2" >a.topic2 &&
41         git add a.topic2 &&
42         git commit -a -m "create topic2" &&
43         git push origin topic2 &&
44
45         # Move stable
46         git checkout stable &&
47         echo "$test_name on stable" >a &&
48         git commit -a -m "move stable that will not be replayed" &&
49         git push origin stable &&
50
51         # And merge stable into topic2
52         git checkout topic2 &&
53         git merge stable &&
54
55         # Move topic2 on the server
56         cd server &&
57         git checkout topic2 &&
58         echo "$test_name" >a.topic2.server &&
59         git add a.topic2.server &&
60         git commit -m "move topic2 on the server" &&
61         cd .. &&
62
63         # Merge stable locally too--should conflict
64         git checkout topic2 &&
65         pull &&
66         test 1 = $(git rev-list --all --pretty=oneline | grep "replayed" | wc -l) &&
67         push
68 '
69
70 test_expect_success 'pull moves when we have no local changes' '
71         git checkout topic2 &&
72
73         # Move topic2 on the server
74         cd server &&
75         git checkout topic2 &&
76         echo "$test_name" > a.topic2.server &&
77         git commit -a -m "move topic2 on the server" &&
78         cd .. &&
79
80         pull &&
81         test $(git rev-parse HEAD) = $(git rev-parse origin/topic2)
82 '
83
84 test_done
85