{"thread":{"id":"47263","subject":"core.safecrlf warning is confusing[improvement suggestion?]","startedAt":"2017-11-21T05:18:36Z","lastAt":"2017-11-22T14:56:46Z","messageCount":6,"participants":["Vladimir Nikishkin","Junio C Hamano","Torsten Bögershausen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"333046","messageId":"CA+A2iZaLZCMvyb3nbcn=ofVGAPeW2_wRhjOeRRu5q01LuV++Gw@mail.gmail.com","threadId":"47263","inReplyTo":null,"subject":"core.safecrlf warning is confusing[improvement suggestion?]","fromName":"Vladimir Nikishkin","fromEmail":"lockywolf@gmail.com","sentAt":"2017-11-21T05:18:30Z","receivedAt":"2017-11-21T05:18:36Z","isPatch":false,"sender":{"key":"lockywolf@gmail.com","avatar":"https://gravatar.com/avatar/ad26382c012afbd65a5b832ad7d98d62350a63454e2e891f80c7ea987fac749c?d=mp&s=160"},"body":"Hello, everyone.\n\nI have the following question.\n\nSo I have a fresh git repository after git init, on Windows.\n\ncore.autocrlf is true explicitly, and core.safecrlf is true implicitly.\n\nI want to have LF line endings in the repository and CRLF endings in\nthe working copy. (Because I use windows-exclusive tools to develop.)\n\nBut for start I have my code with LF endings, because I got it from a\nfellow developer, who develops on UNIX, with LF line endings.\n\nWhat I expect git to do:\nCommit files as is (LF), keep my files in the working directory with\nLF, but after issuing 'git checkout master' have them converted to\nCRLF (since this is a checkout procedure).\n\nSo I put the source in the working directory and tell git to make\n\ngit diff --stat\n\nand I see the (ambiguous) warnings:\n\n'warning: LF will be replaced by CRLF in filename.m.\nThe file will have its original line endings in you working directory.'\n\nHow I read them: \"even though you have core.autocrlf=true, LF will be\nreplaced by CRLF and the repository will store CRLF files. However,\nafter you checkout them again, the CRLFs will be converted back to\nLF(because the files will have original line endings in the working\ndirectory.)\"\n\n I feel like it's the opposite of what is actually happening.\n\nSo, would it make sense to change the warning message to? :\n\n'warning: When you next checkout this commit, your code will have CRLF\nline endings. However, right now your files will not be altered.'\n\n-- \nYours sincerely, Vladimir Nikishkin\n"},{"id":"333049","messageId":"xmqqo9nwi3tn.fsf@gitster.mtv.corp.google.com","threadId":"47263","inReplyTo":"CA+A2iZaLZCMvyb3nbcn=ofVGAPeW2_wRhjOeRRu5q01LuV++Gw@mail.gmail.com","subject":"Re: core.safecrlf warning is confusing[improvement suggestion?]","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-11-21T05:44:04Z","receivedAt":"2017-11-21T05:44:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Vladimir Nikishkin <lockywolf@gmail.com> writes:\n\n> So I put the source in the working directory and tell git to make\n>\n> git diff --stat\n>\n> and I see the (ambiguous) warnings:\n>\n> 'warning: LF will be replaced by CRLF in filename.m.\n> The file will have its original line endings in you working directory.'\n>\n> How I read them: \"even though you have core.autocrlf=true, LF will be\n> replaced by CRLF and the repository will store CRLF files. However,\n> after you checkout them again, the CRLFs will be converted back to\n> LF(because the files will have original line endings in the working\n> directory.)\"\n>\n>  I feel like it's the opposite of what is actually happening.\n>\n> So, would it make sense to change the warning message to? :\n>\n> 'warning: When you next checkout this commit, your code will have CRLF\n> line endings. However, right now your files will not be altered.'\n\nI actually think \"git diff\" should not be triggering the warning\nmessage.  The message may be appropriate when you are doing \"git\nadd\", at which point the \"will be replaced and that may not be what\nyou want to see\" warning might apply, but \"diff\" is doing a read-only\nthing and will not be replacing anything with any other thing.\n"},{"id":"333050","messageId":"xmqqk1yki3kj.fsf@gitster.mtv.corp.google.com","threadId":"47263","inReplyTo":"CA+A2iZaLZCMvyb3nbcn=ofVGAPeW2_wRhjOeRRu5q01LuV++Gw@mail.gmail.com","subject":"Re: core.safecrlf warning is confusing[improvement suggestion?]","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-11-21T05:49:32Z","receivedAt":"2017-11-21T05:49:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Vladimir Nikishkin <lockywolf@gmail.com> writes:\n\n> I want to have LF line endings in the repository and CRLF endings in\n> the working copy. (Because I use windows-exclusive tools to develop.)\n>\n> But for start I have my code with LF endings, because I got it from a\n> fellow developer, who develops on UNIX, with LF line endings.\n\nI somehow suspect that perhaps the way you \"got it\" from the other\ndeveloper is wrong in the first place.  Did you make a zip archive\nor something and extracted it?  That's a wrong way to do a hand-off.\n\nIf you \"git clone\" to have your own copy from the other developer,\nthen your working tree files will follow what your local convention\nis.  Also you do not have to worry about malicious commands left\ninside .git/config when you made a bit-for-bit copy of the\nrepository and the working tree.\n\n"},{"id":"333106","messageId":"20171121161824.GA13548@tor.lan","threadId":"47263","inReplyTo":"CA+A2iZaLZCMvyb3nbcn=ofVGAPeW2_wRhjOeRRu5q01LuV++Gw@mail.gmail.com","subject":"Re: core.safecrlf warning is confusing[improvement suggestion?]","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2017-11-21T16:18:24Z","receivedAt":"2017-11-21T16:18:34Z","isPatch":false,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On Tue, Nov 21, 2017 at 01:18:30PM +0800, Vladimir Nikishkin wrote:\n> Hello, everyone.\n> \n> I have the following question.\n> \n> So I have a fresh git repository after git init, on Windows.\n> \n> core.autocrlf is true explicitly, and core.safecrlf is true implicitly.\n> \n> I want to have LF line endings in the repository and CRLF endings in\n> the working copy. (Because I use windows-exclusive tools to develop.)\n\nSide note: If you ever want to push your repository somewhere,\nit would be good practice to have a .gitattributes file:\n\necho \"* text=auto\" >>.gitattributes\ngit add .gitattributes\ngit commit -m \"add .gitattributes\"\n\nThis can be useful if the repo is pulled to a person who has\ncore.autocrlf=false, if case [s]he is creating files with CRLF in the\nworktree.\n\n> \n> But for start I have my code with LF endings, because I got it from a\n> fellow developer, who develops on UNIX, with LF line endings.\n> \n> What I expect git to do:\n> Commit files as is (LF), keep my files in the working directory with\n> LF, but after issuing 'git checkout master' have them converted to\n> CRLF (since this is a checkout procedure).\n> \n> So I put the source in the working directory and tell git to make\n> \n> git diff --stat\n\nAs Junio pointed out, it is probably not git diff saying this ?\n\nTypically \"git add\" gives the warning.\n\n>\n> and I see the (ambiguous) warnings:\n> \n> 'warning: LF will be replaced by CRLF in filename.m.\n> The file will have its original line endings in you working directory.'\n> \n> How I read them: \"even though you have core.autocrlf=true, LF will be\n> replaced by CRLF and the repository will store CRLF files. However,\n> after you checkout them again, the CRLFs will be converted back to\n> LF(because the files will have original line endings in the working\n> directory.)\"\n> \n>  I feel like it's the opposite of what is actually happening.\n> \n> So, would it make sense to change the warning message to? :\n> \n> 'warning: When you next checkout this commit, your code will have CRLF\n> line endings. However, right now your files will not be altered.'\n\nI could agree.\nDo you want to send a patch for this ?\n(The code to be changd is in convert.c, plus some test cases)\n\n> \n> -- \n> Yours sincerely, Vladimir Nikishkin\n"},{"id":"333219","messageId":"xmqqine3xea5.fsf@gitster.mtv.corp.google.com","threadId":"47263","inReplyTo":"20171121161824.GA13548@tor.lan","subject":"Re: core.safecrlf warning is confusing[improvement suggestion?]","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-11-22T02:01:22Z","receivedAt":"2017-11-22T02:01:36Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Torsten Bögershausen <tboegi@web.de> writes:\n\n>> I want to have LF line endings in the repository and CRLF endings in\n>> the working copy. (Because I use windows-exclusive tools to develop.)\n>\n> Side note: If you ever want to push your repository somewhere,\n> it would be good practice to have a .gitattributes file:\n> ...\n\nNow we got your attention ;-)\n\nWhat would be the BCP we would give if somebody has just a tarball\nwithout .git that has LF endings?\n\n    $ git init a-project\n    $ cd a-project\n    $ tar xf ../a-project.tar\n    $ git add .\n    $ git commit -m 'Initial import'\n\nwould achieve one half of the original wish (i.e. \"I want to end up\nwith repository data in LF eol\"); disabling the \"safe crlf\" before\nrunning that \"git add .\" step may also not be a bad idea, because it\nreduces the number of things that can get in the way by one.\n\nBut the above also leaves the \"working tree\" files in LF eol\n(i.e. it goes against \"I want to work with CRLF in my working\ntree\").  What would be our recommendation?\n\nOne big-hammer way I can think of is\n\n    $ git rm -f .\n    $ git reset --hard\n\nand that actually may be a good enough solution, given that you'd be\ndoing this just once at the beginning of \"your\" project that starts\nfrom an inherited code drop.\n"},{"id":"333278","messageId":"20171122145632.GA22931@tor.lan","threadId":"47263","inReplyTo":"xmqqine3xea5.fsf@gitster.mtv.corp.google.com","subject":"Re: core.safecrlf warning is confusing[improvement suggestion?]","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2017-11-22T14:56:32Z","receivedAt":"2017-11-22T14:56:46Z","isPatch":false,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On Wed, Nov 22, 2017 at 11:01:22AM +0900, Junio C Hamano wrote:\n> Torsten Bögershausen <tboegi@web.de> writes:\n> \n> >> I want to have LF line endings in the repository and CRLF endings in\n> >> the working copy. (Because I use windows-exclusive tools to develop.)\n> >\n> > Side note: If you ever want to push your repository somewhere,\n> > it would be good practice to have a .gitattributes file:\n> > ...\n> \n> Now we got your attention ;-)\n> \n> What would be the BCP we would give if somebody has just a tarball\n> without .git that has LF endings?\n> \n>     $ git init a-project\n>     $ cd a-project\n>     $ tar xf ../a-project.tar\n>     $ git add .\n>     $ git commit -m 'Initial import'\n\nThere is room for small improvements:\n     $ cd /tmp\n     $ git init a-project\n     $ cd a-project\n     $ tar xf ../a-project.tar\n     $ git -c core.autocrlf=false add .\n     $ git commit -m 'Initial import'\n     # Make up your mind: is it truly cross-platform ?\n       $ echo \"* text=auto\" >.gitattributes\n       # E.g. if you have shell scripts:\n       $ echo \"*.sh text eol=lf\" >>.gitattributes\n       # E.g. if you are a git developer:\n       $ echo \"/GIT-VERSION-GEN eol=lf\" >>.gitattributes   \n      # Or, is it e.g. a project where a tool needs some line endings\n      # visual studio is one example, there are many others:\n       $ echo \"* -text\" >.gitattributes\n      # in any case, we need to commit: \n      $ git add .gitattributes && git commit -m \"Add .gitattributes\"\n\n# Now we have the repo. I we don't want the hammer, simply clone it:\n     $ cd $HOME\n     $ git clone /tmp/a-project\n\nThat should work for project small enough not to fill the disk.\nAnd other adjustments may be needed to the .gitattributes file.\nA final check with\n$ git ls-files --eol\nmay give inspiration.\n\n> \n> would achieve one half of the original wish (i.e. \"I want to end up\n> with repository data in LF eol\"); disabling the \"safe crlf\" before\n> running that \"git add .\" step may also not be a bad idea, because it\n> reduces the number of things that can get in the way by one.\n> \n> But the above also leaves the \"working tree\" files in LF eol\n> (i.e. it goes against \"I want to work with CRLF in my working\n> tree\").  What would be our recommendation?\n> \n> One big-hammer way I can think of is\n> \n>     $ git rm -f .\n>     $ git reset --hard\n> \n> and that actually may be a good enough solution, given that you'd be\n> doing this just once at the beginning of \"your\" project that starts\n> from an inherited code drop.\n"}]}