Mercurial .hgignore exlude all files not '.txt' in all subfolders of specified folder

StackOverflow https://stackoverflow.com/questions/13118449

  •  15-07-2021
  •  | 
  •  

문제

having directory structure

foo
 -1.txt
 -1.notxt
 -bar
  -2.txt
  -3.notxt
  -sub
   -1.txt
   -2.txt
another-folders-and-files

Want to exclude all non-'.txt' files in folder foo and its subfolders. The most similar is this pattern:

^foo/(?!.*\.txt$)

But it exclude not only 1.notxt file from foo, but all subfolders too. I think, it because of bar is matches my exclusion pattern, but I do not understand how to say to hg not to ignore bar.

Any ideas?

도움이 되었습니까?

해결책

Unfortunately mercurial ignore patterns don't distinguish between files and directories; so if you ignore every name that doesn't end in .txt, you'll ignore directories too. But since directory names don't usually have a suffix, what you can do is ignore every name that has a suffix other than .txt, like this:

^foo/.*[^/]\.[^/]*$(?<!txt)

Breakdown:

^foo/.* any path in foo/; followed by

[^/]\. a period preceded by (at least) one non-slash character; followed by

[^/]*$, a path-final suffix; finally:

(?<!txt) check that there was no txt immediately before the end of the line.

This lets through names that begin with a period (.hgignore), and names containing no period at all (README). If you have files with no suffix you'll have to find another way to exclude them, but this should get you most of the way there. If you have directory names with dots in the middle, this will suppress them and you'll need to work harder to exclude them-- or change your approach.

(Incidentally, it's probably safer to have a long list of ignored suffixes, and add to it as necessary; soon enough the list will stabilize, and you won't risk ignoring something that shouldn't be.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top