No: if you want to define a content filter driver (smudge/clean script) applied during the checkout of a submodule, it needs to be defined in a .gitattributes
stored within the submodule repo.
BUT: if you don't want to add a .gitattributes
to the submodule repo (because, for instance, you don't own that repo, you are only including it and want to apply a filter which makes sense in your context), what you can do is:
initialize the submodule (
git submodule init
or evengit submodule update --init
):
That will create in your parent repo a.git/modules/yourSubmodule
foldercopy in
.git/modules/yourSubmodule/info/attributes
the attributes you want to declare for certain files (here, fore instance, all ruby files)*.rb filter=yourFilter
That will play the role of the .gitattributes
(still valid only for the submodule, but defined and stored in your parent_repo/.git/modules/
)
That way, you can define attributes for a submodule without having to add a .gitattributes
within the submodule repo itself.
It isn't exactly a '.gitattributes
' of your parent repo: it is something you add after initializing a submodule, within the .git/modules
folder of your parent repo.
You can store the content of that "gitattributes" as a regular file in your parent repo, but you will have to write a script able to initialize submodule and copy that file as a .git/modules/yourSubmodule/info/attributes
file.
I have done so in my project: see this installation script as an example.
modify
.git/modules/yourSubmodule/config
in order to declare a smudge or clean filter referencing that script.[filter "yourFiler"] smudge= yourScript1 %f clean = yourScript2 %f
Then, providing you did already update your submodule (git submodule update
), running a
cd parentRepo/yourSubmodule
git checkout HEAD -- .
That will trigger your filter scripts for that submodule