@@ -86,16 +86,19 @@ test_expect_success 'pulling into void must not create an octopus' '
8686'
8787
8888test_expect_success ' test . as a remote' '
89-
9089 git branch copy master &&
9190 git config branch.copy.remote . &&
9291 git config branch.copy.merge refs/heads/master &&
9392 echo updated >file &&
9493 git commit -a -m updated &&
9594 git checkout copy &&
96- test ` cat file` = file &&
95+ test "$( cat file)" = file &&
9796 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
99102'
100103
101104test_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' '
104107 git commit -a -m modified &&
105108 git checkout copy &&
106109 git reset --hard HEAD^ &&
107- test ` cat file` = file &&
110+ test "$( cat file)" = file &&
108111 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)"
110212'
111213
112214test_expect_success ' --rebase' '
@@ -119,32 +221,41 @@ test_expect_success '--rebase' '
119221 git commit -m "new file" &&
120222 git tag before-rebase &&
121223 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)"
124234'
235+
125236test_expect_success ' pull.rebase' '
126237 git reset --hard before-rebase &&
127238 test_config pull.rebase true &&
128239 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)"
131242'
132243
133244test_expect_success ' branch.to-rebase.rebase' '
134245 git reset --hard before-rebase &&
135246 test_config branch.to-rebase.rebase true &&
136247 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)"
139250'
140251
141252test_expect_success ' branch.to-rebase.rebase should override pull.rebase' '
142253 git reset --hard before-rebase &&
143254 test_config pull.rebase true &&
144255 test_config branch.to-rebase.rebase false &&
145256 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)"
148259'
149260
150261# 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' '
163274 git reset --hard before-preserve-rebase &&
164275 test_config pull.rebase false &&
165276 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)"
169280'
170281
171282test_expect_success ' pull.rebase=true flattens keep-merge' '
172283 git reset --hard before-preserve-rebase &&
173284 test_config pull.rebase true &&
174285 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)"
177288'
178289
179290test_expect_success ' pull.rebase=1 is treated as true and flattens keep-merge' '
180291 git reset --hard before-preserve-rebase &&
181292 test_config pull.rebase 1 &&
182293 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)"
185296'
186297
187298test_expect_success ' pull.rebase=preserve rebases and merges keep-merge' '
188299 git reset --hard before-preserve-rebase &&
189300 test_config pull.rebase preserve &&
190301 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)"
193304'
194305
195306test_expect_success ' pull.rebase=invalid fails' '
@@ -202,25 +313,25 @@ test_expect_success '--rebase=false create a new merge commit' '
202313 git reset --hard before-preserve-rebase &&
203314 test_config pull.rebase true &&
204315 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)"
208319'
209320
210321test_expect_success ' --rebase=true rebases and flattens keep-merge' '
211322 git reset --hard before-preserve-rebase &&
212323 test_config pull.rebase preserve &&
213324 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)"
216327'
217328
218329test_expect_success ' --rebase=preserve rebases and merges keep-merge' '
219330 git reset --hard before-preserve-rebase &&
220331 test_config pull.rebase true &&
221332 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)"
224335'
225336
226337test_expect_success ' --rebase=invalid fails' '
@@ -232,8 +343,8 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
232343 git reset --hard before-preserve-rebase &&
233344 test_config pull.rebase preserve &&
234345 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)"
237348'
238349
239350test_expect_success ' --rebase with rebased upstream' '
@@ -250,7 +361,7 @@ test_expect_success '--rebase with rebased upstream' '
250361 git tag to-rebase-orig &&
251362 git pull --rebase me copy &&
252363 test "conflicting modification" = "$(cat file)" &&
253- test file = $(cat file2)
364+ test file = " $(cat file2)"
254365
255366'
256367
@@ -261,7 +372,7 @@ test_expect_success '--rebase with rebased default upstream' '
261372 git reset --hard to-rebase-orig &&
262373 git pull --rebase &&
263374 test "conflicting modification" = "$(cat file)" &&
264- test file = $(cat file2)
375+ test file = " $(cat file2)"
265376
266377'
267378
@@ -282,18 +393,18 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
282393
283394 git checkout to-rebase &&
284395 git update-ref refs/remotes/me/copy copy^ &&
285- COPY=$(git rev-parse --verify me/copy) &&
396+ COPY=" $(git rev-parse --verify me/copy)" &&
286397 git rebase --onto $COPY copy &&
287398 test_config branch.to-rebase.remote me &&
288399 test_config branch.to-rebase.merge refs/heads/copy &&
289400 test_config branch.to-rebase.rebase true &&
290401 echo dirty >> file &&
291402 git add file &&
292403 test_must_fail git pull &&
293- test $COPY = $(git rev-parse --verify me/copy) &&
404+ test " $COPY" = " $(git rev-parse --verify me/copy)" &&
294405 git checkout HEAD -- file &&
295406 git pull &&
296- test $COPY != $(git rev-parse --verify me/copy)
407+ test " $COPY" != " $(git rev-parse --verify me/copy)"
297408
298409'
299410
@@ -308,6 +419,21 @@ test_expect_success 'pull --rebase works on branch yet to be born' '
308419 test_cmp expect actual
309420'
310421
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+
311437test_expect_success ' setup for detecting upstreamed changes' '
312438 mkdir src &&
313439 (cd src &&
0 commit comments