git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Torsten =?unknown-8bit?Q?B=C3=B6gershausen?= <tboegi@web.de>
To: "Mirochnik, Oleg V" <oleg.v.mirochnik@intel.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: Git apply can convert LF file into CRLF when .gitattributes file is a part of a patch
Date: Sat, 11 Sep 2021 08:43:57 +0200	[thread overview]
Message-ID: <20210911064357.r7cpmxkt5w5davzb@tb-raspi4> (raw)
In-Reply-To: <SJ0PR11MB49429B90AA71A06BD4A3BD15C6D49@SJ0PR11MB4942.namprd11.prod.outlook.com>

On Wed, Sep 08, 2021 at 12:53:42AM +0000, Mirochnik, Oleg V wrote:
> Hi,
>
> Originally the issue was reported in https://github.com/git-for-windows/git/issues/3409
> But I was asked to report it in the mail list as the issue is not a Windows related.
>
> As you can see below "git apply --binary" converts files into CRLF mode if .gitattributes file modification is included into a patch file.
> IMO behavior should be consistent - "git apply --binary" should not convert files into CRLF mode because of unrelated change in .gitattributes file.


It was probablty me who suggested to report this issue here on the mailing list.
Thanks for doing so.

I extracted your test script, run it on a Mac,
and it seems to give a different result then your run.

Just to quote the las lines:
+++ patch no CR
HEAD is now at a47b66d init
+++ After reset and before patch
LF cr/foo
LF lf/foo
LF lf/.gitattributes
+++ After patch
LF cr/foo
LF lf/foo
LF lf/.gitattributes
---------

Seeing this, I am unsure what is going on.
It may be an idea to convert the script into a real git test case,
and send it to the list.
There is a command
git ls-files --eol
to let Git report the line endings of files

Using
----------------
echo "this is what I expected" >expect &&
git ls-files --eol >actual &&
test_cmp expect actual
------------------

would allow everybody to see what is possible wrong.
And somebody may be willing to dig deeper - and if it
a bug, send a patch



>
> Steps:
> $ cat doit
> git --version --build-options
> git config --global core.autocrlf true
>
> rm -rf tst
> mkdir tst
> cd tst
> mkdir repo.git
> cd repo.git
> git init --bare
> cd ..
> git clone repo.git 1
> cd 1
> mkdir cr lf
> echo '* -text' > lf/.gitattributes
> for d in *; do for b in {1..5}; do echo foo >> $d/foo; done; done
> git add *
> git commit -m init
> git push
> cd ../
>
> git clone repo.git/ 2
> cd 2
> for a in `find * -type f`; do echo `od -c $a | grep -q '\\r' && echo CR || echo LF` $a; done
> for a in `find * -type f`; do echo '# dummy' >> $a; done
> git commit -a -m dummy
> echo ""
> echo +++ After commit and before diff
> for a in `find * -type f`; do echo `od -c $a | grep -q '\\r' && echo CR || echo LF` $a; done
> git diff --binary HEAD~ -- cr lf     > ../patch.with
> git diff --binary HEAD~ -- cr lf/foo > ../patch.without
> git diff --binary HEAD~ --    lf     > ../patch.lf-only
> cd ..
>
> echo ""
> echo +++ Patches
> for a in patch*; do echo `od -c $a | grep -q '\\r' && echo CR || echo LF` $a; done
>
> git clone repo.git 3
> cd 3
>
> echo ""
> echo +++ patch w/o .gitattributes
> git reset --hard
> echo +++ After reset and before patch
> for a in `find * -type f`; do echo `od -c $a | grep -q '\\r' && echo CR || echo LF` $a; done
> git apply --binary ../patch.without
> echo +++ After patch
> for a in `find * -type f`; do echo `od -c $a | grep -q '\\r' && echo CR || echo LF` $a; done
>
> echo ""
> echo +++ patch with .gitattributes
> git reset --hard
> echo +++ After reset and before patch
> for a in `find * -type f`; do echo `od -c $a | grep -q '\\r' && echo CR || echo LF` $a; done
> git apply --binary ../patch.with
> echo +++ After patch
> for a in `find * -type f`; do echo `od -c $a | grep -q '\\r' && echo CR || echo LF` $a; done
>
>
> echo ""
> echo +++ patch no CR
> git reset --hard
> echo +++ After reset and before patch
> for a in `find * -type f`; do echo `od -c $a | grep -q '\\r' && echo CR || echo LF` $a; done
> git apply --binary ../patch.lf-only
> echo +++ After patch
> for a in `find * -type f`; do echo `od -c $a | grep -q '\\r' && echo CR || echo LF` $a; done
>
> git config --global core.autocrlf false
>
> $ sh doit
> git version 2.29.2
> cpu: x86_64
> no commit associated with this build
> sizeof-long: 8
> sizeof-size_t: 8
> shell-path: /bin/sh
> Initialized empty Git repository in /tmp/issue3409/tst/repo.git/
> Cloning into '1'...
> warning: You appear to have cloned an empty repository.
> done.
> warning: LF will be replaced by CRLF in cr/foo.
> The file will have its original line endings in your working directory
> [master (root-commit) fc793f1] init
>  3 files changed, 11 insertions(+)
>  create mode 100644 cr/foo
>  create mode 100644 lf/.gitattributes
>  create mode 100644 lf/foo
> Enumerating objects: 6, done.
> Counting objects: 100% (6/6), done.
> Delta compression using up to 24 threads
> Compressing objects: 100% (3/3), done.
> Writing objects: 100% (6/6), 378 bytes | 378.00 KiB/s, done.
> Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
> To /tmp/issue3409/tst/repo.git
>  * [new branch]      master -> master
> Cloning into '2'...
> done.
> CR cr/foo
> LF lf/foo
> LF lf/.gitattributes
> warning: LF will be replaced by CRLF in cr/foo.
> The file will have its original line endings in your working directory
> [master 718534d] dummy
>  3 files changed, 3 insertions(+)
>
> +++ After commit and before diff
> CR cr/foo
> LF lf/foo
> LF lf/.gitattributes
>
> +++ Patches
> CR patch.lf-only
> CR patch.with
> CR patch.without
> Cloning into '3'...
> done.
>
> +++ patch w/o .gitattributes
> HEAD is now at fc793f1 init
> +++ After reset and before patch
> CR cr/foo
> LF lf/foo
> LF lf/.gitattributes
> +++ After patch
> CR cr/foo
> LF lf/foo
> LF lf/.gitattributes
>
> +++ patch with .gitattributes
> HEAD is now at fc793f1 init
> +++ After reset and before patch
> CR cr/foo
> LF lf/foo
> LF lf/.gitattributes
> +++ After patch
> CR cr/foo
> CR lf/foo
> CR lf/.gitattributes
>
> +++ patch no CR
> HEAD is now at fc793f1 init
> +++ After reset and before patch
> CR cr/foo
> LF lf/foo
> LF lf/.gitattributes
> +++ After patch
> CR cr/foo
> LF lf/foo
> LF lf/.gitattributes

      reply	other threads:[~2021-09-11  6:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-08  0:53 Git apply can convert LF file into CRLF when .gitattributes file is a part of a patch Mirochnik, Oleg V
2021-09-11  6:43 ` Torsten =?unknown-8bit?Q?B=C3=B6gershausen?= [this message]

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20210911064357.r7cpmxkt5w5davzb@tb-raspi4 \
    --to=tboegi@web.de \
    --cc=git@vger.kernel.org \
    --cc=oleg.v.mirochnik@intel.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).