git/t/t5520-pull.sh

263 lines
6.3 KiB
Bash
Raw Normal View History

#!/bin/sh
test_description='pulling into void'
. ./test-lib.sh
modify () {
sed -e "$1" <"$2" >"$2.x" &&
mv "$2.x" "$2"
}
D=`pwd`
test_expect_success setup '
echo file >file &&
git add file &&
git commit -a -m original
'
test_expect_success 'pulling into void' '
mkdir cloned &&
cd cloned &&
git init &&
git pull ..
'
cd "$D"
test_expect_success 'checking the results' '
test -f file &&
test -f cloned/file &&
test_cmp file cloned/file
'
test_expect_success 'pulling into void using master:master' '
mkdir cloned-uho &&
(
cd cloned-uho &&
git init &&
git pull .. master:master
) &&
test -f file &&
test -f cloned-uho/file &&
test_cmp file cloned-uho/file
'
test_expect_success 'pulling into void does not overwrite untracked files' '
git init cloned-untracked &&
(
cd cloned-untracked &&
echo untracked >file &&
test_must_fail git pull .. master &&
echo untracked >expect &&
test_cmp expect file
)
'
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 &&
git pull &&
test `cat file` = updated
'
test_expect_success 'the default remote . should not break explicit pull' '
git checkout -b second master^ &&
echo modified >file &&
git commit -a -m modified &&
git checkout copy &&
git reset --hard HEAD^ &&
test `cat file` = file &&
git pull . second &&
test `cat file` = modified
'
test_expect_success '--rebase' '
git branch to-rebase &&
echo modified again > file &&
git commit -m file file &&
git checkout to-rebase &&
echo new > file2 &&
git add file2 &&
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_expect_success 'pull.rebase' '
git reset --hard before-rebase &&
git config --bool pull.rebase true &&
test_when_finished "git config --unset pull.rebase" &&
git pull . copy &&
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 &&
git config --bool branch.to-rebase.rebase true &&
test_when_finished "git config --unset branch.to-rebase.rebase" &&
git pull . copy &&
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' '
git reset --hard before-rebase &&
git config --bool pull.rebase true &&
test_when_finished "git config --unset pull.rebase" &&
git config --bool branch.to-rebase.rebase false &&
test_when_finished "git config --unset branch.to-rebase.rebase" &&
git pull . copy &&
test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
test new = $(git show HEAD:file2)
'
test_expect_success '--rebase with rebased upstream' '
git remote add -f me . &&
git checkout copy &&
git tag copy-orig &&
git reset --hard HEAD^ &&
echo conflicting modification > file &&
git commit -m conflict file &&
git checkout to-rebase &&
echo file > file2 &&
git commit -m to-rebase file2 &&
git tag to-rebase-orig &&
git pull --rebase 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 &&
git checkout --track -b to-rebase2 me/copy &&
git reset --hard to-rebase-orig &&
git pull --rebase &&
test "conflicting modification" = "$(cat file)" &&
test file = $(cat file2)
'
test_expect_success 'rebased upstream + fetch + pull --rebase' '
git update-ref refs/remotes/me/copy copy-orig &&
git reset --hard to-rebase-orig &&
git checkout --track -b to-rebase3 me/copy &&
git reset --hard to-rebase-orig &&
git fetch &&
git pull --rebase &&
test "conflicting modification" = "$(cat file)" &&
test file = "$(cat file2)"
'
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) &&
git rebase --onto $COPY copy &&
git config branch.to-rebase.remote me &&
git config branch.to-rebase.merge refs/heads/copy &&
git config branch.to-rebase.rebase true &&
echo dirty >> file &&
git add file &&
test_must_fail git pull &&
test $COPY = $(git rev-parse --verify me/copy) &&
git checkout HEAD -- file &&
git pull &&
test $COPY != $(git rev-parse --verify me/copy)
'
test_expect_success 'pull --rebase works on branch yet to be born' '
git rev-parse master >expect &&
mkdir empty_repo &&
(cd empty_repo &&
git init &&
git pull --rebase .. master &&
git rev-parse HEAD >../actual
) &&
test_cmp expect actual
'
test_expect_success 'setup for detecting upstreamed changes' '
mkdir src &&
(cd src &&
git init &&
printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
git add stuff &&
git commit -m "Initial revision"
) &&
git clone src dst &&
(cd src &&
modify s/5/43/ stuff &&
git commit -a -m "5->43" &&
modify s/6/42/ stuff &&
git commit -a -m "Make it bigger"
) &&
(cd dst &&
modify s/5/43/ stuff &&
git commit -a -m "Independent discovery of 5->43"
)
'
pull --rebase: Avoid spurious conflicts and reapplying unnecessary patches Prior to c85c792 (pull --rebase: be cleverer with rebased upstream branches, 2008-01-26), pull --rebase would run git rebase $merge_head which resulted in a call to git format-patch ... --ignore-if-in-upstream $merge_head..$cur_branch This resulted in patches from $merge_head..$cur_branch being applied, as long as they did not already exist in $cur_branch..$merge_head. Unfortunately, when upstream is rebased, $merge_head..$cur_branch also refers to "old" commits that have already been rebased upstream, meaning that many patches that were already fixed upstream would be reapplied. This could result in many spurious conflicts, as well as reintroduce patches that were intentionally dropped upstream. So the algorithm was changed in c85c792 (pull --rebase: be cleverer with rebased upstream branches, 2008-01-26) and d44e712 (pull: support rebased upstream + fetch + pull --rebase, 2009-07-19). Defining $old_remote_ref to be the most recent entry in the reflog for @{upstream} that is an ancestor of $cur_branch, pull --rebase was changed to run git rebase --onto $merge_head $old_remote_ref which results in a call to git format-patch ... --ignore-if-in-upstream $old_remote_ref..$cur_branch The whole point of this change was to reduce the number of commits being reapplied, by avoiding commits that upstream already has or had. In the rebased upstream case, this change achieved that purpose. It is worth noting, though, that since $old_remote_ref is always an ancestor of $cur_branch (by its definition), format-patch will not know what upstream is and thus will not be able to determine if any patches are already upstream; they will all be reapplied. In the non-rebased upstream case, this new form is usually the same as the original code but in some cases $old_remote_ref can be an ancestor of $(git merge-base $merge_head $cur_branch) meaning that instead of avoiding reapplying commits that upstream already has, it actually includes more such commits. Combined with the fact that format-patch can no longer detect commits that are already upstream (since it is no longer told what upstream is), results in lots of confusion for users (e.g. "git is giving me lots of conflicts in stuff I didn't even change since my last push.") Cases where additional commits could be reapplied include forking from a commit other than the tracking branch, or amending/rebasing after pushing. Cases where the inability to detect upstreamed commits cause problems include independent discovery of a fix and having your patches get upstreamed by some alternative route (e.g. pulling your changes to a third machine, pushing from there, and then going back to your original machine and trying to pull --rebase). Fix the non-rebased upstream case by ignoring $old_remote_ref whenever it is contained in $(git merge-base $merge_head $cur_branch). This should have no affect on the rebased upstream case. Acked-by: Santi Béjar <santi@agolina.net> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-13 01:50:50 +00:00
test_expect_success 'git pull --rebase detects upstreamed changes' '
(cd dst &&
git pull --rebase &&
test -z "$(git ls-files -u)"
)
'
test_expect_success 'setup for avoiding reapplying old patches' '
(cd dst &&
test_might_fail git rebase --abort &&
git reset --hard origin/master
) &&
git clone --bare src src-replace.git &&
rm -rf src &&
mv src-replace.git src &&
(cd dst &&
modify s/2/22/ stuff &&
git commit -a -m "Change 2" &&
modify s/3/33/ stuff &&
git commit -a -m "Change 3" &&
modify s/4/44/ stuff &&
git commit -a -m "Change 4" &&
git push &&
modify s/44/55/ stuff &&
git commit --amend -a -m "Modified Change 4"
)
'
pull --rebase: Avoid spurious conflicts and reapplying unnecessary patches Prior to c85c792 (pull --rebase: be cleverer with rebased upstream branches, 2008-01-26), pull --rebase would run git rebase $merge_head which resulted in a call to git format-patch ... --ignore-if-in-upstream $merge_head..$cur_branch This resulted in patches from $merge_head..$cur_branch being applied, as long as they did not already exist in $cur_branch..$merge_head. Unfortunately, when upstream is rebased, $merge_head..$cur_branch also refers to "old" commits that have already been rebased upstream, meaning that many patches that were already fixed upstream would be reapplied. This could result in many spurious conflicts, as well as reintroduce patches that were intentionally dropped upstream. So the algorithm was changed in c85c792 (pull --rebase: be cleverer with rebased upstream branches, 2008-01-26) and d44e712 (pull: support rebased upstream + fetch + pull --rebase, 2009-07-19). Defining $old_remote_ref to be the most recent entry in the reflog for @{upstream} that is an ancestor of $cur_branch, pull --rebase was changed to run git rebase --onto $merge_head $old_remote_ref which results in a call to git format-patch ... --ignore-if-in-upstream $old_remote_ref..$cur_branch The whole point of this change was to reduce the number of commits being reapplied, by avoiding commits that upstream already has or had. In the rebased upstream case, this change achieved that purpose. It is worth noting, though, that since $old_remote_ref is always an ancestor of $cur_branch (by its definition), format-patch will not know what upstream is and thus will not be able to determine if any patches are already upstream; they will all be reapplied. In the non-rebased upstream case, this new form is usually the same as the original code but in some cases $old_remote_ref can be an ancestor of $(git merge-base $merge_head $cur_branch) meaning that instead of avoiding reapplying commits that upstream already has, it actually includes more such commits. Combined with the fact that format-patch can no longer detect commits that are already upstream (since it is no longer told what upstream is), results in lots of confusion for users (e.g. "git is giving me lots of conflicts in stuff I didn't even change since my last push.") Cases where additional commits could be reapplied include forking from a commit other than the tracking branch, or amending/rebasing after pushing. Cases where the inability to detect upstreamed commits cause problems include independent discovery of a fix and having your patches get upstreamed by some alternative route (e.g. pulling your changes to a third machine, pushing from there, and then going back to your original machine and trying to pull --rebase). Fix the non-rebased upstream case by ignoring $old_remote_ref whenever it is contained in $(git merge-base $merge_head $cur_branch). This should have no affect on the rebased upstream case. Acked-by: Santi Béjar <santi@agolina.net> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-13 01:50:50 +00:00
test_expect_success 'git pull --rebase does not reapply old patches' '
(cd dst &&
test_must_fail git pull --rebase &&
test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
)
'
test_expect_success 'git pull --rebase against local branch' '
git checkout -b copy2 to-rebase-orig &&
git pull --rebase . to-rebase &&
test "conflicting modification" = "$(cat file)" &&
test file = "$(cat file2)"
'
test_done