git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* core.safecrlf warning is confusing[improvement suggestion?]
@ 2017-11-21  5:18 Vladimir Nikishkin
  2017-11-21  5:44 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Vladimir Nikishkin @ 2017-11-21  5:18 UTC (permalink / raw)
  To: git

Hello, everyone.

I have the following question.

So I have a fresh git repository after git init, on Windows.

core.autocrlf is true explicitly, and core.safecrlf is true implicitly.

I want to have LF line endings in the repository and CRLF endings in
the working copy. (Because I use windows-exclusive tools to develop.)

But for start I have my code with LF endings, because I got it from a
fellow developer, who develops on UNIX, with LF line endings.

What I expect git to do:
Commit files as is (LF), keep my files in the working directory with
LF, but after issuing 'git checkout master' have them converted to
CRLF (since this is a checkout procedure).

So I put the source in the working directory and tell git to make

git diff --stat

and I see the (ambiguous) warnings:

'warning: LF will be replaced by CRLF in filename.m.
The file will have its original line endings in you working directory.'

How I read them: "even though you have core.autocrlf=true, LF will be
replaced by CRLF and the repository will store CRLF files. However,
after you checkout them again, the CRLFs will be converted back to
LF(because the files will have original line endings in the working
directory.)"

 I feel like it's the opposite of what is actually happening.

So, would it make sense to change the warning message to? :

'warning: When you next checkout this commit, your code will have CRLF
line endings. However, right now your files will not be altered.'

-- 
Yours sincerely, Vladimir Nikishkin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: core.safecrlf warning is confusing[improvement suggestion?]
  2017-11-21  5:18 core.safecrlf warning is confusing[improvement suggestion?] Vladimir Nikishkin
@ 2017-11-21  5:44 ` Junio C Hamano
  2017-11-21  5:49 ` Junio C Hamano
  2017-11-21 16:18 ` Torsten Bögershausen
  2 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2017-11-21  5:44 UTC (permalink / raw)
  To: Vladimir Nikishkin; +Cc: git

Vladimir Nikishkin <lockywolf@gmail.com> writes:

> So I put the source in the working directory and tell git to make
>
> git diff --stat
>
> and I see the (ambiguous) warnings:
>
> 'warning: LF will be replaced by CRLF in filename.m.
> The file will have its original line endings in you working directory.'
>
> How I read them: "even though you have core.autocrlf=true, LF will be
> replaced by CRLF and the repository will store CRLF files. However,
> after you checkout them again, the CRLFs will be converted back to
> LF(because the files will have original line endings in the working
> directory.)"
>
>  I feel like it's the opposite of what is actually happening.
>
> So, would it make sense to change the warning message to? :
>
> 'warning: When you next checkout this commit, your code will have CRLF
> line endings. However, right now your files will not be altered.'

I actually think "git diff" should not be triggering the warning
message.  The message may be appropriate when you are doing "git
add", at which point the "will be replaced and that may not be what
you want to see" warning might apply, but "diff" is doing a read-only
thing and will not be replacing anything with any other thing.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: core.safecrlf warning is confusing[improvement suggestion?]
  2017-11-21  5:18 core.safecrlf warning is confusing[improvement suggestion?] Vladimir Nikishkin
  2017-11-21  5:44 ` Junio C Hamano
@ 2017-11-21  5:49 ` Junio C Hamano
  2017-11-21 16:18 ` Torsten Bögershausen
  2 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2017-11-21  5:49 UTC (permalink / raw)
  To: Vladimir Nikishkin; +Cc: git

Vladimir Nikishkin <lockywolf@gmail.com> writes:

> I want to have LF line endings in the repository and CRLF endings in
> the working copy. (Because I use windows-exclusive tools to develop.)
>
> But for start I have my code with LF endings, because I got it from a
> fellow developer, who develops on UNIX, with LF line endings.

