Skip to content

Commit 5430bb2

Browse files
committed
diff: demote core.safecrlf=true to core.safecrlf=warn
Otherwise the user will not be able to start to guess where in the contents in the working tree the offending unsafe CR lies. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e20105 commit 5430bb2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

diff.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,14 @@ static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
26472647
int diff_populate_filespec(struct diff_filespec *s, int size_only)
26482648
{
26492649
int err = 0;
2650+
/*
2651+
* demote FAIL to WARN to allow inspecting the situation
2652+
* instead of refusing.
2653+
*/
2654+
enum safe_crlf crlf_warn = (safe_crlf == SAFE_CRLF_FAIL
2655+
? SAFE_CRLF_WARN
2656+
: safe_crlf);
2657+
26502658
if (!DIFF_FILE_VALID(s))
26512659
die("internal error: asking to populate invalid file.");
26522660
if (S_ISDIR(s->mode))
@@ -2702,7 +2710,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
27022710
/*
27032711
* Convert from working tree format to canonical git format
27042712
*/
2705-
if (convert_to_git(s->path, s->data, s->size, &buf, safe_crlf)) {
2713+
if (convert_to_git(s->path, s->data, s->size, &buf, crlf_warn)) {
27062714
size_t size = 0;
27072715
munmap(s->data, s->size);
27082716
s->should_munmap = 0;

t/t0020-crlf.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ test_expect_success 'safecrlf: print warning only once' '
8181
test $(git add doublewarn 2>&1 | grep "CRLF will be replaced by LF" | wc -l) = 1
8282
'
8383

84+
85+
test_expect_success 'safecrlf: git diff demotes safecrlf=true to warn' '
86+
git config core.autocrlf input &&
87+
git config core.safecrlf true &&
88+
git diff HEAD
89+
'
90+
91+
8492
test_expect_success 'switch off autocrlf, safecrlf, reset HEAD' '
8593
git config core.autocrlf false &&
8694
git config core.safecrlf false &&

0 commit comments

Comments
 (0)