Merge branch 'rl/am-3way-config'
[gitweb.git] / t / t5520-pull.sh
index 4a2c0a1f269f12e78bd6b47fb7d21a406d638f97..f4a7193677a4861440d79e761f02315c790e275f 100755 (executable)
@@ -86,7 +86,6 @@ test_expect_success 'pulling into void must not create an octopus' '
 '
 
 test_expect_success 'test . as a remote' '
-
        git branch copy master &&
        git config branch.copy.remote . &&
        git config branch.copy.merge refs/heads/master &&
@@ -95,7 +94,11 @@ test_expect_success 'test . as a remote' '
        git checkout copy &&
        test "$(cat file)" = file &&
        git pull &&
-       test "$(cat file)" = updated
+       test "$(cat file)" = updated &&
+       git reflog -1 >reflog.actual &&
+       sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
+       echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
+       test_cmp reflog.expected reflog.fuzzy
 '
 
 test_expect_success 'the default remote . should not break explicit pull' '
@@ -106,7 +109,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
        git reset --hard HEAD^ &&
        test "$(cat file)" = file &&
        git pull . second &&
-       test "$(cat file)" = modified
+       test "$(cat file)" = modified &&
+       git reflog -1 >reflog.actual &&
+       sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
+       echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
+       test_cmp reflog.expected reflog.fuzzy
 '
 
 test_expect_success 'fail if wildcard spec does not match any refs' '
@@ -153,6 +160,18 @@ test_expect_success 'fail if no configuration for current branch' '
        test "$(cat file)" = file
 '
 
+test_expect_success 'pull --all: fail if no configuration for current branch' '
+       git remote add test_remote . &&
+       test_when_finished "git remote remove test_remote" &&
+       git checkout -b test copy^ &&
+       test_when_finished "git checkout -f copy && git branch -D test" &&
+       test_config branch.test.remote test_remote &&
+       test "$(cat file)" = file &&
+       test_must_fail git pull --all 2>err &&
+       test_i18ngrep "There is no tracking information" err &&
+       test "$(cat file)" = file
+'
+
 test_expect_success 'fail if upstream branch does not exist' '
        git checkout -b test copy^ &&
        test_when_finished "git checkout -f copy && git branch -D test" &&
@@ -164,6 +183,46 @@ test_expect_success 'fail if upstream branch does not exist' '
        test "$(cat file)" = file
 '
 
+test_expect_success 'fail if the index has unresolved entries' '
+       git checkout -b third second^ &&
+       test_when_finished "git checkout -f copy && git branch -D third" &&
+       test "$(cat file)" = file &&
+       test_commit modified2 file &&
+       test -z "$(git ls-files -u)" &&
+       test_must_fail git pull . second &&
+       test -n "$(git ls-files -u)" &&
+       cp file expected &&
+       test_must_fail git pull . second 2>err &&
+       test_i18ngrep "Pull is not possible because you have unmerged files" err &&
+       test_cmp expected file &&
+       git add file &&
+       test -z "$(git ls-files -u)" &&
+       test_must_fail git pull . second 2>err &&
+       test_i18ngrep "You have not concluded your merge" err &&
+       test_cmp expected file
+'
+
+test_expect_success 'fast-forwards working tree if branch head is updated' '
+       git checkout -b third second^ &&
+       test_when_finished "git checkout -f copy && git branch -D third" &&
+       test "$(cat file)" = file &&
+       git pull . second:third 2>err &&
+       test_i18ngrep "fetch updated the current branch head" err &&
+       test "$(cat file)" = modified &&
+       test "$(git rev-parse third)" = "$(git rev-parse second)"
+'
+
+test_expect_success 'fast-forward fails with conflicting work tree' '
+       git checkout -b third second^ &&
+       test_when_finished "git checkout -f copy && git branch -D third" &&
+       test "$(cat file)" = file &&
+       echo conflict >file &&
+       test_must_fail git pull . second:third 2>err &&
+       test_i18ngrep "Cannot fast-forward your working tree" err &&
+       test "$(cat file)" = conflict &&
+       test "$(git rev-parse third)" = "$(git rev-parse second)"
+'
+
 test_expect_success '--rebase' '
        git branch to-rebase &&
        echo modified again > file &&
@@ -177,6 +236,15 @@ test_expect_success '--rebase' '
        test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
        test new = "$(git show HEAD:file2)"
 '
+
+test_expect_success '--rebase fails with multiple branches' '
+       git reset --hard before-rebase &&
+       test_must_fail git pull --rebase . copy master 2>err &&
+       test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" &&
+       test_i18ngrep "Cannot rebase onto multiple branches" err &&
+       test modified = "$(git show HEAD:file)"
+'
+
 test_expect_success 'pull.rebase' '
        git reset --hard before-rebase &&
        test_config pull.rebase true &&
@@ -309,6 +377,14 @@ test_expect_success '--rebase with rebased upstream' '
 
 '
 
+test_expect_success '--rebase -f with rebased upstream' '
+       test_when_finished "test_might_fail git rebase --abort" &&
+       git reset --hard to-rebase-orig &&
+       git pull --rebase -f me copy &&
+       test "conflicting modification" = "$(cat file)" &&
+       test file = "$(cat file2)"
+'
+
 test_expect_success '--rebase with rebased default upstream' '
 
        git update-ref refs/remotes/me/copy copy-orig &&
@@ -363,6 +439,21 @@ test_expect_success 'pull --rebase works on branch yet to be born' '
        test_cmp expect actual
 '
 
+test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
+       test_when_finished "rm -rf empty_repo2" &&
+       git init empty_repo2 &&
+       (
+               cd empty_repo2 &&
+               echo staged-file >staged-file &&
+               git add staged-file &&
+               test "$(git ls-files)" = staged-file &&
+               test_must_fail git pull --rebase .. master 2>err &&
+               test "$(git ls-files)" = staged-file &&
+               test "$(git show :staged-file)" = staged-file &&
+               test_i18ngrep "unborn branch with changes added to the index" err
+       )
+'
+
 test_expect_success 'setup for detecting upstreamed changes' '
        mkdir src &&
        (cd src &&