Skip to content

Commit 2e42338

Browse files
committed
Merge branch 'mk/merge-incomplete-files'
Merging changes into a file that ends in an incomplete line made the last line into a complete one, even when the other branch did not change anything around the end of file. * mk/merge-incomplete-files: git-merge-file: do not add LF at EOF while applying unrelated change t6023-merge-file.sh: fix and mark as broken invalid tests
2 parents 6e40947 + ba31180 commit 2e42338

File tree

2 files changed

+90
-5
lines changed

2 files changed

+90
-5
lines changed

t/t6023-merge-file.sh

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,29 @@ test_expect_success "merge without conflict (--quiet)" \
7777
"git merge-file --quiet test.txt orig.txt new2.txt"
7878

7979
cp new1.txt test2.txt
80-
test_expect_success "merge without conflict (missing LF at EOF)" \
81-
"git merge-file test2.txt orig.txt new2.txt"
80+
test_expect_failure "merge without conflict (missing LF at EOF)" \
81+
"git merge-file test2.txt orig.txt new4.txt"
8282

83-
test_expect_success "merge result added missing LF" \
83+
test_expect_failure "merge result added missing LF" \
8484
"test_cmp test.txt test2.txt"
8585

86+
cp new4.txt test3.txt
87+
test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" \
88+
"git merge-file --quiet test3.txt new2.txt new3.txt"
89+
90+
cat > expect.txt << EOF
91+
DOMINUS regit me,
92+
et nihil mihi deerit.
93+
In loco pascuae ibi me collocavit,
94+
super aquam refectionis educavit me;
95+
animam meam convertit,
96+
deduxit me super semitas jusitiae,
97+
EOF
98+
printf "propter nomen suum." >> expect.txt
99+
100+
test_expect_success "merge does not add LF away of change" \
101+
"test_cmp test3.txt expect.txt"
102+
86103
cp test.txt backup.txt
87104
test_expect_success "merge with conflicts" \
88105
"test_must_fail git merge-file test.txt orig.txt new3.txt"
@@ -107,6 +124,55 @@ EOF
107124
test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt"
108125

109126
cp backup.txt test.txt
127+
128+
cat > expect.txt << EOF
129+
Dominus regit me, et nihil mihi deerit.
130+
In loco pascuae ibi me collocavit,
131+
super aquam refectionis educavit me;
132+
animam meam convertit,
133+
deduxit me super semitas jusitiae,
134+
propter nomen suum.
135+
Nam et si ambulavero in medio umbrae mortis,
136+
non timebo mala, quoniam tu mecum es:
137+
virga tua et baculus tuus ipsa me consolata sunt.
138+
EOF
139+
test_expect_success "merge conflicting with --ours" \
140+
"git merge-file --ours test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
141+
cp backup.txt test.txt
142+
143+
cat > expect.txt << EOF
144+
DOMINUS regit me,
145+
et nihil mihi deerit.
146+
In loco pascuae ibi me collocavit,
147+
super aquam refectionis educavit me;
148+
animam meam convertit,
149+
deduxit me super semitas jusitiae,
150+
propter nomen suum.
151+
Nam et si ambulavero in medio umbrae mortis,
152+
non timebo mala, quoniam tu mecum es:
153+
virga tua et baculus tuus ipsa me consolata sunt.
154+
EOF
155+
test_expect_success "merge conflicting with --theirs" \
156+
"git merge-file --theirs test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
157+
cp backup.txt test.txt
158+
159+
cat > expect.txt << EOF
160+
Dominus regit me, et nihil mihi deerit.
161+
DOMINUS regit me,
162+
et nihil mihi deerit.
163+
In loco pascuae ibi me collocavit,
164+
super aquam refectionis educavit me;
165+
animam meam convertit,
166+
deduxit me super semitas jusitiae,
167+
propter nomen suum.
168+
Nam et si ambulavero in medio umbrae mortis,
169+
non timebo mala, quoniam tu mecum es:
170+
virga tua et baculus tuus ipsa me consolata sunt.
171+
EOF
172+
test_expect_success "merge conflicting with --union" \
173+
"git merge-file --union test.txt orig.txt new3.txt && test_cmp test.txt expect.txt"
174+
cp backup.txt test.txt
175+
110176
test_expect_success "merge with conflicts, using -L" \
111177
"test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
112178

@@ -260,4 +326,23 @@ test_expect_success 'marker size' '
260326
test_cmp expect actual
261327
'
262328

329+
printf "line1\nline2\nline3" >nolf-orig.txt
330+
printf "line1\nline2\nline3x" >nolf-diff1.txt
331+
printf "line1\nline2\nline3y" >nolf-diff2.txt
332+
333+
test_expect_success 'conflict at EOF without LF resolved by --ours' \
334+
'git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
335+
printf "line1\nline2\nline3x" >expect.txt &&
336+
test_cmp expect.txt output.txt'
337+
338+
test_expect_success 'conflict at EOF without LF resolved by --theirs' \
339+
'git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
340+
printf "line1\nline2\nline3y" >expect.txt &&
341+
test_cmp expect.txt output.txt'
342+
343+
test_expect_success 'conflict at EOF without LF resolved by --union' \
344+
'git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
345+
printf "line1\nline2\nline3x\nline3y" >expect.txt &&
346+
test_cmp expect.txt output.txt'
347+
263348
test_done

xdiff/xmerge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
245245
dest ? dest + size : NULL);
246246
/* Postimage from side #1 */
247247
if (m->mode & 1)
248-
size += xdl_recs_copy(xe1, m->i1, m->chg1, 1,
248+
size += xdl_recs_copy(xe1, m->i1, m->chg1, (m->mode & 2),
249249
dest ? dest + size : NULL);
250250
/* Postimage from side #2 */
251251
if (m->mode & 2)
252-
size += xdl_recs_copy(xe2, m->i2, m->chg2, 1,
252+
size += xdl_recs_copy(xe2, m->i2, m->chg2, 0,
253253
dest ? dest + size : NULL);
254254
} else
255255
continue;

0 commit comments

Comments
 (0)