0

I have a Git repository that several people are using. I want to enforce a spacing standard (no tabs, if any tabs are present, replace with 3 spaces). Is it possible to enforce this on the server-side (i.e. if someone pushes a file with a tab, have it converted to 3 spaces before it goes in)?

So far I've been trying to write a filter, and I have it working, but as far as I can tell, this is a client side solution.

I have a .gitattributes file checked into the repository with:

*.py filter=indent

And I've added the following to my config:

[filter "indent"]
    clean = sed -i -b 's/\t/   /g' %f
    smudge = dir

However, after much searching, I cannot find anyway to "check in" the config entries to the repository. In order for the filter to work, users need to manually add the entries to their config. Is there any way to force config settings for the repository for all users? Or is there some other way this could be done?

So far Can git automatically switch between spaces and tabs? has been were I've gotten most of my info.

Community
  • 1
  • 1
  • possible duplicate of [Can I specify .git/config values in a repo](http://stackoverflow.com/questions/26786778/can-i-specify-git-config-values-in-a-repo) – jthill Dec 11 '14 at 18:54
  • That answers my secondary question of whether or not I could achieve server-side spacing conventions with filters (answer: not really). So I guess that leaves me with looking into pre-commit hooks to achieve the desired effect? – Nate Swartzentruber Dec 11 '14 at 19:50
  • Others can enforce any standards they want in their own repos, and can make it drop-dead easy for you to adopt those standards in yours. You can do the same. Put the suggested config commands in the `README` and people can `vap:!sh` it in vim or `M-hM-|sh` in emacs or whatever, or put the commands in a setup script and they can just run it. – jthill Dec 11 '14 at 21:07
  • You can put a server side hook in that *detect* tabs and rejects those pushes. It would be up to the clients to redo their content to conform. – Andrew C Dec 12 '14 at 02:02

1 Answers1

0

Based on the comments and additional research, it appears Git's collaboration model makes it very difficult to force things on the server side.

My final solution was to use the filter I had and distribute a simple script for users to run to add the relevant configs to their system (as per the answer to Can I specify .git/config values in a repo).

Community
  • 1
  • 1