Merge branch 'dl/t5520-cleanup'

Test cleanup.

* dl/t5520-cleanup:
  t5520: replace `! git` with `test_must_fail git`
  t5520: remove redundant lines in test cases
  t5520: replace $(cat ...) comparison with test_cmp
  t5520: don't put git in upstream of pipe
  t5520: test single-line files by git with test_cmp
  t5520: use test_cmp_rev where possible
  t5520: replace test -{n,z} with test-lib functions
  t5520: use test_line_count where possible
  t5520: remove spaces after redirect operator
  t5520: replace test -f with test-lib functions
  t5520: let sed open its own input
  t5520: use sq for test case names
  t5520: improve test style
  t: teach test_cmp_rev to accept ! for not-equals
  t0000: test multiple local assignment
This commit is contained in:
Junio C Hamano
2019-12-05 12:52:47 -08:00
10 changed files with 237 additions and 158 deletions

View File

@ -20,9 +20,9 @@ modification *should* take notice and update the test vectors here.
. ./test-lib.sh . ./test-lib.sh
try_local_x () { try_local_xy () {
local x="local" && local x="local" y="alsolocal" &&
echo "$x" echo "$x $y"
} }
# Check whether the shell supports the "local" keyword. "local" is not # Check whether the shell supports the "local" keyword. "local" is not
@ -35,11 +35,12 @@ try_local_x () {
# relying on "local". # relying on "local".
test_expect_success 'verify that the running shell supports "local"' ' test_expect_success 'verify that the running shell supports "local"' '
x="notlocal" && x="notlocal" &&
echo "local" >expected1 && y="alsonotlocal" &&
try_local_x >actual1 && echo "local alsolocal" >expected1 &&
try_local_xy >actual1 &&
test_cmp expected1 actual1 && test_cmp expected1 actual1 &&
echo "notlocal" >expected2 && echo "notlocal alsonotlocal" >expected2 &&
echo "$x" >actual2 && echo "$x $y" >actual2 &&
test_cmp expected2 actual2 test_cmp expected2 actual2
' '

View File

@ -438,7 +438,7 @@ test_expect_success 'git worktree add does not match remote' '
cd foo && cd foo &&
test_must_fail git config "branch.foo.remote" && test_must_fail git config "branch.foo.remote" &&
test_must_fail git config "branch.foo.merge" && test_must_fail git config "branch.foo.merge" &&
! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
) )
' '
@ -483,7 +483,7 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' '
cd foo && cd foo &&
test_must_fail git config "branch.foo.remote" && test_must_fail git config "branch.foo.remote" &&
test_must_fail git config "branch.foo.merge" && test_must_fail git config "branch.foo.merge" &&
! test_cmp_rev refs/remotes/repo_a/foo refs/heads/foo test_cmp_rev ! refs/remotes/repo_a/foo refs/heads/foo
) )
' '

View File

@ -64,7 +64,7 @@ test_expect_success 'rebase sets ORIG_HEAD to pre-rebase state' '
pre="$(git rev-parse --verify HEAD)" && pre="$(git rev-parse --verify HEAD)" &&
git rebase master && git rebase master &&
test_cmp_rev "$pre" ORIG_HEAD && test_cmp_rev "$pre" ORIG_HEAD &&
! test_cmp_rev "$pre" HEAD test_cmp_rev ! "$pre" HEAD
' '
test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' ' test_expect_success 'rebase, with <onto> and <upstream> specified as :/quuxery' '

View File

@ -61,7 +61,7 @@ test_run_rebase () {
test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" " test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" "
reset_rebase && reset_rebase &&
git rebase $* -f b e && git rebase $* -f b e &&
! test_cmp_rev e HEAD && test_cmp_rev ! e HEAD &&
test_cmp_rev b HEAD~2 && test_cmp_rev b HEAD~2 &&
test_linear_range 'd e' b.. test_linear_range 'd e' b..
" "
@ -78,7 +78,7 @@ test_run_rebase () {
test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" " test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" "
reset_rebase && reset_rebase &&
git rebase $* -f branch-b branch-e && git rebase $* -f branch-b branch-e &&
! test_cmp_rev branch-e origin/branch-e && test_cmp_rev ! branch-e origin/branch-e &&
test_cmp_rev branch-b HEAD~2 && test_cmp_rev branch-b HEAD~2 &&
test_linear_range 'd e' branch-b.. test_linear_range 'd e' branch-b..
" "
@ -368,7 +368,7 @@ test_run_rebase () {
test_expect_$result "rebase $* -f --root on linear history causes re-write" " test_expect_$result "rebase $* -f --root on linear history causes re-write" "
reset_rebase && reset_rebase &&
git rebase $* -f --root c && git rebase $* -f --root c &&
! test_cmp_rev a HEAD~2 && test_cmp_rev ! a HEAD~2 &&
test_linear_range 'a b c' HEAD test_linear_range 'a b c' HEAD
" "
} }

View File

@ -346,7 +346,7 @@ test_expect_success 'A root commit can be a cousin, treat it that way' '
git merge --allow-unrelated-histories khnum && git merge --allow-unrelated-histories khnum &&
test_tick && test_tick &&
git rebase -f -r HEAD^ && git rebase -f -r HEAD^ &&
! test_cmp_rev HEAD^2 khnum && test_cmp_rev ! HEAD^2 khnum &&
test_cmp_graph HEAD^.. <<-\EOF && test_cmp_graph HEAD^.. <<-\EOF &&
* Merge branch '\''khnum'\'' into asherah * Merge branch '\''khnum'\'' into asherah
|\ |\

View File

@ -64,7 +64,7 @@ test_rebase_same_head_ () {
test_cmp_rev \$oldhead \$newhead test_cmp_rev \$oldhead \$newhead
elif test $cmp = diff elif test $cmp = diff
then then
! test_cmp_rev \$oldhead \$newhead test_cmp_rev ! \$oldhead \$newhead
fi fi
" "
} }

