5

I'm trying to address files without extensions in .gitattributes:

* text=auto
*. eol=lf
.py eol=lf

*. clearly doesn't help. git check-attr --all -- ./foo outputs:

./foo: text: auto

How can this be done?

3
  • *. means files that have a period as their last character. "Extensions" is a silly human notion, not something computers do. :-) So a file named foo is just "a file named foo" here, there's no notion of whether it has any extension. (This used to be different in the old DOS 8.3 fliename days, in MS-DOS and CP/M at least, where the names really were stored as "name, extension". But that stopped being true by the 1990s.) Commented Jun 28, 2017 at 16:54
  • @torek I guess this totally depends on how particular piece of software parses this silly human notion. This explains why this may not work in Git but not how it should be fixed. Commented Jun 28, 2017 at 17:10
  • Hence the comment rather than answer. I think for the moment you're stuck with zigam's method. In Mercurial, you can use regular expressions (which are more powerful than file glob notation and hence can detect file names that contain no periods), although Mercurial itself does not have the equivalent of .gitattributes in the first place. But Git doesn't have regular expression support on paths. Commented Jun 28, 2017 at 17:16

2 Answers 2

6

I think you have to set the value you want to all files, then remove the attribute for files with extension:

* text=auto eol=lf
*.* -eol # or set another default value
*.py eol=lf

It will give the result:

$ git check-attr --all -- file
file: text: auto
file: eol: crlf
$ git check-attr --all -- foo.py
foo.py: text: auto
foo.py: eol: lf
$ git check-attr --all -- bar.txt
bar.txt: text: auto
bar.txt: eol: unset
Sign up to request clarification or add additional context in comments.

2 Comments

I need to set eol=lf only on *. and *.py. Not on *.*. That's why the question was asked.
Oh, my bad. I'll fix my answer.
0

This looks like a missing facility in .gitattributes.

In gitignore, you can use the ! operator, as mentioned in How do I add files without dots in them (all extension-less files) to the gitignore file? but gitattributes does not support !.

It's not clear how ! would work in .gitattributes: they may need to add an 'exclude' operation of some sort.

not/valid/yet/* exclude=.

Comments

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.