git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jeff King <peff@peff.net>
Date
May 19, 2021, 16:28 UTC
Message-ID
<YKU8yMIO8uSuIYZh@coredump.intra.peff.net>
In-Reply-To
<GJHGZLcAwaihWwWmzAt8bdOKWi8JiupQxVUXCs1FwKTOmn2yvWEjI8DDTmDaBA48lzz4pGQ-JmwmHKSrEU2NCpdyxXW-ExqZcgxKEmL-454=@pyrosoftsolutions.co.uk>
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
Previous: James Hughes
Message 2 of 2 in “Fw: Tabs vs Spaces - Handle like CLRF?”
  1. James HughesMay 19, 2021
  2. Jeff KingMay 19, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.