0

I have a vim plugin that draws indentation lines similar to Sublime Text, but it requires whitespace to be represented as tabs. Complicating things, ideologically, I think spaces are preferable for the repository.

So, right now, I'm using vim to convert spaces to tab on write, which is computationally expensive and has started to slow down editing.

Is it possible for git to convert spaces to tabs on checkout/pull/merge and convert from tabs to spaces pre-commit?

Thanks

6
  • 5
    Tools are tools, don't let them dictate your workflow. Especially in the name of eye candy. Also, vim-indent-guides supports both tabs and spaces. Commented May 23, 2014 at 20:05
  • Your files must be very large, or your computer very slow to have a simple global substitution "slow down editing" (rather, opening and writing, isn't it?!) Do you really think a Git / external solution is that much faster? Have you actually reduced the performance problem to the substitution? (which you do how?) Commented May 23, 2014 at 20:09
  • 1
    Linux usually has two utilities expressly for this purpose - called expand and unexpand... Commented May 23, 2014 at 20:36
  • @romainl I don't particularly like vim-indent-guides implementation, but forking it is an interesting thought. Commented May 23, 2014 at 23:38
  • 1
    Again, you should have included your conversion implementation, because a :substitute doesn't behave the "I can watch it work" way you describe; i.e. there are no interim screen updates. Commented May 24, 2014 at 8:06

1 Answer 1

4

You could do it using .gitattributes, see the smudge/clean concept in the git book. You can create filters that convert the files on commit and checkout.

In .gitattributes, configure what files should be affected by your filter

* filter=spacetabs

On command line, tell what scripts should be run for filtering the files:

$ git config --global filter.spacetabs.clean tabs-to-spaces-script
$ git config --global filter.spacetabs.smudge spaces-to-tabs-script

Another possibility could be git hooks. Add conversion scripts that run on commit and checkout. But .gitattributes are probably more appropriate for this scenario.

Sign up to request clarification or add additional context in comments.

3 Comments

.gitattributes was my first thought, but there's no way to define one filter for commits and another for pulls, is there?
@seagoj one filter maps to to two different scripts tabs-to-spaces-script and spaces-to-tabs-script.
@seagoj if you are asking for a filter to run on pull rather than checkout, that is not really necessary. You only care what the file looks like once you have checked it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.