git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Stefan-W. Hahn" <stefan.hahn@s-hahn.de>
To: Johannes Sixt <j6t@kdbg.org>
Cc: git@vger.kernel.org
Subject: Re: Bug: Problem with CRLF line ending in git-diff with coloring
Date: Sat, 15 Feb 2014 08:21:58 +0100	[thread overview]
Message-ID: <20140215072158.GK7560@pille.home> (raw)
In-Reply-To: <52FE8847.8020101@kdbg.org>

Mail von Johannes Sixt, Fri, 14 Feb 2014 at 22:19:03 +0100:

Good morning,

> Am 14.02.2014 17:47, schrieb Stefan-W. Hahn:
> >> It's the right solution. IOW, you should place something like this in
> >> your .gitattributes:
> >>  *.html whitespace=cr-at-eol
> > 
> > Sorry, but this is not possible, because I have files of both sorts (mainly
> > C/C++) files in my repository and cannot change the files as I wish.
> 
> I'm confused. This setting does not change your files, but instructs git
> diff and git apply to not report the trailing CR as white-space error.
> Didn't you try it?

You are right, if I configure

        git config core.whitespace cr-at-eol

then the CR is not highlighted.

I try to work with it; I hope there are no other traps with it.

I changed the test to regard this, here it is.

With kind regards,
Stefan

#!/bin/sh
#
# Copyright (c) 2014 Stefan-W. Hahn
#

test_description='Test coloring of diff with CRLF line ending.

'
. ./test-lib.sh

get_color ()
{
	git config --get-color "$1"
}

test_expect_success setup '
        git config color.diff.plain black &&
        git config color.diff.meta blue &&
        git config color.diff.frag yellow &&
        git config color.diff.func normal &&
        git config color.diff.old red &&
        git config color.diff.new green &&
        git config color.diff.commit normal &&
	c_reset=$(git config --get-color no.such.color reset) &&
	c_plain=$(get_color color.diff.plain) &&
	c_meta=$(get_color color.diff.meta) &&
	c_frag=$(get_color color.diff.frag) &&
	c_func=$(get_color color.diff.func) &&
	c_old=$(get_color color.diff.old) &&
	c_new=$(get_color color.diff.new) &&
	c_commit=$(get_color color.diff.commit) &&
	c_whitespace=$(get_color color.diff.whitespace)
'

# Test cases
# - DOS line ending
#   - change one line
#   - change one line ending to UNIX
# - UNIX line ending
#   - change one line (trivial not tested here)
#   - change one line ending to DOS

tr 'Q' '\015' << EOF > x
Zeile 1Q
Zeile 2Q
Zeile 3Q
EOF

git update-index --add x

tr 'Q' '\015' << EOF > x
Zeile 1Q
Zeile 22Q
Zeile 3Q
EOF

tr 'Q' '\015' << EOF > expect
diff --git a/x b/x
index 3411cc1..68a4b2c 100644
--- a/x
+++ b/x
@@ -1,3 +1,3 @@
 Zeile 1Q
-Zeile 2Q
+Zeile 22Q
 Zeile 3Q
EOF

tr 'Q' '\015' << EOF > expect_color
${c_meta}diff --git a/x b/x${c_reset}
${c_meta}index 3411cc1..68a4b2c 100644${c_reset}
${c_meta}--- a/x${c_reset}
${c_meta}+++ b/x${c_reset}
${c_frag}@@ -1,3 +1,3 @@${c_reset}
${c_plain} Zeile 1${c_reset}Q
${c_old}-Zeile 2${c_reset}Q
${c_new}+${c_reset}${c_new}Zeile 22${c_reset}Q
${c_plain} Zeile 3${c_reset}Q
EOF

git -c color.diff=false diff > out
test_expect_success "diff files: change line in DOS file without color" '
        test_cmp expect out'

git -c color.diff=always -c core.whitespace=cr-at-eol diff > out
test_expect_success "diff files: change line in DOS file with color" '
        test_cmp expect_color out'


tr 'Q' '\015' << EOF > x
Zeile 1Q
Zeile 2Q
Zeile 3Q
EOF

git update-index --add x

tr 'Q' '\015' << EOF > x
Zeile 1Q
Zeile 2
Zeile 3Q
EOF

tr 'Q' '\015' << EOF > expect
diff --git a/x b/x
index 3411cc1..c040c67 100644
--- a/x
+++ b/x
@@ -1,3 +1,3 @@
 Zeile 1Q
-Zeile 2Q
+Zeile 2
 Zeile 3Q
EOF

tr 'Q' '\015' << EOF > expect_color
${c_meta}diff --git a/x b/x${c_reset}
${c_meta}index 3411cc1..c040c67 100644${c_reset}
${c_meta}--- a/x${c_reset}
${c_meta}+++ b/x${c_reset}
${c_frag}@@ -1,3 +1,3 @@${c_reset}
${c_plain} Zeile 1${c_reset}Q
${c_old}-Zeile 2${c_reset}Q
${c_new}+${c_reset}${c_new}Zeile 2${c_reset}
${c_plain} Zeile 3${c_reset}Q
EOF

git -c color.diff=false diff > out
test_expect_success "diff files: change line ending in DOS file to LF ending without color" '
        test_cmp expect out'

git -c color.diff=always diff > out
test_expect_success "diff files: change line ending in DOS file to LF ending with color" '
        test_cmp expect_color out'

tr 'Q' '\015' << EOF > x
Zeile 1
Zeile 2
Zeile 3
EOF

git update-index --add x

tr 'Q' '\015' << EOF > x
Zeile 1
Zeile 2Q
Zeile 3
EOF

tr 'Q' '\015' << EOF > expect
diff --git a/x b/x
index a385875..63416d7 100644
--- a/x
+++ b/x
@@ -1,3 +1,3 @@
 Zeile 1
-Zeile 2
+Zeile 2Q
 Zeile 3
EOF

tr 'Q' '\015' << EOF > expect_color
${c_meta}diff --git a/x b/x${c_reset}
${c_meta}index a385875..63416d7 100644${c_reset}
${c_meta}--- a/x${c_reset}
${c_meta}+++ b/x${c_reset}
${c_frag}@@ -1,3 +1,3 @@${c_reset}
${c_plain} Zeile 1${c_reset}
${c_old}-Zeile 2${c_reset}
${c_new}+${c_reset}${c_new}Zeile 2${c_reset}Q
${c_plain} Zeile 3${c_reset}
EOF

git -c color.diff=false diff > out
test_expect_success "diff files: change line ending in UNIX file to CRLF ending without color" '
        test_cmp expect out'

git -c color.diff=always -c core.whitespace=cr-at-eol diff > out
test_expect_success "diff files: change line ending in UNIX file to CRLF ending with color" '
        test_cmp expect_color out'

test_done


-- 
Stefan-W. Hahn                          It is easy to make things.
                                        It is hard to make things simple.

  reply	other threads:[~2014-02-15  7:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-09 11:01 Bug: Problem with CRLF line ending in git-diff with coloring Stefan-W. Hahn
2014-02-09 18:30 ` Johannes Sixt
2014-02-14 16:47 ` Stefan-W. Hahn
2014-02-14 21:19   ` Johannes Sixt
2014-02-15  7:21     ` Stefan-W. Hahn [this message]
2014-02-14 21:17 ` Stefan-W. Hahn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140215072158.GK7560@pille.home \
    --to=stefan.hahn@s-hahn.de \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).