9

I am writing some tools for git that make use of smudge/clean filters, and so I must create entries in the .gitattributes file.

Unfortunately, that file is parsed rather simply by splitting on whitespace, and so it is does not seem possible to me to include an explicit space character in the pattern.

I have been replacing whitespace characters with ?, which matches again zero or one characters.

Ergo, a pattern of has?spaces will match against my target filename of has spaces, but also hasspaces.

Is there a way to only match spaces, or am I stuck with the near-match?

Charles
  • 50,943
  • 13
  • 104
  • 142
Mike Boers
  • 6,665
  • 3
  • 31
  • 40

1 Answers1

8

You can try, as part of your pattern:

[[:space:]]
# as in
has[[:space:]]spaces

The gitattributes man page does mention an example with it.
And the pattern tests also include several examples:

match 1 x ' ' '[[:digit:][:upper:][:space:]]'
Mike Boers
  • 6,665
  • 3
  • 31
  • 40
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This does match against less things, but it could still grab (terribly named) files with tabs and newlines in them. Perhaps that is enough... – Mike Boers Sep 18 '13 at 16:14
  • @MikeBoers it should answer precisely the question you originally asked, though . – VonC Sep 18 '13 at 16:20
  • 1
    +1, using `[[:space:]]` or `[[:blank:]]` is currently probably the best workaround available. Perhaps we will eventually see [a _true_ fix for the issue](http://thread.gmane.org/gmane.comp.version-control.git/242176) in one of the next Git versions. – Chriki Apr 17 '14 at 08:44