View File

@ -106,7 +106,7 @@ test_expect_success 'cherry-pick on unborn branch' '
rm -rf * && rm -rf * &&
git cherry-pick initial && git cherry-pick initial &&
git diff --quiet initial && git diff --quiet initial &&
! test_cmp_rev initial HEAD test_cmp_rev ! initial HEAD
' '
test_expect_success 'cherry-pick "-" to pick from previous branch' ' test_expect_success 'cherry-pick "-" to pick from previous branch' '

View File

@ -5,7 +5,7 @@ test_description='test cherry-picking many commits'
. ./test-lib.sh . ./test-lib.sh
check_head_differs_from() { check_head_differs_from() {
! test_cmp_rev HEAD "$1" test_cmp_rev ! HEAD "$1"
} }
check_head_equals() { check_head_equals() {

View File

@ -5,7 +5,7 @@ test_description='pulling into void'
. ./test-lib.sh . ./test-lib.sh
modify () { modify () {
sed -e "$1" <"$2" >"$2.x" && sed -e "$1" "$2" >"$2.x" &&
mv "$2.x" "$2" mv "$2.x" "$2"
} }
@ -15,8 +15,10 @@ test_pull_autostash () {
git add new_file && git add new_file &&
git pull "$@" . copy && git pull "$@" . copy &&
test_cmp_rev HEAD^ copy && test_cmp_rev HEAD^ copy &&
test "$(cat new_file)" = dirty && echo dirty >expect &&
test "$(cat file)" = "modified again" test_cmp expect new_file &&
echo "modified again" >expect &&
test_cmp expect file
} }
test_pull_autostash_fail () { test_pull_autostash_fail () {
@ -39,8 +41,8 @@ test_expect_success 'pulling into void' '
cd cloned && cd cloned &&
git pull .. git pull ..
) && ) &&
test -f file && test_path_is_file file &&
test -f cloned/file && test_path_is_file cloned/file &&
test_cmp file cloned/file test_cmp file cloned/file
' '
@ -50,8 +52,8 @@ test_expect_success 'pulling into void using master:master' '
cd cloned-uho && cd cloned-uho &&
git pull .. master:master git pull .. master:master
) && ) &&
test -f file && test_path_is_file file &&
test -f cloned-uho/file && test_path_is_file cloned-uho/file &&
test_cmp file cloned-uho/file test_cmp file cloned-uho/file
' '
@ -99,7 +101,7 @@ test_expect_success 'pulling into void must not create an octopus' '
( (
cd cloned-octopus && cd cloned-octopus &&
test_must_fail git pull .. master master && test_must_fail git pull .. master master &&
! test -f file test_path_is_missing file
) )
' '
@ -110,9 +112,11 @@ test_expect_success 'test . as a remote' '
echo updated >file && echo updated >file &&
git commit -a -m updated && git commit -a -m updated &&
git checkout copy && git checkout copy &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
git pull && git pull &&
test "$(cat file)" = updated && echo updated >expect &&
test_cmp expect file &&
git reflog -1 >reflog.actual && git reflog -1 >reflog.actual &&
sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected && echo "OBJID HEAD@{0}: pull: Fast-forward" >reflog.expected &&
@ -125,9 +129,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
git commit -a -m modified && git commit -a -m modified &&
git checkout copy && git checkout copy &&
git reset --hard HEAD^ && git reset --hard HEAD^ &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
git pull . second && git pull . second &&
test "$(cat file)" = modified && echo modified >expect &&
test_cmp expect file &&
git reflog -1 >reflog.actual && git reflog -1 >reflog.actual &&
sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy && sed "s/^[0-9a-f][0-9a-f]*/OBJID/" reflog.actual >reflog.fuzzy &&
echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected && echo "OBJID HEAD@{0}: pull . second: Fast-forward" >reflog.expected &&
@ -137,10 +143,11 @@ test_expect_success 'the default remote . should not break explicit pull' '
test_expect_success 'fail if wildcard spec does not match any refs' ' test_expect_success 'fail if wildcard spec does not match any refs' '
git checkout -b test copy^ && git checkout -b test copy^ &&
test_when_finished "git checkout -f copy && git branch -D test" && test_when_finished "git checkout -f copy && git branch -D test" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err && test_must_fail git pull . "refs/nonexisting1/*:refs/nonexisting2/*" 2>err &&
test_i18ngrep "no candidates for merging" err && test_i18ngrep "no candidates for merging" err &&
test "$(cat file)" = file test_cmp expect file
' '
test_expect_success 'fail if no branches specified with non-default remote' ' test_expect_success 'fail if no branches specified with non-default remote' '
@ -148,11 +155,12 @@ test_expect_success 'fail if no branches specified with non-default remote' '
test_when_finished "git remote remove test_remote" && test_when_finished "git remote remove test_remote" &&
git checkout -b test copy^ && git checkout -b test copy^ &&
test_when_finished "git checkout -f copy && git branch -D test" && test_when_finished "git checkout -f copy && git branch -D test" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_config branch.test.remote origin && test_config branch.test.remote origin &&
test_must_fail git pull test_remote 2>err && test_must_fail git pull test_remote 2>err &&
test_i18ngrep "specify a branch on the command line" err && test_i18ngrep "specify a branch on the command line" err &&
test "$(cat file)" = file test_cmp expect file
' '
test_expect_success 'fail if not on a branch' ' test_expect_success 'fail if not on a branch' '
@ -160,10 +168,11 @@ test_expect_success 'fail if not on a branch' '
test_when_finished "git remote remove origin" && test_when_finished "git remote remove origin" &&
git checkout HEAD^ && git checkout HEAD^ &&
test_when_finished "git checkout -f copy" && test_when_finished "git checkout -f copy" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_must_fail git pull 2>err && test_must_fail git pull 2>err &&
test_i18ngrep "not currently on a branch" err && test_i18ngrep "not currently on a branch" err &&
test "$(cat file)" = file test_cmp expect file
' '
test_expect_success 'fail if no configuration for current branch' ' test_expect_success 'fail if no configuration for current branch' '
@ -172,10 +181,11 @@ test_expect_success 'fail if no configuration for current branch' '
git checkout -b test copy^ && git checkout -b test copy^ &&
test_when_finished "git checkout -f copy && git branch -D test" && test_when_finished "git checkout -f copy && git branch -D test" &&
test_config branch.test.remote test_remote && test_config branch.test.remote test_remote &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_must_fail git pull 2>err && test_must_fail git pull 2>err &&
test_i18ngrep "no tracking information" err && test_i18ngrep "no tracking information" err &&
test "$(cat file)" = file test_cmp expect file
' '
test_expect_success 'pull --all: fail if no configuration for current branch' ' test_expect_success 'pull --all: fail if no configuration for current branch' '
@ -184,10 +194,11 @@ test_expect_success 'pull --all: fail if no configuration for current branch' '
git checkout -b test copy^ && git checkout -b test copy^ &&
test_when_finished "git checkout -f copy && git branch -D test" && test_when_finished "git checkout -f copy && git branch -D test" &&
test_config branch.test.remote test_remote && test_config branch.test.remote test_remote &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_must_fail git pull --all 2>err && test_must_fail git pull --all 2>err &&
test_i18ngrep "There is no tracking information" err && test_i18ngrep "There is no tracking information" err &&
test "$(cat file)" = file test_cmp expect file
' '
test_expect_success 'fail if upstream branch does not exist' ' test_expect_success 'fail if upstream branch does not exist' '
@ -195,26 +206,31 @@ test_expect_success 'fail if upstream branch does not exist' '
test_when_finished "git checkout -f copy && git branch -D test" && test_when_finished "git checkout -f copy && git branch -D test" &&
test_config branch.test.remote . && test_config branch.test.remote . &&
test_config branch.test.merge refs/heads/nonexisting && test_config branch.test.merge refs/heads/nonexisting &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_must_fail git pull 2>err && test_must_fail git pull 2>err &&
test_i18ngrep "no such ref was fetched" err && test_i18ngrep "no such ref was fetched" err &&
test "$(cat file)" = file test_cmp expect file
' '
test_expect_success 'fail if the index has unresolved entries' ' test_expect_success 'fail if the index has unresolved entries' '
git checkout -b third second^ && git checkout -b third second^ &&
test_when_finished "git checkout -f copy && git branch -D third" && test_when_finished "git checkout -f copy && git branch -D third" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
test_commit modified2 file && test_commit modified2 file &&
test -z "$(git ls-files -u)" && git ls-files -u >unmerged &&
test_must_be_empty unmerged &&
test_must_fail git pull . second && test_must_fail git pull . second &&
test -n "$(git ls-files -u)" && git ls-files -u >unmerged &&
test_file_not_empty unmerged &&
cp file expected && cp file expected &&
test_must_fail git pull . second 2>err && test_must_fail git pull . second 2>err &&
test_i18ngrep "Pulling is not possible because you have unmerged files." err && test_i18ngrep "Pulling is not possible because you have unmerged files." err &&
test_cmp expected file && test_cmp expected file &&
git add file && git add file &&
test -z "$(git ls-files -u)" && git ls-files -u >unmerged &&
test_must_be_empty unmerged &&
test_must_fail git pull . second 2>err && test_must_fail git pull . second 2>err &&
test_i18ngrep "You have not concluded your merge" err && test_i18ngrep "You have not concluded your merge" err &&
test_cmp expected file test_cmp expected file
@ -223,36 +239,42 @@ test_expect_success 'fail if the index has unresolved entries' '
test_expect_success 'fast-forwards working tree if branch head is updated' ' test_expect_success 'fast-forwards working tree if branch head is updated' '
git checkout -b third second^ && git checkout -b third second^ &&
test_when_finished "git checkout -f copy && git branch -D third" && test_when_finished "git checkout -f copy && git branch -D third" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
git pull . second:third 2>err && git pull . second:third 2>err &&
test_i18ngrep "fetch updated the current branch head" err && test_i18ngrep "fetch updated the current branch head" err &&
test "$(cat file)" = modified && echo modified >expect &&
test "$(git rev-parse third)" = "$(git rev-parse second)" test_cmp expect file &&
test_cmp_rev third second
' '
test_expect_success 'fast-forward fails with conflicting work tree' ' test_expect_success 'fast-forward fails with conflicting work tree' '
git checkout -b third second^ && git checkout -b third second^ &&
test_when_finished "git checkout -f copy && git branch -D third" && test_when_finished "git checkout -f copy && git branch -D third" &&
test "$(cat file)" = file && echo file >expect &&
test_cmp expect file &&
echo conflict >file && echo conflict >file &&
test_must_fail git pull . second:third 2>err && test_must_fail git pull . second:third 2>err &&
test_i18ngrep "Cannot fast-forward your working tree" err && test_i18ngrep "Cannot fast-forward your working tree" err &&
test "$(cat file)" = conflict && echo conflict >expect &&
test "$(git rev-parse third)" = "$(git rev-parse second)" test_cmp expect file &&
test_cmp_rev third second
' '
test_expect_success '--rebase' ' test_expect_success '--rebase' '
git branch to-rebase && git branch to-rebase &&
echo modified again > file && echo modified again >file &&
git commit -m file file && git commit -m file file &&
git checkout to-rebase && git checkout to-rebase &&
echo new > file2 && echo new >file2 &&
git add file2 && git add file2 &&
git commit -m "new file" && git commit -m "new file" &&
git tag before-rebase && git tag before-rebase &&
git pull --rebase . copy && git pull --rebase . copy &&
test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^ copy &&
test new = "$(git show HEAD:file2)" echo new >expect &&
git show HEAD:file2 >actual &&
test_cmp expect actual
' '
test_expect_success '--rebase fast forward' ' test_expect_success '--rebase fast forward' '
@ -263,7 +285,7 @@ test_expect_success '--rebase fast forward' '
git checkout to-rebase && git checkout to-rebase &&
git pull --rebase . ff && git pull --rebase . ff &&
test "$(git rev-parse HEAD)" = "$(git rev-parse ff)" && test_cmp_rev HEAD ff &&
# The above only validates the result. Did we actually bypass rebase? # The above only validates the result. Did we actually bypass rebase?
git reflog -1 >reflog.actual && git reflog -1 >reflog.actual &&
@ -287,7 +309,7 @@ test_expect_success '--rebase --autostash fast forward' '
git checkout behind && git checkout behind &&
echo dirty >file && echo dirty >file &&
git pull --rebase --autostash . to-rebase-ff && git pull --rebase --autostash . to-rebase-ff &&
test "$(git rev-parse HEAD)" = "$(git rev-parse to-rebase-ff)" test_cmp_rev HEAD to-rebase-ff
' '
test_expect_success '--rebase with conflicts shows advice' ' test_expect_success '--rebase with conflicts shows advice' '
@ -325,9 +347,11 @@ test_expect_success 'failed --rebase shows advice' '
test_expect_success '--rebase fails with multiple branches' ' test_expect_success '--rebase fails with multiple branches' '
git reset --hard before-rebase && git reset --hard before-rebase &&
test_must_fail git pull --rebase . copy master 2>err && test_must_fail git pull --rebase . copy master 2>err &&
test "$(git rev-parse HEAD)" = "$(git rev-parse before-rebase)" && test_cmp_rev HEAD before-rebase &&
test_i18ngrep "Cannot rebase onto multiple branches" err && test_i18ngrep "Cannot rebase onto multiple branches" err &&
test modified = "$(git show HEAD:file)" echo modified >expect &&
git show HEAD:file >actual &&
test_cmp expect actual
' '
test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' ' test_expect_success 'pull --rebase succeeds with dirty working directory and rebase.autostash set' '
@ -377,8 +401,10 @@ test_expect_success 'pull.rebase' '
git reset --hard before-rebase && git reset --hard before-rebase &&
test_config pull.rebase true && test_config pull.rebase true &&
git pull . copy && git pull . copy &&
test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^ copy &&
test new = "$(git show HEAD:file2)" echo new >expect &&
git show HEAD:file2 >actual &&
test_cmp expect actual
' '
test_expect_success 'pull --autostash & pull.rebase=true' ' test_expect_success 'pull --autostash & pull.rebase=true' '
@ -395,8 +421,10 @@ test_expect_success 'branch.to-rebase.rebase' '
git reset --hard before-rebase && git reset --hard before-rebase &&
test_config branch.to-rebase.rebase true && test_config branch.to-rebase.rebase true &&
git pull . copy && git pull . copy &&
test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^ copy &&
test new = "$(git show HEAD:file2)" echo new >expect &&
git show HEAD:file2 >actual &&
test_cmp expect actual
' '
test_expect_success 'branch.to-rebase.rebase should override pull.rebase' ' test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
@ -404,23 +432,29 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
test_config pull.rebase true && test_config pull.rebase true &&
test_config branch.to-rebase.rebase false && test_config branch.to-rebase.rebase false &&
git pull . copy && git pull . copy &&
test "$(git rev-parse HEAD^)" != "$(git rev-parse copy)" && test_cmp_rev ! HEAD^ copy &&
test new = "$(git show HEAD:file2)" echo new >expect &&
git show HEAD:file2 >actual &&
test_cmp expect actual
' '
test_expect_success "pull --rebase warns on --verify-signatures" ' test_expect_success 'pull --rebase warns on --verify-signatures' '
git reset --hard before-rebase && git reset --hard before-rebase &&
git pull --rebase --verify-signatures . copy 2>err && git pull --rebase --verify-signatures . copy 2>err &&
test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^ copy &&
test new = "$(git show HEAD:file2)" && echo new >expect &&
git show HEAD:file2 >actual &&
test_cmp expect actual &&
test_i18ngrep "ignoring --verify-signatures for rebase" err test_i18ngrep "ignoring --verify-signatures for rebase" err
' '
test_expect_success "pull --rebase does not warn on --no-verify-signatures" ' test_expect_success 'pull --rebase does not warn on --no-verify-signatures' '
git reset --hard before-rebase && git reset --hard before-rebase &&
git pull --rebase --no-verify-signatures . copy 2>err && git pull --rebase --no-verify-signatures . copy 2>err &&
test "$(git rev-parse HEAD^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^ copy &&
test new = "$(git show HEAD:file2)" && echo new >expect &&
git show HEAD:file2 >actual &&
test_cmp expect actual &&
test_i18ngrep ! "verify-signatures" err test_i18ngrep ! "verify-signatures" err
' '
@ -440,25 +474,31 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
git reset --hard before-preserve-rebase && git reset --hard before-preserve-rebase &&
test_config pull.rebase false && test_config pull.rebase false &&
git pull . copy && git pull . copy &&
test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" && test_cmp_rev HEAD^1 before-preserve-rebase &&
test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^2 copy &&
test file3 = "$(git show HEAD:file3.t)" echo file3 >expect &&
git show HEAD:file3.t >actual &&
test_cmp expect actual
' '
test_expect_success 'pull.rebase=true flattens keep-merge' ' test_expect_success 'pull.rebase=true flattens keep-merge' '
git reset --hard before-preserve-rebase && git reset --hard before-preserve-rebase &&
test_config pull.rebase true && test_config pull.rebase true &&
git pull . copy && git pull . copy &&
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^^ copy &&
test file3 = "$(git show HEAD:file3.t)" echo file3 >expect &&
git show HEAD:file3.t >actual &&
test_cmp expect actual
' '
test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' ' test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
git reset --hard before-preserve-rebase && git reset --hard before-preserve-rebase &&
test_config pull.rebase 1 && test_config pull.rebase 1 &&
git pull . copy && git pull . copy &&
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^^ copy &&
test file3 = "$(git show HEAD:file3.t)" echo file3 >expect &&
git show HEAD:file3.t >actual &&
test_cmp expect actual
' '
test_expect_success REBASE_P \ test_expect_success REBASE_P \
@ -466,8 +506,8 @@ test_expect_success REBASE_P \
git reset --hard before-preserve-rebase && git reset --hard before-preserve-rebase &&
test_config pull.rebase preserve && test_config pull.rebase preserve &&
git pull . copy && git pull . copy &&
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^^ copy &&
test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)" test_cmp_rev HEAD^2 keep-merge
' '
test_expect_success 'pull.rebase=interactive' ' test_expect_success 'pull.rebase=interactive' '
@ -478,7 +518,8 @@ test_expect_success 'pull.rebase=interactive' '
test_set_editor "$TRASH_DIRECTORY/fake-editor" && test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
test_when_finished "test_might_fail git rebase --abort" && test_when_finished "test_might_fail git rebase --abort" &&
test_must_fail git pull --rebase=interactive . copy && test_must_fail git pull --rebase=interactive . copy &&
test "I was here" = "$(cat fake.out)" echo "I was here" >expect &&
test_cmp expect fake.out
' '
test_expect_success 'pull --rebase=i' ' test_expect_success 'pull --rebase=i' '
@ -489,30 +530,35 @@ test_expect_success 'pull --rebase=i' '
test_set_editor "$TRASH_DIRECTORY/fake-editor" && test_set_editor "$TRASH_DIRECTORY/fake-editor" &&
test_when_finished "test_might_fail git rebase --abort" && test_when_finished "test_might_fail git rebase --abort" &&
test_must_fail git pull --rebase=i . copy && test_must_fail git pull --rebase=i . copy &&
test "I was here, too" = "$(cat fake.out)" echo "I was here, too" >expect &&
test_cmp expect fake.out
' '
test_expect_success 'pull.rebase=invalid fails' ' test_expect_success 'pull.rebase=invalid fails' '
git reset --hard before-preserve-rebase && git reset --hard before-preserve-rebase &&
test_config pull.rebase invalid && test_config pull.rebase invalid &&
! git pull . copy test_must_fail git pull . copy
' '
test_expect_success '--rebase=false create a new merge commit' ' test_expect_success '--rebase=false create a new merge commit' '
git reset --hard before-preserve-rebase && git reset --hard before-preserve-rebase &&
test_config pull.rebase true && test_config pull.rebase true &&
git pull --rebase=false . copy && git pull --rebase=false . copy &&
test "$(git rev-parse HEAD^1)" = "$(git rev-parse before-preserve-rebase)" && test_cmp_rev HEAD^1 before-preserve-rebase &&
test "$(git rev-parse HEAD^2)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^2 copy &&
test file3 = "$(git show HEAD:file3.t)" echo file3 >expect &&
git show HEAD:file3.t >actual &&
test_cmp expect actual
' '
test_expect_success '--rebase=true rebases and flattens keep-merge' ' test_expect_success '--rebase=true rebases and flattens keep-merge' '
git reset --hard before-preserve-rebase && git reset --hard before-preserve-rebase &&
test_config pull.rebase preserve && test_config pull.rebase preserve &&
git pull --rebase=true . copy && git pull --rebase=true . copy &&
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^^ copy &&
test file3 = "$(git show HEAD:file3.t)" echo file3 >expect &&
git show HEAD:file3.t >actual &&
test_cmp expect actual
' '
test_expect_success REBASE_P \ test_expect_success REBASE_P \
@ -520,58 +566,62 @@ test_expect_success REBASE_P \
git reset --hard before-preserve-rebase && git reset --hard before-preserve-rebase &&
test_config pull.rebase true && test_config pull.rebase true &&
git pull --rebase=preserve . copy && git pull --rebase=preserve . copy &&
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^^ copy &&
test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)" test_cmp_rev HEAD^2 keep-merge
' '
test_expect_success '--rebase=invalid fails' ' test_expect_success '--rebase=invalid fails' '
git reset --hard before-preserve-rebase && git reset --hard before-preserve-rebase &&
! git pull --rebase=invalid . copy test_must_fail git pull --rebase=invalid . copy
' '
test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' ' test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' '
git reset --hard before-preserve-rebase && git reset --hard before-preserve-rebase &&
test_config pull.rebase preserve && test_config pull.rebase preserve &&
git pull --rebase . copy && git pull --rebase . copy &&
test "$(git rev-parse HEAD^^)" = "$(git rev-parse copy)" && test_cmp_rev HEAD^^ copy &&
test file3 = "$(git show HEAD:file3.t)" echo file3 >expect &&
git show HEAD:file3.t >actual &&
test_cmp expect actual
' '
test_expect_success '--rebase with rebased upstream' ' test_expect_success '--rebase with rebased upstream' '
git remote add -f me . && git remote add -f me . &&
git checkout copy && git checkout copy &&
git tag copy-orig && git tag copy-orig &&
git reset --hard HEAD^ && git reset --hard HEAD^ &&
echo conflicting modification > file && echo conflicting modification >file &&
git commit -m conflict file && git commit -m conflict file &&
git checkout to-rebase && git checkout to-rebase &&
echo file > file2 && echo file >file2 &&
git commit -m to-rebase file2 && git commit -m to-rebase file2 &&
git tag to-rebase-orig && git tag to-rebase-orig &&
git pull --rebase me copy && git pull --rebase me copy &&
test "conflicting modification" = "$(cat file)" && echo "conflicting modification" >expect &&
test file = "$(cat file2)" test_cmp expect file &&
echo file >expect &&
test_cmp expect file2
' '
test_expect_success '--rebase -f with rebased upstream' ' test_expect_success '--rebase -f with rebased upstream' '
test_when_finished "test_might_fail git rebase --abort" && test_when_finished "test_might_fail git rebase --abort" &&
git reset --hard to-rebase-orig && git reset --hard to-rebase-orig &&
git pull --rebase -f me copy && git pull --rebase -f me copy &&
test "conflicting modification" = "$(cat file)" && echo "conflicting modification" >expect &&
test file = "$(cat file2)" test_cmp expect file &&
echo file >expect &&
test_cmp expect file2
' '
test_expect_success '--rebase with rebased default upstream' ' test_expect_success '--rebase with rebased default upstream' '
git update-ref refs/remotes/me/copy copy-orig && git update-ref refs/remotes/me/copy copy-orig &&
git checkout --track -b to-rebase2 me/copy && git checkout --track -b to-rebase2 me/copy &&
git reset --hard to-rebase-orig && git reset --hard to-rebase-orig &&
git pull --rebase && git pull --rebase &&
test "conflicting modification" = "$(cat file)" && echo "conflicting modification" >expect &&
test file = "$(cat file2)" test_cmp expect file &&
echo file >expect &&
test_cmp expect file2
' '
test_expect_success 'rebased upstream + fetch + pull --rebase' ' test_expect_success 'rebased upstream + fetch + pull --rebase' '
@ -582,13 +632,14 @@ test_expect_success 'rebased upstream + fetch + pull --rebase' '
git reset --hard to-rebase-orig && git reset --hard to-rebase-orig &&
git fetch && git fetch &&
git pull --rebase && git pull --rebase &&
test "conflicting modification" = "$(cat file)" && echo "conflicting modification" >expect &&
test file = "$(cat file2)" test_cmp expect file &&
echo file >expect &&
test_cmp expect file2
' '
test_expect_success 'pull --rebase dies early with dirty working directory' ' test_expect_success 'pull --rebase dies early with dirty working directory' '
git checkout to-rebase && git checkout to-rebase &&
git update-ref refs/remotes/me/copy copy^ && git update-ref refs/remotes/me/copy copy^ &&
COPY="$(git rev-parse --verify me/copy)" && COPY="$(git rev-parse --verify me/copy)" &&
@ -596,23 +647,23 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
test_config branch.to-rebase.remote me && test_config branch.to-rebase.remote me &&
test_config branch.to-rebase.merge refs/heads/copy && test_config branch.to-rebase.merge refs/heads/copy &&
test_config branch.to-rebase.rebase true && test_config branch.to-rebase.rebase true &&
echo dirty >> file && echo dirty >>file &&
git add file && git add file &&
test_must_fail git pull && test_must_fail git pull &&
test "$COPY" = "$(git rev-parse --verify me/copy)" && test_cmp_rev "$COPY" me/copy &&
git checkout HEAD -- file && git checkout HEAD -- file &&
git pull && git pull &&
test "$COPY" != "$(git rev-parse --verify me/copy)" test_cmp_rev ! "$COPY" me/copy
' '
test_expect_success 'pull --rebase works on branch yet to be born' ' test_expect_success 'pull --rebase works on branch yet to be born' '
git rev-parse master >expect && git rev-parse master >expect &&
mkdir empty_repo && mkdir empty_repo &&
(cd empty_repo && (
git init && cd empty_repo &&
git pull --rebase .. master && git init &&
git rev-parse HEAD >../actual git pull --rebase .. master &&
git rev-parse HEAD >../actual
) && ) &&
test_cmp expect actual test_cmp expect actual
' '
@ -624,10 +675,14 @@ test_expect_success 'pull --rebase fails on unborn branch with staged changes' '
cd empty_repo2 && cd empty_repo2 &&
echo staged-file >staged-file && echo staged-file >staged-file &&
git add staged-file && git add staged-file &&
test "$(git ls-files)" = staged-file && echo staged-file >expect &&
git ls-files >actual &&
test_cmp expect actual &&
test_must_fail git pull --rebase .. master 2>err && test_must_fail git pull --rebase .. master 2>err &&
test "$(git ls-files)" = staged-file && git ls-files >actual &&
test "$(git show :staged-file)" = staged-file && test_cmp expect actual &&
git show :staged-file >actual &&
test_cmp expect actual &&
test_i18ngrep "unborn branch with changes added to the index" err test_i18ngrep "unborn branch with changes added to the index" err
) )
' '
@ -638,7 +693,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
( (
cd corrupt && cd corrupt &&
test_commit one && test_commit one &&
obj=$(git rev-parse --verify HEAD | sed "s#^..#&/#") && git rev-parse --verify HEAD >head &&
obj=$(sed "s#^..#&/#" head) &&
rm -f .git/objects/$obj && rm -f .git/objects/$obj &&
test_must_fail git pull --rebase test_must_fail git pull --rebase
) )
@ -646,66 +702,77 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
test_expect_success 'setup for detecting upstreamed changes' ' test_expect_success 'setup for detecting upstreamed changes' '
mkdir src && mkdir src &&
(cd src && (
git init && cd src &&
printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff && git init &&
git add stuff && printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
git commit -m "Initial revision" git add stuff &&
git commit -m "Initial revision"
) && ) &&
git clone src dst && git clone src dst &&
(cd src && (
modify s/5/43/ stuff && cd src &&
git commit -a -m "5->43" && modify s/5/43/ stuff &&
modify s/6/42/ stuff && git commit -a -m "5->43" &&
git commit -a -m "Make it bigger" modify s/6/42/ stuff &&
git commit -a -m "Make it bigger"
) && ) &&
(cd dst && (
modify s/5/43/ stuff && cd dst &&
git commit -a -m "Independent discovery of 5->43" modify s/5/43/ stuff &&
git commit -a -m "Independent discovery of 5->43"
) )
' '
test_expect_success 'git pull --rebase detects upstreamed changes' ' test_expect_success 'git pull --rebase detects upstreamed changes' '
(cd dst && (
git pull --rebase && cd dst &&
test -z "$(git ls-files -u)" git pull --rebase &&
git ls-files -u >untracked &&
test_must_be_empty untracked
) )
' '
test_expect_success 'setup for avoiding reapplying old patches' ' test_expect_success 'setup for avoiding reapplying old patches' '
(cd dst && (
test_might_fail git rebase --abort && cd dst &&
git reset --hard origin/master test_might_fail git rebase --abort &&
git reset --hard origin/master
) && ) &&
git clone --bare src src-replace.git && git clone --bare src src-replace.git &&
rm -rf src && rm -rf src &&
mv src-replace.git src && mv src-replace.git src &&
(cd dst && (
modify s/2/22/ stuff && cd dst &&
git commit -a -m "Change 2" && modify s/2/22/ stuff &&
modify s/3/33/ stuff && git commit -a -m "Change 2" &&
git commit -a -m "Change 3" && modify s/3/33/ stuff &&
modify s/4/44/ stuff && git commit -a -m "Change 3" &&
git commit -a -m "Change 4" && modify s/4/44/ stuff &&
git push && git commit -a -m "Change 4" &&
git push &&
modify s/44/55/ stuff && modify s/44/55/ stuff &&
git commit --amend -a -m "Modified Change 4" git commit --amend -a -m "Modified Change 4"
) )
' '
test_expect_success 'git pull --rebase does not reapply old patches' ' test_expect_success 'git pull --rebase does not reapply old patches' '
(cd dst && (
test_must_fail git pull --rebase && cd dst &&
test 1 = $(find .git/rebase-apply -name "000*" | wc -l) test_must_fail git pull --rebase &&
find .git/rebase-apply -name "000*" >patches &&
test_line_count = 1 patches
) )
' '
test_expect_success 'git pull --rebase against local branch' ' test_expect_success 'git pull --rebase against local branch' '
git checkout -b copy2 to-rebase-orig && git checkout -b copy2 to-rebase-orig &&
git pull --rebase . to-rebase && git pull --rebase . to-rebase &&
test "conflicting modification" = "$(cat file)" && echo "conflicting modification" >expect &&
test file = "$(cat file2)" test_cmp expect file &&
echo file >expect &&
test_cmp expect file2
' '
test_done test_done

View File

@ -1012,19 +1012,30 @@ test_must_be_empty () {
fi fi
} }
# Tests that its two parameters refer to the same revision # Tests that its two parameters refer to the same revision, or if '!' is
# provided first, that its other two parameters refer to different
# revisions.
test_cmp_rev () { test_cmp_rev () {
local op='=' wrong_result=different
if test $# -ge 1 && test "x$1" = 'x!'
then
op='!='
wrong_result='the same'
shift
fi
if test $# != 2 if test $# != 2
then then
error "bug in the test script: test_cmp_rev requires two revisions, but got $#" error "bug in the test script: test_cmp_rev requires two revisions, but got $#"
else else
local r1 r2 local r1 r2
r1=$(git rev-parse --verify "$1") && r1=$(git rev-parse --verify "$1") &&
r2=$(git rev-parse --verify "$2") && r2=$(git rev-parse --verify "$2") || return 1
if test "$r1" != "$r2"
if ! test "$r1" "$op" "$r2"
then then
cat >&4 <<-EOF cat >&4 <<-EOF
error: two revisions point to different objects: error: two revisions point to $wrong_result objects:
'$1': $r1 '$1': $r1
'$2': $r2 '$2': $r2
EOF EOF