threads / discuss / 55734

Fw: Tabs vs Spaces - Handle like CLRF?

Subject: Fw: Tabs vs Spaces - Handle like CLRF?

## tl;dr

2 messages between May 19, 2021 and May 19, 2021.

replies: 1people: 2as markdown or json

James Hughes· May 19, 2021, 15:55 UTC · lore
Hi all,
We have the ability to automagically handle CLRF issues when we commit and check-out to handle different dev environments.
A lot of us will also hold religious beliefs as to which is the correct way to indent, tabs or spaces.
Since it's simple a whitespacing issue, is there any reason we couldn't handle this in a similar way to CLRF? Give devs the choice to commit with tabs/spaces as per their organisations requirements and then convert to their preference on checkout?
All the best,
James
Jeff King· May 19, 2021, 16:28 UTC · re: James Hughes · lore

Re: Fw: Tabs vs Spaces - Handle like CLRF?

On Wed, May 19, 2021 at 03:55:46PM +0000, James Hughes wrote:
Show 10 quoted lines
> We have the ability to automagically handle CLRF issues when we commit
> and check-out to handle different dev environments.
> 
> A lot of us will also hold religious beliefs as to which is the
> correct way to indent, tabs or spaces.
> 
> Since it's simple a whitespacing issue, is there any reason we
> couldn't handle this in a similar way to CLRF? Give devs the choice to
> commit with tabs/spaces as per their organisations requirements and
> then convert to their preference on checkout?

You can. See clean/smudge filters in the gitattributes(5) manpage. You'd declare one of them the canonical in-repo format (let's say tabs). Then your "clean" filter would convert spaces-to-tabs, perhaps with something like "perl -pe 's/ {8}/\t/g'". And your "smudge" filter would convert tabs back to spaces.

And then you just mark the files you want converted with an attribute in .gitattributes, and wire up that attribute to the filters in your config.

-Peff

← back to recent threads