Skip to content

Commit 833abdc

Browse files
mkiedrowiczgitster
authored andcommitted
merge tests: octopus with redundant parents
This happens when git merge is run to merge multiple commits that are descendants of current HEAD (or are HEAD). We've hit this while updating master to origin/master but accidentaly we called (while being on master): $ git merge master origin/master Here is a minimal testcase: $ git init a && cd a $ echo a >a && git add a $ git commit -minitial $ echo b >a && git add a $ git commit -msecond $ git checkout master^ $ git merge master master Fast-forwarding to: master Already up-to-date with master Merge made by the 'octopus' strategy. a | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) $ git cat-file commit HEAD tree eebfed94e75e7760540d1485c740902590a00332 parent bd679e85202280b263e20a57639a142fa14c2c64 author Michał Kiedrowicz <[email protected]> 1329132996 +0100 committer Michał Kiedrowicz <[email protected]> 1329132996 +0100 Merge branches 'master' and 'master' into HEAD Signed-off-by: Michał Kiedrowicz <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6eab5f2 commit 833abdc

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

t/t6028-merge-up-to-date.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ test_expect_success setup '
1616
test_tick &&
1717
git commit -m second &&
1818
git tag c1 &&
19-
git branch test
19+
git branch test &&
20+
echo third >file &&
21+
git add file &&
22+
test_tick &&
23+
git commit -m third &&
24+
git tag c2
2025
'
2126

2227
test_expect_success 'merge -s recursive up-to-date' '
@@ -74,4 +79,14 @@ test_expect_success 'merge -s subtree up-to-date' '
7479
7580
'
7681

82+
test_expect_failure 'merge fast-forward octopus' '
83+
84+
git reset --hard c0 &&
85+
test_tick &&
86+
git merge c1 c2
87+
expect=$(git rev-parse c2) &&
88+
current=$(git rev-parse HEAD) &&
89+
test "$expect" = "$current"
90+
'
91+
7792
test_done

t/t7602-merge-octopus-many.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,15 @@ test_expect_success 'merge output uses pretty names' '
7070
'
7171

7272
cat >expected <<\EOF
73-
Already up-to-date with c4
74-
Trying simple merge with c5
75-
Merge made by the 'octopus' strategy.
73+
Merge made by the 'recursive' strategy.
7674
c5.c | 1 +
7775
1 file changed, 1 insertion(+)
7876
create mode 100644 c5.c
7977
EOF
8078

81-
test_expect_success 'merge up-to-date output uses pretty names' '
82-
git merge c4 c5 >actual &&
83-
test_cmp actual expected
79+
test_expect_failure 'merge reduces irrelevant remote heads' '
80+
GIT_MERGE_VERBOSITY=0 git merge c4 c5 >actual &&
81+
test_cmp expected actual
8482
'
8583

8684
cat >expected <<\EOF

t/t7603-merge-reduce-heads.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,23 @@ test_expect_success 'verify merge result' '
113113
test $(git rev-parse HEAD^1) = $(git rev-parse E2) &&
114114
test $(git rev-parse HEAD^2) = $(git rev-parse I2)
115115
'
116+
117+
test_expect_success 'fast-forward to redundant refs' '
118+
git reset --hard c0 &&
119+
git merge c4 c5
120+
'
121+
122+
test_expect_failure 'verify merge result' '
123+
test $(git rev-parse HEAD) = $(git rev-parse c5)
124+
'
125+
126+
test_expect_success 'merge up-to-date redundant refs' '
127+
git reset --hard c5 &&
128+
git merge c0 c4
129+
'
130+
131+
test_expect_success 'verify merge result' '
132+
test $(git rev-parse HEAD) = $(git rev-parse c5)
133+
'
134+
116135
test_done

0 commit comments

Comments
 (0)