1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-31 22:37:54 +01:00

Merge branch 'pt/pull-tests' into pt/pull-optparse

* pt/pull-tests:
  t5520: check reflog action in fast-forward merge
  t5521: test --dry-run does not make any changes
  t5520: test --rebase failure on unborn branch with index
  t5520: test --rebase with multiple branches
  t5520: test work tree fast-forward when fetch updates head
  t5520: test for failure if index has unresolved entries
  t5520: test no merge candidates cases
  t5520: prevent field splitting in content comparisons
This commit is contained in:
Junio C Hamano 2015-06-02 13:35:52 -07:00
commit 2c9c1c5178
2 changed files with 175 additions and 36 deletions

View file

@ -86,16 +86,19 @@ 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 &&
echo updated >file &&
git commit -a -m updated &&
git checkout copy &&
test `cat file` = file &&
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' '
@ -104,9 +107,108 @@ test_expect_success 'the default remote . should not break explicit pull' '
git commit -a -m modified &&
git checkout copy &&
git reset --hard HEAD^ &&
test `cat file` = file &&
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' '
git checkout -b test copy^ &&
test_when_finished "git checkout -f copy && git branch -D test" &&
test "$(cat file)" = file &&
test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
test_i18ngrep "no candidates for merging" err &&
test "$(cat file)" = file
'
test_expect_success 'fail if no branches specified with non-default remote' '
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 "$(cat file)" = file &&
test_config branch.test.remote origin &&
test_must_fail git pull test_remote 2>err &&
test_i18ngrep "specify a branch on the command line" err &&
test "$(cat file)" = file
'
test_expect_success 'fail if not on a branch' '
git remote add origin . &&
test_when_finished "git remote remove origin" &&
git checkout HEAD^ &&
test_when_finished "git checkout -f copy" &&
test "$(cat file)" = file &&
test_must_fail git pull 2>err &&
test_i18ngrep "not currently on a branch" err &&
test "$(cat file)" = file
'
test_expect_success '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 2>err &&
test_i18ngrep "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" &&
test_config branch.test.remote . &&
test_config branch.test.merge refs/heads/nonexisting &&
test "$(cat file)" = file &&
test_must_fail git pull 2>err &&
test_i18ngrep "no such ref was fetched" err &&
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' '
@ -119,23 +221,32 @@ test_expect_success '--rebase' '
git commit -m "new file" &&
git tag before-rebase &&
git pull --rebase . copy &&
test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
test new = $(git show HEAD:file2)
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 &&
git pull . copy &&
test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
test new = $(git show HEAD:file2)
test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
test new = "$(git show HEAD:file2)"
'
test_expect_success 'branch.to-rebase.rebase' '
git reset --hard before-rebase &&
test_config branch.to-rebase.rebase true &&
git pull . copy &&
test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
test new = $(git show HEAD:file2)
test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" &&
test new = "$(git show HEAD:file2)"
'
test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
@ -143,8 +254,8 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
test_config pull.rebase true &&
test_config branch.to-rebase.rebase false &&
git pull . copy &&
test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
test new = $(git show HEAD:file2)
test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" &&
test new = "$(git show HEAD:file2)"
'
# 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' '
git reset --hard before-preserve-rebase &&
test_config pull.rebase false &&
git pull . copy &&
test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
test file3 = $(git show HEAD:file3.t)
test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
test file3 = "$(git show HEAD:file3.t)"
'
test_expect_success 'pull.rebase=true flattens keep-merge' '
git reset --hard before-preserve-rebase &&
test_config pull.rebase true &&
git pull . copy &&
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
test file3 = $(git show HEAD:file3.t)
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
test file3 = "$(git show HEAD:file3.t)"
'
test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
git reset --hard before-preserve-rebase &&
test_config pull.rebase 1 &&
git pull . copy &&
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
test file3 = $(git show HEAD:file3.t)
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
test file3 = "$(git show HEAD:file3.t)"
'
test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
git reset --hard before-preserve-rebase &&
test_config pull.rebase preserve &&
git pull . copy &&
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
'
test_expect_success 'pull.rebase=invalid fails' '
@ -202,25 +313,25 @@ test_expect_success '--rebase=false create a new merge commit' '
git reset --hard before-preserve-rebase &&
test_config pull.rebase true &&
git pull --rebase=false . copy &&
test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) &&
test $(git rev-parse HEAD^2) = $(git rev-parse copy) &&
test file3 = $(git show HEAD:file3.t)
test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" &&
test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" &&
test file3 = "$(git show HEAD:file3.t)"
'
test_expect_success '--rebase=true rebases and flattens keep-merge' '
git reset --hard before-preserve-rebase &&
test_config pull.rebase preserve &&
git pull --rebase=true . copy &&
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
test file3 = $(git show HEAD:file3.t)
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
test file3 = "$(git show HEAD:file3.t)"
'
test_expect_success '--rebase=preserve rebases and merges keep-merge' '
git reset --hard before-preserve-rebase &&
test_config pull.rebase true &&
git pull --rebase=preserve . copy &&
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge)
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
'
test_expect_success '--rebase=invalid fails' '
@ -232,8 +343,8 @@ test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-m
git reset --hard before-preserve-rebase &&
test_config pull.rebase preserve &&
git pull --rebase . copy &&
test $(git rev-parse HEAD^^) = $(git rev-parse copy) &&
test file3 = $(git show HEAD:file3.t)
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" &&
test file3 = "$(git show HEAD:file3.t)"
'
test_expect_success '--rebase with rebased upstream' '
@ -250,7 +361,7 @@ test_expect_success '--rebase with rebased upstream' '
git tag to-rebase-orig &&
git pull --rebase me copy &&
test "conflicting modification" = "$(cat file)" &&
test file = $(cat file2)
test file = "$(cat file2)"
'
@ -261,7 +372,7 @@ test_expect_success '--rebase with rebased default upstream' '
git reset --hard to-rebase-orig &&
git pull --rebase &&
test "conflicting modification" = "$(cat file)" &&
test file = $(cat file2)
test file = "$(cat file2)"
'
@ -282,7 +393,7 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
git checkout to-rebase &&
git update-ref refs/remotes/me/copy copy^ &&
COPY=$(git rev-parse --verify me/copy) &&
COPY="$(git rev-parse --verify me/copy)" &&
git rebase --onto $COPY copy &&
test_config branch.to-rebase.remote me &&
test_config branch.to-rebase.merge refs/heads/copy &&
@ -290,10 +401,10 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
echo dirty >> file &&
git add file &&
test_must_fail git pull &&
test $COPY = $(git rev-parse --verify me/copy) &&
test "$COPY" = "$(git rev-parse --verify me/copy)" &&
git checkout HEAD -- file &&
git pull &&
test $COPY != $(git rev-parse --verify me/copy)
test "$COPY" != "$(git rev-parse --verify me/copy)"
'
@ -308,6 +419,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 &&

View file

@ -117,4 +117,17 @@ test_expect_success 'git pull --all' '
)
'
test_expect_success 'git pull --dry-run' '
test_when_finished "rm -rf clonedry" &&
git init clonedry &&
(
cd clonedry &&
git pull --dry-run ../parent &&
test_path_is_missing .git/FETCH_HEAD &&
test_path_is_missing .git/refs/heads/master &&
test_path_is_missing .git/index &&
test_path_is_missing file
)
'
test_done