Merge branch 'cb/maint-orphan-merge-noclobber'
[git/kirr.git] / t / t5520-pull.sh
blob0b489f5b1227268c050c1256d105d57d871f5698
1 #!/bin/sh
3 test_description='pulling into void'
5 . ./test-lib.sh
7 modify () {
8 sed -e "$1" <"$2" >"$2.x" &&
9 mv "$2.x" "$2"
12 D=`pwd`
14 test_expect_success setup '
16 echo file >file &&
17 git add file &&
18 git commit -a -m original
22 test_expect_success 'pulling into void' '
23 mkdir cloned &&
24 cd cloned &&
25 git init &&
26 git pull ..
29 cd "$D"
31 test_expect_success 'checking the results' '
32 test -f file &&
33 test -f cloned/file &&
34 test_cmp file cloned/file
37 test_expect_success 'pulling into void using master:master' '
38 mkdir cloned-uho &&
40 cd cloned-uho &&
41 git init &&
42 git pull .. master:master
43 ) &&
44 test -f file &&
45 test -f cloned-uho/file &&
46 test_cmp file cloned-uho/file
49 test_expect_success 'test . as a remote' '
51 git branch copy master &&
52 git config branch.copy.remote . &&
53 git config branch.copy.merge refs/heads/master &&
54 echo updated >file &&
55 git commit -a -m updated &&
56 git checkout copy &&
57 test `cat file` = file &&
58 git pull &&
59 test `cat file` = updated
62 test_expect_success 'the default remote . should not break explicit pull' '
63 git checkout -b second master^ &&
64 echo modified >file &&
65 git commit -a -m modified &&
66 git checkout copy &&
67 git reset --hard HEAD^ &&
68 test `cat file` = file &&
69 git pull . second &&
70 test `cat file` = modified
73 test_expect_success '--rebase' '
74 git branch to-rebase &&
75 echo modified again > file &&
76 git commit -m file file &&
77 git checkout to-rebase &&
78 echo new > file2 &&
79 git add file2 &&
80 git commit -m "new file" &&
81 git tag before-rebase &&
82 git pull --rebase . copy &&
83 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
84 test new = $(git show HEAD:file2)
87 test_expect_success 'branch.to-rebase.rebase' '
88 git reset --hard before-rebase &&
89 git config branch.to-rebase.rebase 1 &&
90 git pull . copy &&
91 git config branch.to-rebase.rebase 0 &&
92 test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
93 test new = $(git show HEAD:file2)
96 test_expect_success '--rebase with rebased upstream' '
98 git remote add -f me . &&
99 git checkout copy &&
100 git tag copy-orig &&
101 git reset --hard HEAD^ &&
102 echo conflicting modification > file &&
103 git commit -m conflict file &&
104 git checkout to-rebase &&
105 echo file > file2 &&
106 git commit -m to-rebase file2 &&
107 git tag to-rebase-orig &&
108 git pull --rebase me copy &&
109 test "conflicting modification" = "$(cat file)" &&
110 test file = $(cat file2)
114 test_expect_success '--rebase with rebased default upstream' '
116 git update-ref refs/remotes/me/copy copy-orig &&
117 git checkout --track -b to-rebase2 me/copy &&
118 git reset --hard to-rebase-orig &&
119 git pull --rebase &&
120 test "conflicting modification" = "$(cat file)" &&
121 test file = $(cat file2)
125 test_expect_success 'rebased upstream + fetch + pull --rebase' '
127 git update-ref refs/remotes/me/copy copy-orig &&
128 git reset --hard to-rebase-orig &&
129 git checkout --track -b to-rebase3 me/copy &&
130 git reset --hard to-rebase-orig &&
131 git fetch &&
132 git pull --rebase &&
133 test "conflicting modification" = "$(cat file)" &&
134 test file = "$(cat file2)"
138 test_expect_success 'pull --rebase dies early with dirty working directory' '
140 git checkout to-rebase &&
141 git update-ref refs/remotes/me/copy copy^ &&
142 COPY=$(git rev-parse --verify me/copy) &&
143 git rebase --onto $COPY copy &&
144 git config branch.to-rebase.remote me &&
145 git config branch.to-rebase.merge refs/heads/copy &&
146 git config branch.to-rebase.rebase true &&
147 echo dirty >> file &&
148 git add file &&
149 test_must_fail git pull &&
150 test $COPY = $(git rev-parse --verify me/copy) &&
151 git checkout HEAD -- file &&
152 git pull &&
153 test $COPY != $(git rev-parse --verify me/copy)
157 test_expect_success 'pull --rebase works on branch yet to be born' '
158 git rev-parse master >expect &&
159 mkdir empty_repo &&
160 (cd empty_repo &&
161 git init &&
162 git pull --rebase .. master &&
163 git rev-parse HEAD >../actual
164 ) &&
165 test_cmp expect actual
168 test_expect_success 'setup for detecting upstreamed changes' '
169 mkdir src &&
170 (cd src &&
171 git init &&
172 printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
173 git add stuff &&
174 git commit -m "Initial revision"
175 ) &&
176 git clone src dst &&
177 (cd src &&
178 modify s/5/43/ stuff &&
179 git commit -a -m "5->43" &&
180 modify s/6/42/ stuff &&
181 git commit -a -m "Make it bigger"
182 ) &&
183 (cd dst &&
184 modify s/5/43/ stuff &&
185 git commit -a -m "Independent discovery of 5->43"
189 test_expect_success 'git pull --rebase detects upstreamed changes' '
190 (cd dst &&
191 git pull --rebase &&
192 test -z "$(git ls-files -u)"
196 test_expect_success 'setup for avoiding reapplying old patches' '
197 (cd dst &&
198 test_might_fail git rebase --abort &&
199 git reset --hard origin/master
200 ) &&
201 git clone --bare src src-replace.git &&
202 rm -rf src &&
203 mv src-replace.git src &&
204 (cd dst &&
205 modify s/2/22/ stuff &&
206 git commit -a -m "Change 2" &&
207 modify s/3/33/ stuff &&
208 git commit -a -m "Change 3" &&
209 modify s/4/44/ stuff &&
210 git commit -a -m "Change 4" &&
211 git push &&
213 modify s/44/55/ stuff &&
214 git commit --amend -a -m "Modified Change 4"
218 test_expect_success 'git pull --rebase does not reapply old patches' '
219 (cd dst &&
220 test_must_fail git pull --rebase &&
221 test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
225 test_done