]>
Commit | Line | Data |
---|---|---|
d09e79cb LT |
1 | #!/bin/sh |
2 | ||
3 | test_description='pulling into void' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
3cee9236 EN |
7 | modify () { |
8 | sed -e "$1" <"$2" >"$2.x" && | |
9 | mv "$2.x" "$2" | |
10 | } | |
11 | ||
d09e79cb LT |
12 | D=`pwd` |
13 | ||
14 | test_expect_success setup ' | |
15 | ||
16 | echo file >file && | |
17 | git add file && | |
18 | git commit -a -m original | |
19 | ||
20 | ' | |
21 | ||
22 | test_expect_success 'pulling into void' ' | |
23 | mkdir cloned && | |
24 | cd cloned && | |
5c94f87e | 25 | git init && |
d09e79cb LT |
26 | git pull .. |
27 | ' | |
28 | ||
29 | cd "$D" | |
30 | ||
31 | test_expect_success 'checking the results' ' | |
32 | test -f file && | |
33 | test -f cloned/file && | |
4fdf71be | 34 | test_cmp file cloned/file |
d09e79cb LT |
35 | ' |
36 | ||
b0ad11ea JH |
37 | test_expect_success 'pulling into void using master:master' ' |
38 | mkdir cloned-uho && | |
39 | ( | |
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 | |
47 | ' | |
48 | ||
9debc324 PB |
49 | test_expect_success 'test . as a remote' ' |
50 | ||
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 | |
60 | ' | |
61 | ||
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 | |
71 | ' | |
72 | ||
cd67e4d4 JS |
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) | |
85 | ' | |
86 | ||
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 && | |
c85c7927 | 91 | git config branch.to-rebase.rebase 0 && |
cd67e4d4 JS |
92 | test $(git rev-parse HEAD^) = $(git rev-parse copy) && |
93 | test new = $(git show HEAD:file2) | |
94 | ' | |
95 | ||
c85c7927 JS |
96 | test_expect_success '--rebase with rebased upstream' ' |
97 | ||
98 | git remote add -f me . && | |
99 | git checkout copy && | |
e9460a66 | 100 | git tag copy-orig && |
c85c7927 JS |
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 && | |
e9460a66 | 107 | git tag to-rebase-orig && |
c85c7927 JS |
108 | git pull --rebase me copy && |
109 | test "conflicting modification" = "$(cat file)" && | |
110 | test file = $(cat file2) | |
111 | ||
112 | ' | |
113 | ||
e9460a66 SB |
114 | test_expect_success '--rebase with rebased default upstream' ' |
115 | ||
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) | |
122 | ||
123 | ' | |
124 | ||
d44e7126 | 125 | test_expect_success 'rebased upstream + fetch + pull --rebase' ' |
a418441b SB |
126 | |
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 && | |
d44e7126 | 132 | git pull --rebase && |
a418441b SB |
133 | test "conflicting modification" = "$(cat file)" && |
134 | test file = "$(cat file2)" | |
135 | ||
136 | ' | |
137 | ||
f9189cf8 JS |
138 | test_expect_success 'pull --rebase dies early with dirty working directory' ' |
139 | ||
e9460a66 | 140 | git checkout to-rebase && |
f9189cf8 JS |
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) | |
154 | ||
155 | ' | |
156 | ||
19a7fcbf JK |
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 | |
166 | ' | |
167 | ||
3cee9236 EN |
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" | |
186 | ) | |
187 | ' | |
188 | ||
cf65426d | 189 | test_expect_success 'git pull --rebase detects upstreamed changes' ' |
3cee9236 EN |
190 | (cd dst && |
191 | git pull --rebase && | |
192 | test -z "$(git ls-files -u)" | |
193 | ) | |
194 | ' | |
195 | ||
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 && | |
212 | ||
213 | modify s/44/55/ stuff && | |
214 | git commit --amend -a -m "Modified Change 4" | |
215 | ) | |
216 | ' | |
217 | ||
cf65426d | 218 | test_expect_success 'git pull --rebase does not reapply old patches' ' |
3cee9236 EN |
219 | (cd dst && |
220 | test_must_fail git pull --rebase && | |
221 | test 1 = $(find .git/rebase-apply -name "000*" | wc -l) | |
222 | ) | |
223 | ' | |
224 | ||
fe249b42 MZ |
225 | test_expect_success 'git pull --rebase against local branch' ' |
226 | git checkout -b copy2 to-rebase-orig && | |
227 | git pull --rebase . to-rebase && | |
228 | test "conflicting modification" = "$(cat file)" && | |
229 | test file = "$(cat file2)" | |
230 | ' | |
231 | ||
d09e79cb | 232 | test_done |