Merge branch 'jc/merge'

"git merge FETCH_HEAD" learned that the previous "git fetch" could
be to create an Octopus merge, i.e. recording multiple branches
that are not marked as "not-for-merge"; this allows us to lose an
old style invocation "git merge <msg> HEAD $commits..." in the
implementation of "git pull" script; the old style syntax can now
be deprecated.

* jc/merge:
  merge: deprecate 'git merge <message> HEAD <commit>' syntax
  merge: handle FETCH_HEAD internally
  merge: decide if we auto-generate the message early in collect_parents()
  merge: make collect_parents() auto-generate the merge message
  merge: extract prepare_merge_message() logic out
  merge: narrow scope of merge_names
  merge: split reduce_parents() out of collect_parents()
  merge: clarify collect_parents() logic
  merge: small leakfix and code simplification
  merge: do not check argc to determine number of remote heads
  merge: clarify "pulling into void" special case
  t5520: test pulling an octopus into an unborn branch
  t5520: style fixes
  merge: simplify code flow
  merge: test the top-level merge driver
This commit is contained in:
Junio C Hamano
2015-05-19 13:17:57 -07:00
10 changed files with 329 additions and 117 deletions

136
t/t3033-merge-toplevel.sh Executable file
View File

@ -0,0 +1,136 @@
#!/bin/sh
test_description='"git merge" top-level frontend'
. ./test-lib.sh
t3033_reset () {
git checkout -B master two &&
git branch -f left three &&
git branch -f right four
}
test_expect_success setup '
test_commit one &&
git branch left &&
git branch right &&
test_commit two &&
git checkout left &&
test_commit three &&
git checkout right &&
test_commit four &&
git checkout master
'
# Local branches
test_expect_success 'merge an octopus into void' '
t3033_reset &&
git checkout --orphan test &&
git rm -fr . &&
test_must_fail git merge left right &&
test_must_fail git rev-parse --verify HEAD &&
git diff --quiet &&
test_must_fail git rev-parse HEAD
'
test_expect_success 'merge an octopus, fast-forward (ff)' '
t3033_reset &&
git reset --hard one &&
git merge left right &&
# one is ancestor of three (left) and four (right)
test_must_fail git rev-parse --verify HEAD^3 &&
git rev-parse HEAD^1 HEAD^2 | sort >actual &&
git rev-parse three four | sort >expect &&
test_cmp expect actual
'
test_expect_success 'merge octopus, non-fast-forward (ff)' '
t3033_reset &&
git reset --hard one &&
git merge --no-ff left right &&
# one is ancestor of three (left) and four (right)
test_must_fail git rev-parse --verify HEAD^4 &&
git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
git rev-parse one three four | sort >expect &&
test_cmp expect actual
'
test_expect_success 'merge octopus, fast-forward (does not ff)' '
t3033_reset &&
git merge left right &&
# two (master) is not an ancestor of three (left) and four (right)
test_must_fail git rev-parse --verify HEAD^4 &&
git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
git rev-parse two three four | sort >expect &&
test_cmp expect actual
'
test_expect_success 'merge octopus, non-fast-forward' '
t3033_reset &&
git merge --no-ff left right &&
test_must_fail git rev-parse --verify HEAD^4 &&
git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
git rev-parse two three four | sort >expect &&
test_cmp expect actual
'
# The same set with FETCH_HEAD
test_expect_success 'merge FETCH_HEAD octopus into void' '
t3033_reset &&
git checkout --orphan test &&
git rm -fr . &&
git fetch . left right &&
test_must_fail git merge FETCH_HEAD &&
test_must_fail git rev-parse --verify HEAD &&
git diff --quiet &&
test_must_fail git rev-parse HEAD
'
test_expect_success 'merge FETCH_HEAD octopus fast-forward (ff)' '
t3033_reset &&
git reset --hard one &&
git fetch . left right &&
git merge FETCH_HEAD &&
# one is ancestor of three (left) and four (right)
test_must_fail git rev-parse --verify HEAD^3 &&
git rev-parse HEAD^1 HEAD^2 | sort >actual &&
git rev-parse three four | sort >expect &&
test_cmp expect actual
'
test_expect_success 'merge FETCH_HEAD octopus non-fast-forward (ff)' '
t3033_reset &&
git reset --hard one &&
git fetch . left right &&
git merge --no-ff FETCH_HEAD &&
# one is ancestor of three (left) and four (right)
test_must_fail git rev-parse --verify HEAD^4 &&
git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
git rev-parse one three four | sort >expect &&
test_cmp expect actual
'
test_expect_success 'merge FETCH_HEAD octopus fast-forward (does not ff)' '
t3033_reset &&
git fetch . left right &&
git merge FETCH_HEAD &&
# two (master) is not an ancestor of three (left) and four (right)
test_must_fail git rev-parse --verify HEAD^4 &&
git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
git rev-parse two three four | sort >expect &&
test_cmp expect actual
'
test_expect_success 'merge FETCH_HEAD octopus non-fast-forward' '
t3033_reset &&
git fetch . left right &&
git merge --no-ff FETCH_HEAD &&
test_must_fail git rev-parse --verify HEAD^4 &&
git rev-parse HEAD^1 HEAD^2 HEAD^3 | sort >actual &&
git rev-parse two three four | sort >expect &&
test_cmp expect actual
'
test_done

