Skip to content

Commit eea9828

Browse files
Marius Storm-Olsengitster
authored andcommitted
Add testcase for merging in a CRLF repo
If you work on a repo with core.autocrlf == true, you would expect every text file to have CRLF EOLs. However, if you by some operation, get a conflict, then the conflicted file has LF EOLs. Now, of course you'd go about resolving the files conflict, and then 'git add <file>'. When you do that, you'll get the warning saying that LF will be replaced by CRLF. Then you commit. The end result is that you have a workingdir with a mix of LF and CRLF files, which after some more operations may trigger a "whole file changed" diff, due to the workingdir file now having LF EOLs. An LF only conflict file results in the resolved file being in LF, the commit is in LF and a warning saying that LF will be replaced by CRLF, and the working dir ends up with a mix of CRLF and LF files. Signed-off-by: Marius Storm-Olsen <marius@trolltech.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 170e095 commit eea9828

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

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_failure '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)