1

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

Justin
  • 447
  • 4
  • 10
  • 33
  • 1
    I knew my old answer had to be involved. Is there any case issue? (.ccp vs. .CPP)? – VonC Mar 15 '18 at 06:01
  • All our files are lowercase, so there is no mix there or casing issue. I tried .CPP filter to rule this out, no change in behaviour. I am running latest git for windows as well. – Justin Mar 15 '18 at 15:15
  • Can you check in a CMD session with a simplified PATH as in https://stackoverflow.com/a/49248983/6309? Are you using git bash or the regular CMD? – VonC Mar 15 '18 at 15:17
  • I'm using git bash. I've setup a simplified PATH cmd window as you linked. git bash is not a recognized command there. git checkout HEAD -- "$(git rev-parse --show-toplevel)" gives the error error: pathspec '$(git rev-parse --show-toplevel)' did not match any file(s) known to git. I'll keep trying things, but I wanted to reply ASAP. – Justin Mar 15 '18 at 15:28
  • git checkout HEAD -- from that simplified PATH cmd shell yielded the same result (smudge not applied to cpp file). – Justin Mar 15 '18 at 15:34
  • From a CMD or bash session? – VonC Mar 15 '18 at 16:01
  • Can you try also on a fresh clone? – VonC Mar 15 '18 at 16:01
  • Thanks for your help. From a CMD. Trying a fresh clone now. – Justin Mar 15 '18 at 16:21
  • Cloning into a new repository did workaround the problem. I will use the new repo for the time being. – Justin Mar 15 '18 at 17:00
  • Great! I have included an answer to that effect. – VonC Mar 15 '18 at 17:02

1 Answers1

1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ensure the .gitattributes are set properly in all relevant branches before doing the new clone! – Justin Mar 15 '18 at 17:32