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>
Johannes Schindelin committed
Jun 9, 2008 at 22:23 UTC
249c61a62d82c22df98cb72ec61c120887b944e1
2 files changed
+12
-1
builtin-merge-recursive.c
+11
@@ -551,9 +551,19 @@ static void update_file_flags(const unsigned char *sha,
551
die("cannot read object %s '%s'", sha1_to_hex(sha), path);
552
if (type != OBJ_BLOB)
553
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
+ }
563
564
if (make_room_for_path(path) < 0) {
565
update_wd = 0;
566
+ free(buf);
567
goto update_index;
568
}
569
if (S_ISREG(mode) || (!has_symlinks && S_ISLNK(mode))) {
@@ -576,6 +586,7 @@ static void update_file_flags(const unsigned char *sha,
586
} else
587
die("do not know what to do with %06o %s '%s'",
588
mode, sha1_to_hex(sha), path);
589
+ free(buf);
590
}
591
update_index:
592
if (update_cache)
t/t6033-merge-crlf.sh
+1
-1
@@ -42,7 +42,7 @@ test_expect_success 'Check "ours" is CRLF' '
42
test_cmp file file.temp
43
'
44
45
-test_expect_failure 'Check that conflict file is CRLF' '
45
+test_expect_success 'Check that conflict file is CRLF' '
46
git reset --hard a &&
47
test_must_fail git merge side &&
48
cat file | remove_cr | append_cr >file.temp &&