View File

@ -47,7 +47,7 @@ test_expect_success setup '
'
test_expect_success 'reference merge' '
git merge -s recursive "reference merge" HEAD master
git merge -s recursive -m "reference merge" master
'
PRE_REBASE=$(git rev-parse test-rebase)

View File

@ -9,36 +9,27 @@ modify () {
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' '
git init cloned &&
(
cd cloned &&
git pull ..
) &&
test -f file &&
test -f cloned/file &&
test_cmp file cloned/file
'
test_expect_success 'pulling into void using master:master' '
mkdir cloned-uho &&
git init cloned-uho &&
(
cd cloned-uho &&
git init &&
git pull .. master:master
) &&
test -f file &&
@ -71,7 +62,6 @@ test_expect_success 'pulling into void does not overwrite staged files' '
)
'
test_expect_success 'pulling into void does not remove new staged files' '
git init cloned-staged-new &&
(
@ -86,6 +76,15 @@ test_expect_success 'pulling into void does not remove new staged files' '
)
'
test_expect_success 'pulling into void must not create an octopus' '
git init cloned-octopus &&
(
cd cloned-octopus &&
test_must_fail git pull .. master master &&
! test -f file
)
'
test_expect_success 'test . as a remote' '
git branch copy master &&

View File

@ -24,7 +24,7 @@ test_expect_success 'prepare repository' '
'
test_expect_success 'Merge with d/f conflicts' '
test_expect_code 1 git merge "merge msg" B master
test_expect_code 1 git merge -m "merge msg" master
'
test_expect_success 'F/D conflict' '

View File

@ -48,7 +48,7 @@ echo "1
" > file &&
git commit -m "C3" file &&
git branch C3 &&
git merge "pre E3 merge" B A &&
git merge -m "pre E3 merge" A &&
echo "1
2
3 changed in E3, branch B. New file size
@ -61,7 +61,7 @@ echo "1
" > file &&
git commit -m "E3" file &&
git checkout A &&
git merge "pre D8 merge" A C3 &&
git merge -m "pre D8 merge" C3 &&
echo "1
2
3 changed in C3, branch B
@ -73,7 +73,7 @@ echo "1
9" > file &&
git commit -m D8 file'
test_expect_success 'Criss-cross merge' 'git merge "final merge" A B'
test_expect_success 'Criss-cross merge' 'git merge -m "final merge" B'
cat > file-expect <<EOF
1

View File

@ -496,7 +496,7 @@ test_expect_success 'check [cvswork3] diff' '
'
test_expect_success 'merge early [cvswork3] b3 with b1' '
( cd gitwork3 && git merge "message" HEAD b1 ) &&
( cd gitwork3 && git merge -m "message" b1 ) &&
git fetch gitwork3 b3:b3 &&
git tag v3merged b3 &&
git push --tags gitcvs.git b3:b3