Skip to content

Commit 52b48ef

Browse files
jrngitster
authored andcommitted
merge: let custom strategies intervene in trivial merges
As v1.6.1-rc1~294^2 (2008-08-23) explains, custom merge strategies do not even kick in when the merge is truly trivial. But they should, since otherwise a custom “--strategy=theirs” is not useful. Perhaps custom strategies should not allow fast-forward either. This patch does not make that change, since it is less important (because it is always possible to explicitly use --no-ff). Reported-by: Yaroslav Halchenko <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6209036 commit 52b48ef

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

builtin/merge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static struct strategy *get_strategy(const char *name)
131131

132132
ret = xcalloc(1, sizeof(struct strategy));
133133
ret->name = xstrdup(name);
134+
ret->attr = NO_TRIVIAL;
134135
return ret;
135136
}
136137

t/t7606-merge-custom.sh

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ test_description="git merge
44
55
Testing a custom strategy.
66
7-
* (HEAD, master) Merge commit 'c2'
7+
* (HEAD, master) Merge commit 'c3'
88
|\
9-
| * (tag: c2) c2
9+
| * (tag: c3) c3
1010
* | (tag: c1) c1
1111
|/
12+
| * tag: c2) c2
13+
|/
1214
* (tag: c0) c0
1315
"
1416

@@ -31,7 +33,9 @@ test_expect_success 'setup' '
3133
git reset --keep c0 &&
3234
echo c1c1 >c1.c &&
3335
git add c1.c &&
34-
test_commit c2 c2.c
36+
test_commit c2 c2.c &&
37+
git reset --keep c0 &&
38+
test_commit c3 c3.c
3539
'
3640

3741
test_expect_success 'merge c2 with a custom strategy' '
@@ -60,4 +64,30 @@ test_expect_success 'merge c2 with a custom strategy' '
6064
test -f c2.c
6165
'
6266

67+
test_expect_success 'trivial merge with custom strategy' '
68+
git reset --hard c1 &&
69+
70+
git rev-parse c1 >head.old &&
71+
git rev-parse c3 >second-parent.expected &&
72+
git rev-parse c3^{tree} >tree.expected &&
73+
git merge -s theirs c3 &&
74+
75+
git rev-parse HEAD >head &&
76+
git rev-parse HEAD^1 >first-parent &&
77+
git rev-parse HEAD^2 >second-parent &&
78+
git rev-parse HEAD^{tree} >tree &&
79+
git update-index --refresh &&
80+
git diff --exit-code &&
81+
git diff --exit-code c3 HEAD &&
82+
git diff --exit-code c3 &&
83+
84+
! test_cmp head.old head &&
85+
test_cmp head.old first-parent &&
86+
test_cmp second-parent.expected second-parent &&
87+
test_cmp tree.expected tree &&
88+
test -f c0.c &&
89+
! test -e c1.c &&
90+
test -f c3.c
91+
'
92+
6393
test_done

0 commit comments

Comments
 (0)