Skip to content

Commit 82ec54d

Browse files
committed
Merge branch 'jc/maint-diff-core-safecrlf' into maint
Avoid failing "git diff" when core.safecrlf is set to true, because the user cannot tell where the breakage is in preparation for fixing and committing. * jc/maint-diff-core-safecrlf: diff: demote core.safecrlf=true to core.safecrlf=warn
2 parents 7c8ce4e + 5430bb2 commit 82ec54d

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
@@ -2677,6 +2677,14 @@ static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
26772677
int diff_populate_filespec(struct diff_filespec *s, int size_only)
26782678
{
26792679
int err = 0;
2680+
/*
2681+
* demote FAIL to WARN to allow inspecting the situation
2682+
* instead of refusing.
2683+
*/
2684+
enum safe_crlf crlf_warn = (safe_crlf == SAFE_CRLF_FAIL
2685+
? SAFE_CRLF_WARN
2686+
: safe_crlf);
2687+
26802688
if (!DIFF_FILE_VALID(s))
26812689
die("internal error: asking to populate invalid file.");
26822690
if (S_ISDIR(s->mode))
@@ -2732,7 +2740,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
27322740
/*
27332741
* Convert from working tree format to canonical git format
27342742
*/
2735-
if (convert_to_git(s->path, s->data, s->size, &buf, safe_crlf)) {
2743+
if (convert_to_git(s->path, s->data, s->size, &buf, crlf_warn)) {
27362744
size_t size = 0;
27372745
munmap(s->data, s->size);
27382746
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)