Skip to content

Commit eff313f

Browse files
committed
Merge branch 'dl/apply-3way-diff3'
"git apply --3way" learned to honor merge.conflictStyle configuration variable, like merges would. * dl/apply-3way-diff3: apply: respect merge.conflictStyle in --3way t4108: demonstrate bug in apply t4108: use `test_config` instead of `git config` t4108: remove git command upstream of pipe t4108: replace create_file with test_write_lines
2 parents db806d7 + 091489d commit eff313f

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void git_apply_config(void)
3232
{
3333
git_config_get_string_const("apply.whitespace", &apply_default_whitespace);
3434
git_config_get_string_const("apply.ignorewhitespace", &apply_default_ignorewhitespace);
35-
git_config(git_default_config, NULL);
35+
git_config(git_xmerge_config, NULL);
3636
}
3737

3838
static int parse_whitespace_option(struct apply_state *state, const char *option)

t/t4108-apply-threeway.sh

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,31 @@ test_description='git apply --3way'
44

55
. ./test-lib.sh
66

7-
create_file () {
8-
for i
9-
do
10-
echo "$i"
11-
done
12-
}
13-
14-
sanitize_conflicted_diff () {
7+
print_sanitized_conflicted_diff () {
8+
git diff HEAD >diff.raw &&
159
sed -e '
1610
/^index /d
17-
s/^\(+[<>][<>][<>][<>]*\) .*/\1/
18-
'
11+
s/^\(+[<>|][<>|][<>|][<>|]*\) .*/\1/
12+
' diff.raw
1913
}
2014

2115
test_expect_success setup '
2216
test_tick &&
23-
create_file >one 1 2 3 4 5 6 7 &&
17+
test_write_lines 1 2 3 4 5 6 7 >one &&
2418
cat one >two &&
2519
git add one two &&
2620
git commit -m initial &&
2721
2822
git branch side &&
2923
3024
test_tick &&
31-
create_file >one 1 two 3 4 5 six 7 &&
32-
create_file >two 1 two 3 4 5 6 7 &&
25+
test_write_lines 1 two 3 4 5 six 7 >one &&
26+
test_write_lines 1 two 3 4 5 6 7 >two &&
3327
git commit -a -m master &&
3428
3529
git checkout side &&
36-
create_file >one 1 2 3 4 five 6 7 &&
37-
create_file >two 1 2 3 4 five 6 7 &&
30+
test_write_lines 1 2 3 4 five 6 7 >one &&
31+
test_write_lines 1 2 3 4 five 6 7 >two &&
3832
git commit -a -m side &&
3933
4034
git checkout master
@@ -52,7 +46,7 @@ test_expect_success 'apply without --3way' '
5246
git diff-index --exit-code --cached HEAD
5347
'
5448

55-
test_expect_success 'apply with --3way' '
49+
test_apply_with_3way () {
5650
# Merging side should be similar to applying this patch
5751
git diff ...side >P.diff &&
5852

@@ -61,22 +55,31 @@ test_expect_success 'apply with --3way' '
6155
git checkout master^0 &&
6256
test_must_fail git merge --no-commit side &&
6357
git ls-files -s >expect.ls &&
64-
git diff HEAD | sanitize_conflicted_diff >expect.diff &&
58+
print_sanitized_conflicted_diff >expect.diff &&
6559

6660
# should fail to apply
6761
git reset --hard &&
6862
git checkout master^0 &&
6963
test_must_fail git apply --index --3way P.diff &&
7064
git ls-files -s >actual.ls &&
71-
git diff HEAD | sanitize_conflicted_diff >actual.diff &&
65+
print_sanitized_conflicted_diff >actual.diff &&
7266

7367
# The result should resemble the corresponding merge
7468
test_cmp expect.ls actual.ls &&
7569
test_cmp expect.diff actual.diff
70+
}
71+
72+
test_expect_success 'apply with --3way' '
73+
test_apply_with_3way
74+
'
75+
76+
test_expect_success 'apply with --3way with merge.conflictStyle = diff3' '
77+
test_config merge.conflictStyle diff3 &&
78+
test_apply_with_3way
7679
'
7780

7881
test_expect_success 'apply with --3way with rerere enabled' '
79-
git config rerere.enabled true &&
82+
test_config rerere.enabled true &&
8083
8184
# Merging side should be similar to applying this patch
8285
git diff ...side >P.diff &&
@@ -87,7 +90,7 @@ test_expect_success 'apply with --3way with rerere enabled' '
8790
test_must_fail git merge --no-commit side &&
8891
8992
# Manually resolve and record the resolution
90-
create_file 1 two 3 4 five six 7 >one &&
93+
test_write_lines 1 two 3 4 five six 7 >one &&
9194
git rerere &&
9295
cat one >expect &&
9396
@@ -104,14 +107,14 @@ test_expect_success 'apply -3 with add/add conflict setup' '
104107
git reset --hard &&
105108
106109
git checkout -b adder &&
107-
create_file 1 2 3 4 5 6 7 >three &&
108-
create_file 1 2 3 4 5 6 7 >four &&
110+
test_write_lines 1 2 3 4 5 6 7 >three &&
111+
test_write_lines 1 2 3 4 5 6 7 >four &&
109112
git add three four &&
110113
git commit -m "add three and four" &&
111114
112115
git checkout -b another adder^ &&
113-
create_file 1 2 3 4 5 6 7 >three &&
114-
create_file 1 2 3 four 5 6 7 >four &&
116+
test_write_lines 1 2 3 4 5 6 7 >three &&
117+
test_write_lines 1 2 3 four 5 6 7 >four &&
115118
git add three four &&
116119
git commit -m "add three and four" &&
117120
@@ -121,7 +124,7 @@ test_expect_success 'apply -3 with add/add conflict setup' '
121124
git checkout adder^0 &&
122125
test_must_fail git merge --no-commit another &&
123126
git ls-files -s >expect.ls &&
124-
git diff HEAD | sanitize_conflicted_diff >expect.diff
127+
print_sanitized_conflicted_diff >expect.diff
125128
'
126129

127130
test_expect_success 'apply -3 with add/add conflict' '
@@ -131,7 +134,7 @@ test_expect_success 'apply -3 with add/add conflict' '
131134
test_must_fail git apply --index --3way P.diff &&
132135
# ... and leave conflicts in the index and in the working tree
133136
git ls-files -s >actual.ls &&
134-
git diff HEAD | sanitize_conflicted_diff >actual.diff &&
137+
print_sanitized_conflicted_diff >actual.diff &&
135138
136139
# The result should resemble the corresponding merge
137140
test_cmp expect.ls actual.ls &&

0 commit comments

Comments
 (0)