@@ -86,16 +86,19 @@ test_expect_success 'pulling into void must not create an octopus' '
86
86
'
87
87
88
88
test_expect_success ' test . as a remote' '
89
-
90
89
git branch copy master &&
91
90
git config branch.copy.remote . &&
92
91
git config branch.copy.merge refs/heads/master &&
93
92
echo updated >file &&
94
93
git commit -a -m updated &&
95
94
git checkout copy &&
96
- test ` cat file` = file &&
95
+ test "$( cat file)" = file &&
97
96
git pull &&
98
- test `cat file` = updated
97
+ test "$(cat file)" = updated &&
98
+ git reflog -1 >reflog.actual &&
99
+ sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
100
+ echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
101
+ test_cmp reflog.expected reflog.fuzzy
99
102
'
100
103
101
104
test_expect_success ' the default remote . should not break explicit pull' '
@@ -104,9 +107,108 @@ test_expect_success 'the default remote . should not break explicit pull' '
104
107
git commit -a -m modified &&
105
108
git checkout copy &&
106
109
git reset --hard HEAD^ &&
107
- test ` cat file` = file &&
110
+ test "$( cat file)" = file &&
108
111
git pull . second &&
109
- test `cat file` = modified
112
+ test "$(cat file)" = modified &&
113
+ git reflog -1 >reflog.actual &&
114
+ sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
115
+ echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
116
+ test_cmp reflog.expected reflog.fuzzy
117
+ '
118
+
119
+ test_expect_success ' fail if wildcard spec does not match any refs' '
120
+ git checkout -b test copy^ &&
121
+ test_when_finished "git checkout -f copy && git branch -D test" &&
122
+ test "$(cat file)" = file &&
123
+ test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
124
+ test_i18ngrep "no candidates for merging" err &&
125
+ test "$(cat file)" = file
126
+ '
127
+
128
+ test_expect_success ' fail if no branches specified with non-default remote' '
129
+ git remote add test_remote . &&
130
+ test_when_finished "git remote remove test_remote" &&
131
+ git checkout -b test copy^ &&
132
+ test_when_finished "git checkout -f copy && git branch -D test" &&
133
+ test "$(cat file)" = file &&
134
+ test_config branch.test.remote origin &&
135
+ test_must_fail git pull test_remote 2>err &&
136
+ test_i18ngrep "specify a branch on the command line" err &&
137
+ test "$(cat file)" = file
138
+ '
139
+
140
+ test_expect_success ' fail if not on a branch' '
141
+ git remote add origin . &&
142
+ test_when_finished "git remote remove origin" &&
143
+ git checkout HEAD^ &&
144
+ test_when_finished "git checkout -f copy" &&
145
+ test "$(cat file)" = file &&
146
+ test_must_fail git pull 2>err &&
147
+ test_i18ngrep "not currently on a branch" err &&
148
+ test "$(cat file)" = file
149
+ '
150
+
151
+ test_expect_success ' fail if no configuration for current branch' '
152
+ git remote add test_remote . &&
153
+ test_when_finished "git remote remove test_remote" &&
154
+ git checkout -b test copy^ &&
155
+ test_when_finished "git checkout -f copy && git branch -D test" &&
156
+ test_config branch.test.remote test_remote &&
157
+ test "$(cat file)" = file &&
158
+ test_must_fail git pull 2>err &&
159
+ test_i18ngrep "no tracking information" err &&
160
+ test "$(cat file)" = file
161
+ '
162
+
163
+ test_expect_success ' fail if upstream branch does not exist' '
164
+ git checkout -b test copy^ &&
165
+ test_when_finished "git checkout -f copy && git branch -D test" &&
166
+ test_config branch.test.remote . &&
167
+ test_config branch.test.merge refs/heads/nonexisting &&
168
+ test "$(cat file)" = file &&
169
+ test_must_fail git pull 2>err &&
170
+ test_i18ngrep "no such ref was fetched" err &&
171
+ test "$(cat file)" = file
172
+ '
173
+
174
+ test_expect_success ' fail if the index has unresolved entries' '
175
+ git checkout -b third second^ &&
176
+ test_when_finished "git checkout -f copy && git branch -D third" &&
177
+ test "$(cat file)" = file &&
178
+ test_commit modified2 file &&
179
+ test -z "$(git ls-files -u)" &&
180
+ test_must_fail git pull . second &&
181
+ test -n "$(git ls-files -u)" &&
182
+ cp file expected &&
183
+ test_must_fail git pull . second 2>err &&
184
+ test_i18ngrep "Pull is not possible because you have unmerged files" err &&
185
+ test_cmp expected file &&
186
+ git add file &&
187
+ test -z "$(git ls-files -u)" &&
188
+ test_must_fail git pull . second 2>err &&
189
+ test_i18ngrep "You have not concluded your merge" err &&
190
+ test_cmp expected file
191
+ '
192
+
193
+ test_expect_success ' fast-forwards working tree if branch head is updated' '
194
+ git checkout -b third second^ &&
195
+ test_when_finished "git checkout -f copy && git branch -D third" &&
196
+ test "$(cat file)" = file &&
197
+ git pull . second:third 2>err &&
198
+ test_i18ngrep "fetch updated the current branch head" err &&
199
+ test "$(cat file)" = modified &&
200
+ test "$(git rev-parse third)" = "$(git rev-parse second)"
201
+ '
202
+
203
+ test_expect_success ' fast-forward fails with conflicting work tree' '
204
+ git checkout -b third second^ &&
205
+ test_when_finished "git checkout -f copy && git branch -D third" &&
206
+ test "$(cat file)" = file &&
207
+ echo conflict >file &&
208
+ test_must_fail git pull . second:third 2>err &&
209
+ test_i18ngrep "Cannot fast-forward your working tree" err &&
210
+ test "$(cat file)" = conflict &&
211
+ test "$(git rev-parse third)" = "$(git rev-parse second)"
110
212
'
111
213
112
214
test_expect_success ' --rebase' '
@@ -119,32 +221,41 @@ test_expect_success '--rebase' '
119
221
git commit -m "new file" &&
120
222
git tag before-rebase &&
121
223
git pull --rebase . copy &&
122
- test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
123
- test new = $(git show HEAD:file2)
224
+ test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
225
+ test new = "$(git show HEAD:file2)"
226
+ '
227
+
228
+ test_expect_success ' --rebase fails with multiple branches' '
229
+ git reset --hard before-rebase &&
230
+ test_must_fail git pull --rebase . copy master 2>err &&
231
+ test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
232
+ test_i18ngrep "Cannot rebase onto multiple branches" err &&
233
+ test modified = "$(git show HEAD:file)"
124
234
'
235
+
125
236
test_expect_success ' pull.rebase' '
126
237
git reset --hard before-rebase &&
127
238
test_config pull.rebase true &&
128
239
git pull . copy &&
129
- test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
130
- test new = $(git show HEAD:file2)
240
+ test " $(git rev-parse HEAD^)" = " $(git rev-parse copy)" &&
241
+ test new = " $(git show HEAD:file2)"
131
242
'
132
243
133
244
test_expect_success ' branch.to-rebase.rebase' '
134
245
git reset --hard before-rebase &&
135
246
test_config branch.to-rebase.rebase true &&
136
247
git pull . copy &&
137
- test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
138
- test new = $(git show HEAD:file2)
248
+ test " $(git rev-parse HEAD^)" = " $(git rev-parse copy)" &&
249
+ test new = " $(git show HEAD:file2)"
139
250
'
140
251
141
252
test_expect_success ' branch.to-rebase.rebase should override pull.rebase' '
142
253
git reset --hard before-rebase &&
143
254
test_config pull.rebase true &&
144
255
test_config branch.to-rebase.rebase false &&
145
256
git pull . copy &&
146
- test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
147
- test new = $(git show HEAD:file2)
257
+ test " $(git rev-parse HEAD^)" != " $(git rev-parse copy)" &&
258
+ test new = " $(git show HEAD:file2)"
148
259
'
149
260
150
261
# add a feature branch, keep-merge, that is merged into master, so the
@@ -163,33 +274,33 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
163
274
git reset --hard before-preserve-rebase &&
164
275
test_config pull.rebase false &&
165
276
git pull . copy &&
166
- test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
167
- test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
168
- test file3 = $(git show HEAD:file3.t)
277
+ test " $(git rev-parse HEAD^1)" = " $(git rev-parse before-preserve-rebase)" &&
278
+ test " $(git rev-parse HEAD^2)" = " $(git rev-parse copy)" &&
279
+ test file3 = " $(git show HEAD:file3.t)"
169
280
'
170
281
171
282
test_expect_success ' pull.rebase=true flattens keep-merge' '
172
283
git reset --hard before-preserve-rebase &&
173
284
test_config pull.rebase true &&
174
285
git pull . copy &&
175
- test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
176
- test file3 = $(git show HEAD:file3.t)
286
+ test " $(git rev-parse HEAD^^)" = " $(git rev-parse copy)" &&
287
+ test file3 = " $(git show HEAD:file3.t)"
177
288
'
178
289
179
290
test_expect_success ' pull.rebase=1 is treated as true and flattens keep-merge' '
180
291
git reset --hard before-preserve-rebase &&
181
292
test_config pull.rebase 1 &&
182
293
git pull . copy &&
183
- test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
184
- test file3 = $(git show HEAD:file3.t)
294
+ test " $(git rev-parse HEAD^^)" = " $(git rev-parse copy)" &&
295
+ test file3 = " $(git show HEAD:file3.t)"
185
296
'
186
297
187
298
test_expect_success ' pull.rebase=preserve rebases and merges keep-merge' '
188
299
git reset --hard before-preserve-rebase &&
189
300
test_config pull.rebase preserve &&
190
301
git pull . copy &&
191
- test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
192
- test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
302
+ test " $(git rev-parse HEAD^^)" = " $(git rev-parse copy)" &&
303
+ test " $(git rev-parse HEAD^2)" = " $(git rev-parse keep-merge)"
193
304
'
194
305
195
306
test_expect_success ' pull.rebase=invalid fails' '
@@ -202,25 +313,25 @@ test_expect_success '--rebase=false create a new merge commit' '
202
313
git reset --hard before-preserve-rebase &&
203
314
test_config pull.rebase true &&
204
315
git pull --rebase=false . copy &&
205
- test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
206
- test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
207
- test file3 = $(git show HEAD:file3.t)
316
+ test " $(git rev-parse HEAD^1)" = " $(git rev-parse before-preserve-rebase)" &&
317
+ test " $(git rev-parse HEAD^2)" = " $(git rev-parse copy)" &&
318
+ test file3 = " $(git show HEAD:file3.t)"
208
319
'
209
320
210
321
test_expect_success ' --rebase=true rebases and flattens keep-merge' '
211
322
git reset --hard before-preserve-rebase &&
212
323
test_config pull.rebase preserve &&
213
324
git pull --rebase=true . copy &&
214
- test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
215
- test file3 = $(git show HEAD:file3.t)
325
+ test " $(git rev-parse HEAD^^)" = " $(git rev-parse copy)" &&
326
+ test file3 = " $(git show HEAD:file3.t)"
216
327
'
217
328
218
329
test_expect_success ' --rebase=preserve rebases and merges keep-merge' '
219
330
git reset --hard before-preserve-rebase &&
220
331
test_config pull.rebase true &&
221
332
git pull --rebase=preserve . copy &&
222
- test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
223
- test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
333
+ test " $(git rev-parse HEAD^^)" = " $(git rev-parse copy)" &&
334
+ test " $(git rev-parse HEAD^2)" = " $(git rev-parse keep-merge)"
224
335
'
225
336
226
337
test_expect_success ' --rebase=invalid fails' '
@@ -232,8 +343,8 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
232
343
git reset --hard before-preserve-rebase &&
233
344
test_config pull.rebase preserve &&
234
345
git pull --rebase . copy &&
235
- test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
236
- test file3 = $(git show HEAD:file3.t)
346
+ test " $(git rev-parse HEAD^^)" = " $(git rev-parse copy)" &&
347
+ test file3 = " $(git show HEAD:file3.t)"
237
348
'
238
349
239
350
test_expect_success ' --rebase with rebased upstream' '
@@ -250,7 +361,7 @@ test_expect_success '--rebase with rebased upstream' '
250
361
git tag to-rebase-orig &&
251
362
git pull --rebase me copy &&
252
363
test "conflicting modification" = "$(cat file)" &&
253
- test file = $(cat file2)
364
+ test file = " $(cat file2)"
254
365
255
366
'
256
367
@@ -261,7 +372,7 @@ test_expect_success '--rebase with rebased default upstream' '
261
372
git reset --hard to-rebase-orig &&
262
373
git pull --rebase &&
263
374
test "conflicting modification" = "$(cat file)" &&
264
- test file = $(cat file2)
375
+ test file = " $(cat file2)"
265
376
266
377
'
267
378
@@ -282,18 +393,18 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
282
393
283
394
git checkout to-rebase &&
284
395
git update-ref refs/remotes/me/copy copy^ &&
285
- COPY=$(git rev-parse --verify me/copy) &&
396
+ COPY=" $(git rev-parse --verify me/copy)" &&
286
397
git rebase --onto $COPY copy &&
287
398
test_config branch.to-rebase.remote me &&
288
399
test_config branch.to-rebase.merge refs/heads/copy &&
289
400
test_config branch.to-rebase.rebase true &&
290
401
echo dirty >> file &&
291
402
git add file &&
292
403
test_must_fail git pull &&
293
- test $COPY = $(git rev-parse --verify me/copy) &&
404
+ test " $COPY" = " $(git rev-parse --verify me/copy)" &&
294
405
git checkout HEAD -- file &&
295
406
git pull &&
296
- test $COPY != $(git rev-parse --verify me/copy)
407
+ test " $COPY" != " $(git rev-parse --verify me/copy)"
297
408
298
409
'
299
410
@@ -308,6 +419,21 @@ test_expect_success 'pull --rebase works on branch yet to be born' '
308
419
test_cmp expect actual
309
420
'
310
421
422
+ test_expect_success ' pull --rebase fails on unborn branch with staged changes' '
423
+ test_when_finished "rm -rf empty_repo2" &&
424
+ git init empty_repo2 &&
425
+ (
426
+ cd empty_repo2 &&
427
+ echo staged-file >staged-file &&
428
+ git add staged-file &&
429
+ test "$(git ls-files)" = staged-file &&
430
+ test_must_fail git pull --rebase .. master 2>err &&
431
+ test "$(git ls-files)" = staged-file &&
432
+ test "$(git show :staged-file)" = staged-file &&
433
+ test_i18ngrep "unborn branch with changes added to the index" err
434
+ )
435
+ '
436
+
311
437
test_expect_success ' setup for detecting upstreamed changes' '
312
438
mkdir src &&
313
439
(cd src &&
0 commit comments