Skip to content

Commit ea81e10

Browse files
committed
Merge branch 'js/merge-recursive'
* js/merge-recursive: merge-recursive: respect core.autocrlf when writing out the result Add testcase for merging in a CRLF repo
2 parents 5bcde30 + 249c61a commit ea81e10

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

builtin-merge-recursive.c

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

559568
if (make_room_for_path(path) < 0) {
560569
update_wd = 0;
570+
free(buf);
561571
goto update_index;
562572
}
563573
if (S_ISREG(mode) || (!has_symlinks && S_ISLNK(mode))) {
@@ -580,6 +590,7 @@ static void update_file_flags(const unsigned char *sha,
580590
} else
581591
die("do not know what to do with %06o %s '%s'",
582592
mode, sha1_to_hex(sha), path);
593+
free(buf);
583594
}
584595
update_index:
585596
if (update_cache)

t/t6033-merge-crlf.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
3+
append_cr () {
4+
sed -e 's/$/Q/' | tr Q '\015'
5+
}
6+
7+
remove_cr () {
8+
tr '\015' Q | sed -e 's/Q$//'
9+
}
10+
11+
test_description='merge conflict in crlf repo
12+
13+
b---M
14+
/ /
15+
initial---a
16+
17+
'
18+
19+
. ./test-lib.sh
20+
21+
test_expect_success setup '
22+
git config core.autocrlf true &&
23+
echo foo | append_cr >file &&
24+
git add file &&
25+
git commit -m "Initial" &&
26+
git tag initial &&
27+
git branch side &&
28+
echo line from a | append_cr >file &&
29+
git commit -m "add line from a" file &&
30+
git tag a &&
31+
git checkout side &&
32+
echo line from b | append_cr >file &&
33+
git commit -m "add line from b" file &&
34+
git tag b &&
35+
git checkout master
36+
'
37+
38+
test_expect_success 'Check "ours" is CRLF' '
39+
git reset --hard initial &&
40+
git merge side -s ours &&
41+
cat file | remove_cr | append_cr >file.temp &&
42+
test_cmp file file.temp
43+
'
44+
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 &&
49+
test_cmp file file.temp
50+
'
51+
52+
test_done

0 commit comments

Comments
 (0)