Regex for all files except .hg_keep

I use empty .hg_keepfiles to store some (otherwise empty) folders in Mercurial.

The problem is that I cannot find a working regular expression that excludes everything except files .hg_keep.

lets say that we have this structure:

a/b/c2/.hg_keep
a/b/c/d/.hg_keep
a/b/c/d/file1
a/b/c/d2/.hg_keep
a/b/.hg_keep
a/b/file2
a/b/file1
a/.hg_keep
a/file2
a/file1

and I want to save only files .hg_keepunder a/b/.

using http://gskinner.com/RegExr/ I created the following .hgignore:

syntax: regexp
.*b.*/(?!.*\.hg_keep)

but Mercurial ignores all .hg_keepfiles in subfolders b.

# hg status
? .hgignore
? a/.hg_keep
? a/b/.hg_keep
? a/file1
? a/file

# hg status -i
I a/b/c/d/.hg_keep
I a/b/c/d/file1
I a/b/c/d2/.hg_keep
I a/b/c2/.hg_keep
I a/b/file1
I a/b/file2

I know that I can hd addall files .hg_keep, but is there a solution with regex (or glob)?

+3
4

Regexp. , a/b/.hg_keep, , , :

^(?!a/b/\.hg_keep)$

, :

^                   anchor the match to the beginning of the file path
(?!  ... )          negation of the expression between '!' and ')'
a/b/\.hg_keep       the full path of the file you want to match
$                   anchor the match to the end of the file path

^a/b/\.hg_keep$

a/b/.hg_keep.

^(?!a/b/\.hg_keep)$

.

+3

, Regex, , , .hg_keep:

^.*\.hg_keep$

: , :

^(?:(?!.*\.hg_keep).)*$
+1

(?!.*/\.hg_keep$).

0

- . , , .

There is no easy way to ignore everything except a set of files. Attempting to use an inverted regex match will fail in combination with other patterns. This is a deliberate limitation, since all alternative formats are considered too likely to confuse users as additional flexibility.

Link: https://www.mercurial-scm.org/wiki/.hgignore

0
source

Source: https://habr.com/ru/post/1777055/


All Articles