I somehow suspect that perhaps the way you "got it" from the other
developer is wrong in the first place.  Did you make a zip archive
or something and extracted it?  That's a wrong way to do a hand-off.

If you "git clone" to have your own copy from the other developer,
then your working tree files will follow what your local convention
is.  Also you do not have to worry about malicious commands left
inside .git/config when you made a bit-for-bit copy of the
repository and the working tree.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: core.safecrlf warning is confusing[improvement suggestion?]
  2017-11-21  5:18 core.safecrlf warning is confusing[improvement suggestion?] Vladimir Nikishkin
  2017-11-21  5:44 ` Junio C Hamano
  2017-11-21  5:49 ` Junio C Hamano
@ 2017-11-21 16:18 ` Torsten Bögershausen
  2017-11-22  2:01   ` Junio C Hamano
  2 siblings, 1 reply; 6+ messages in thread
From: Torsten Bögershausen @ 2017-11-21 16:18 UTC (permalink / raw)
  To: Vladimir Nikishkin; +Cc: git

On Tue, Nov 21, 2017 at 01:18:30PM +0800, Vladimir Nikishkin wrote:
> Hello, everyone.
> 
> I have the following question.
> 
> So I have a fresh git repository after git init, on Windows.
> 
> core.autocrlf is true explicitly, and core.safecrlf is true implicitly.
> 
> I want to have LF line endings in the repository and CRLF endings in
> the working copy. (Because I use windows-exclusive tools to develop.)

Side note: If you ever want to push your repository somewhere,
it would be good practice to have a .gitattributes file:

echo "* text=auto" >>.gitattributes
git add .gitattributes
git commit -m "add .gitattributes"

This can be useful if the repo is pulled to a person who has
core.autocrlf=false, if case [s]he is creating files with CRLF in the
worktree.

> 
> But for start I have my code with LF endings, because I got it from a
> fellow developer, who develops on UNIX, with LF line endings.
> 
> What I expect git to do:
> Commit files as is (LF), keep my files in the working directory with
> LF, but after issuing 'git checkout master' have them converted to
> CRLF (since this is a checkout procedure).
> 
> So I put the source in the working directory and tell git to make
> 
> git diff --stat

As Junio pointed out, it is probably not git diff saying this ?

Typically "git add" gives the warning.

>
> and I see the (ambiguous) warnings:
> 
> 'warning: LF will be replaced by CRLF in filename.m.
> The file will have its original line endings in you working directory.'
> 
> How I read them: "even though you have core.autocrlf=true, LF will be
> replaced by CRLF and the repository will store CRLF files. However,
> after you checkout them again, the CRLFs will be converted back to
> LF(because the files will have original line endings in the working
> directory.)"
> 
>  I feel like it's the opposite of what is actually happening.
> 
> So, would it make sense to change the warning message to? :
> 
> 'warning: When you next checkout this commit, your code will have CRLF
> line endings. However, right now your files will not be altered.'

I could agree.
Do you want to send a patch for this ?
(The code to be changd is in convert.c, plus some test cases)

> 
> -- 
> Yours sincerely, Vladimir Nikishkin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: core.safecrlf warning is confusing[improvement suggestion?]
  2017-11-21 16:18 ` Torsten Bögershausen
@ 2017-11-22  2:01   ` Junio C Hamano
  2017-11-22 14:56     ` Torsten Bögershausen
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2017-11-22  2:01 UTC (permalink / raw)
  To: Torsten Bögershausen; +Cc: Vladimir Nikishkin, git

Torsten Bögershausen <tboegi@web.de> writes:

>> I want to have LF line endings in the repository and CRLF endings in
>> the working copy. (Because I use windows-exclusive tools to develop.)
>
> Side note: If you ever want to push your repository somewhere,
> it would be good practice to have a .gitattributes file:
> ...

Now we got your attention ;-)

What would be the BCP we would give if somebody has just a tarball
without .git that has LF endings?

    $ git init a-project
    $ cd a-project
    $ tar xf ../a-project.tar
    $ git add .
    $ git commit -m 'Initial import'

would achieve one half of the original wish (i.e. "I want to end up
with repository data in LF eol"); disabling the "safe crlf" before
running that "git add ." step may also not be a bad idea, because it
reduces the number of things that can get in the way by one.

But the above also leaves the "working tree" files in LF eol
(i.e. it goes against "I want to work with CRLF in my working
tree").  What would be our recommendation?

One big-hammer way I can think of is

    $ git rm -f .
    $ git reset --hard

and that actually may be a good enough solution, given that you'd be
doing this just once at the beginning of "your" project that starts
from an inherited code drop.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: core.safecrlf warning is confusing[improvement suggestion?]
  2017-11-22  2:01   ` Junio C Hamano
