Justin
Justin

Reputation: 507

git smudge not applied to specific file types

I have followed the below guide in order to setup smudge and clean to use tabs locally and commit with spaces. The issue I'm seeing now is that smudge is not applied to all desired filetypes. If I checkout an .xml, .proto or .build file, the filter is applied and the smudge occurs, so the spaces are changed to tabs. If I try to checkout a .cpp or .h file, the filter is not applied and smudge does not happen.

Note that I did already have the repo at head on my machine here before setting up the filter. Solutions for that are to checkout each file in the repo. I've tried that with various commands and deleting .git/index but that did not work. The problem seems to be that smudge is not applied to certain file types since it is partially working.

Does anyone know what I might be missing or what the problem is? I'm on windows 10 with this version of unexpand. I'm able to confirm that the filter is not applied by renaming the smudge "unexpand" command to something invalid to trigger an error message. I do see the error message for some filetypes but not for others.

$ unexpand --version
unexpand (GNU coreutils) 8.26
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David MacKenzie.

in my .gitconfig, I've specified the filter

[filter "tab2spaces"]
smudge = unexpand --tabs=4 --first-only
clean = expand --tabs=4 --initial

in my .gitattributes, I've specified the filetypes it should apply to, including .cpp and .h.

*.cpp               filter=tab2spaces
*.java              filter=tab2spaces
*.m                 filter=tab2spaces
*.mm                filter=tab2spaces
*.c                 filter=tab2spaces
*.cc                filter=tab2spaces
*.hpp               filter=tab2spaces
*.h                 filter=tab2spaces
*.xml               filter=tab2spaces
*.proto             filter=tab2spaces
*.build             filter=tab2spaces

Here is the setup document I used Can git automatically switch between spaces and tabs?

Here is the other solution I tried git: re-checkout files after creating smudge filter

Upvotes: 1

Views: 320

Answers (1)

VonC
VonC

Reputation: 1326616

In case resetting the index does not work, a workaround would be to re-clone the repo.

Then, in that new clone, you can check the .gitattributes rules does apply.

As commented below by the OP:

Ensure the .gitattributes are set properly in all relevant branches before doing the new clone.

Upvotes: 1

Related Questions