git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* proposal for improving gitignore syntax
@ 2020-04-23  8:04 Timothee Cour
  0 siblings, 0 replies; only message in thread
From: Timothee Cour @ 2020-04-23  8:04 UTC (permalink / raw)
  To: git

I'm facing a common problem with gitignore, see
https://stackoverflow.com/questions/61381438/how-to-gitignore-extension-less-files-without-breaking-a-global-gitignore
It doesn't seem to be possible to gitignore extension-less files (eg
posix binaries) without negative side effects, eg:
```
*
!/**/
!*.*
```
It's more complicated than it should and also doesn't work well, as it
will render a global gitignore useless.

This is just one of the problems with gitignore.

Such a common task should have an easy solution, and I'm wondering
whether gitignore can be improved to make this easy/possible.

Here's a concrete proposal. If 1st line contains `#
gitignore-syntax:v2`, it uses a new syntax, otherwise it uses existing
syntax, to ensure backward compatibility.
With the new syntax, strings enclosed inside parenthesis, eg (\w+)
denote regular expressions matching a single path component, with ^$
implied for each path component to match the entire component.

Regular expressions are forbidden to span across path components.
(\w+\.(md|txt))
Examples:
```
# gitignore-syntax:v2
# the line above enables the new syntax for this file

# this gitignores all extension-less files anywhere (:
([^.]+)
# this un-ignores files called README
!README

# this will gitignore for example /abc/foo.md
/*/((foo|bar)\.md)

# this will gitignore directories (bc trailing /) like ab/cd/foo/123/
**/(\w+)/(\d+)/
```

old tools like grep support regex so I'm assuming git could too, but
if for some reason that can't work (why?), some simplified version
could be supported to at least enable common cases without a full
blown regex engine, for example */([^.]+)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-23  8:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23  8:04 proposal for improving gitignore syntax Timothee Cour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).