@ 2017-11-22 14:56     ` Torsten Bögershausen
  0 siblings, 0 replies; 6+ messages in thread
From: Torsten Bögershausen @ 2017-11-22 14:56 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Vladimir Nikishkin, git

On Wed, Nov 22, 2017 at 11:01:22AM +0900, Junio C Hamano wrote:
> Torsten Bögershausen <tboegi@web.de> writes:
> 
> >> I want to have LF line endings in the repository and CRLF endings in
> >> the working copy. (Because I use windows-exclusive tools to develop.)
> >
> > Side note: If you ever want to push your repository somewhere,
> > it would be good practice to have a .gitattributes file:
> > ...
> 
> Now we got your attention ;-)
> 
> What would be the BCP we would give if somebody has just a tarball
> without .git that has LF endings?
> 
>     $ git init a-project
>     $ cd a-project
>     $ tar xf ../a-project.tar
>     $ git add .
>     $ git commit -m 'Initial import'

There is room for small improvements:
     $ cd /tmp
     $ git init a-project
     $ cd a-project
     $ tar xf ../a-project.tar
     $ git -c core.autocrlf=false add .
     $ git commit -m 'Initial import'
     # Make up your mind: is it truly cross-platform ?
       $ echo "* text=auto" >.gitattributes
       # E.g. if you have shell scripts:
       $ echo "*.sh text eol=lf" >>.gitattributes
       # E.g. if you are a git developer:
       $ echo "/GIT-VERSION-GEN eol=lf" >>.gitattributes   
      # Or, is it e.g. a project where a tool needs some line endings
      # visual studio is one example, there are many others:
       $ echo "* -text" >.gitattributes
      # in any case, we need to commit: 
      $ git add .gitattributes && git commit -m "Add .gitattributes"

# Now we have the repo. I we don't want the hammer, simply clone it:
     $ cd $HOME
     $ git clone /tmp/a-project

That should work for project small enough not to fill the disk.
And other adjustments may be needed to the .gitattributes file.
A final check with
$ git ls-files --eol
may give inspiration.

> 
> would achieve one half of the original wish (i.e. "I want to end up
> with repository data in LF eol"); disabling the "safe crlf" before
> running that "git add ." step may also not be a bad idea, because it
> reduces the number of things that can get in the way by one.
> 
> But the above also leaves the "working tree" files in LF eol
> (i.e. it goes against "I want to work with CRLF in my working
> tree").  What would be our recommendation?
> 
> One big-hammer way I can think of is
> 
>     $ git rm -f .
>     $ git reset --hard
> 
> and that actually may be a good enough solution, given that you'd be
> doing this just once at the beginning of "your" project that starts
> from an inherited code drop.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-11-22 14:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-21  5:18 core.safecrlf warning is confusing[improvement suggestion?] Vladimir Nikishkin
2017-11-21  5:44 ` Junio C Hamano
2017-11-21  5:49 ` Junio C Hamano
2017-11-21 16:18 ` Torsten Bögershausen
2017-11-22  2:01   ` Junio C Hamano
2017-11-22 14:56     ` Torsten Bögershausen

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).