Skip to content

Commit 249c61a

Browse files
dschogitster
authored andcommitted
merge-recursive: respect core.autocrlf when writing out the result
The code forgot to convert the blob contents into work tree representation before writing it out. Also fixes leaks -- earlier the updated blobs were never freed. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent eea9828 commit 249c61a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

builtin-merge-recursive.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,19 @@ static void update_file_flags(const unsigned char *sha,
551551
die("cannot read object %s '%s'", sha1_to_hex(sha), path);
552552
if (type != OBJ_BLOB)
553553
die("blob expected for %s '%s'", sha1_to_hex(sha), path);
554+
if (S_ISREG(mode)) {
555+
struct strbuf strbuf;
556+
strbuf_init(&strbuf, 0);
557+
if (convert_to_working_tree(path, buf, size, &strbuf)) {
558+
free(buf);
559+
size = strbuf.len;
560+
buf = strbuf_detach(&strbuf, NULL);
561+
}
562+
}
554563

555564
if (make_room_for_path(path) < 0) {
556565
update_wd = 0;
566+
free(buf);
557567
goto update_index;
558568
}
559569
if (S_ISREG(mode) || (!has_symlinks && S_ISLNK(mode))) {
@@ -576,6 +586,7 @@ static void update_file_flags(const unsigned char *sha,
576586
} else
577587
die("do not know what to do with %06o %s '%s'",
578588
mode, sha1_to_hex(sha), path);
589+
free(buf);
579590
}
580591
update_index:
581592
if (update_cache)

t/t6033-merge-crlf.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test_expect_success 'Check "ours" is CRLF' '
4242
test_cmp file file.temp
4343
'
4444

45-
test_expect_failure 'Check that conflict file is CRLF' '
45+
test_expect_success 'Check that conflict file is CRLF' '
4646
git reset --hard a &&
4747
test_must_fail git merge side &&
4848
cat file | remove_cr | append_cr >file.temp &&

0 commit comments

Comments
 (0)