How can I force line endings to LF in submodules via .gitattributes in the parent project?
Asked Answered
S

3

14

I've got a repository that stores all of my Vim settings. It uses submodules to pull in plugins with Pathogen (I've looked at other plugin managers, not interested so far).

Due to the way MSYSGit handles line endings when opening Vim for commit messages, I need to have the repository stored with Unix line endings (eol=lf).

I've tried adding a .gitattributes file in the main repo with the content:

* eol=lf
* text=auto

After refreshing the main repository using git rm --cached -r . and git reset --hard, the line endings in the main repo are now LF. Running the same commands inside of submodules, however, did not work.

How can configure my git repo so that submodules are checked out with LF line endings?

Senaidasenalda answered 10/9, 2015 at 15:41 Comment(2)
Did you find a solution to your problem ?Obstruent
I'm struggling with this too.. Did you find an answer?Frumpish
L
1

I cannot reproduce your scenario, but I suggest you to give a try to git config --global core.autocrlf input.

With the above instruction you force your system to handle any carriage return in unix format.

Here is a more detailed guide about it.

Lachrymator answered 6/9, 2021 at 10:49 Comment(0)
I
0

Your .gitattributes file only affects the current working tree according to the documentation:

...Git consults $GIT_DIR/info/attributes file (which has the highest precedence), .gitattributes file in the same directory as the path in question, and its parent directories up to the toplevel of the work tree").

The "work tree" is the directory that represents your repository. If you're in a submodule, its work tree doesn't include the parent repository, and so your file is being ignore.

The solution is probably to add the .gitattributes file to each subrepo - if you use a global file or configuration, it will be specific to you (as a user) rather than to your code.

Isidore answered 6/9, 2021 at 11:9 Comment(0)
R
0

You can set up a repo template with those settings

git config --global init.templatedir ~/.config/git/init.template
mkdir -p $_/info
printf %s\\n '* eol=lf' '* text=auto' >$_/attributes

then all new clones including the ones git submodule does for you will have those default attributes.

You can see the factory-default template at the slightly-misnamed /usr/share/git-core/templates.

I suppose if you wanted you could set init.templatedir in your vim repo, I haven't checked but seems to me that should work, should make a repo-local template for git submodule.

Rhodic answered 19/5, 2023 at 17:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.