git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] submodule: Tolerate auto/safecrlf when adding .gitmodules

From
Jeff King <peff@peff.net>
Date
Jun 20, 2012, 19:11 UTC
Message-ID
<20120620191132.GB31520@sigill.intra.peff.net>
In-Reply-To
<4FE21133.2030001@kitware.com>
On Wed, Jun 20, 2012 at 02:06:43PM -0400, Brad King wrote:
Show 16 quoted lines
> > Hmm, I have no objections against the intention of the patch. But
> > as I understand it this message will reoccur when the user e.g.
> > edits the .gitmodules file later with any editor who just writes
> > lfs and adds it.
> > 
> > I don't know terribly much about crlf support but maybe flagging
> > the .gitmodules file in .gitattributes would be a better solution
> > here? Opinions?
> 
> Once a user edits the file with an outside tool it is his/her
> responsibility to add .gitattributes for the file.  In the reported
> case Git is creating the file and already knows the crlf mode when
> creating it.
> 
> I think Junio's proposal to teach "git config" to respect crlf
> configuration is a more general solution.

I don't think so. It should not be an issue at all that .gitmodules has CRLF or even mixed line endings; the config parser knows that its input is a text file and ignores the CRs already.

The only problem is when adding the file, because git is not aware that .gitmodules is, by definition, a text file. The point of safecrlf was to prevent accidents with files which are really binary, or for which mixed line endings must be preserved; .gitmodules is not such a file. We know that, but we never tell git.

We can paper over the problem by normalizing line endings when config writes it out, but that does not cover the case of somebody editing it manually and introducing mixed line endings. Nor does it help if somebody checks in a .gitmodules file with CRLF, which we then checkout on a LF-based system. Or if we do a merge between two versions with different line endings.

The only sane thing is to have a canonical in-repo representation. Fortunately we already have the infrastructure for that, and in theory it should be as easy as adding ".gitmodules text" to our built-in gitattributes (you could even do "eol=lf", but I don't see a reason not to respect the native line endings in the working tree, given that git can handle the CRLFs just fine).

I say "in theory" there because I am not sure whether specifying a file as definitely text via attributes will actually suppress the safecrlf check or not. IMHO, it should, since safecrlf is really about preventing false positives via autocrlf or text=auto.

I don't see any reason for each individual repo to have to add these attributes manually. This is a git-specific file, and the format is dictated by git. We know that it's a text file, so why not help out the user? We should possibly do the same thing for .gitattributes and .gitignore.

-Peff
Previous: Jens LehmannNext: Junio C Hamano
Message 7 of 12 in “submodule add + autocrlf + safecrlf”
  1. 0/2 submodule add + autocrlf + safecrlfBrad King, Jun 20, 2012
  2. 1/2 submodule: Demonstrate failure to add with auto/safecrlfBrad King, Jun 20, 2012
  3. 2/2 submodule: Tolerate auto/safecrlf when adding .gitmodulesBrad King, Jun 20, 2012
  4. Jens LehmannJun 20, 2012
  5. Brad KingJun 20, 2012
  6. Jens LehmannJun 20, 2012
  7. Jeff KingJun 20, 2012
  8. Junio C HamanoJun 20, 2012
  9. Jens LehmannJun 21, 2012
  10. Junio C HamanoJun 20, 2012
  11. Brad KingJun 20, 2012
  12. Junio C HamanoJun 20, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.