Mercurial, stop the version cache directory, but save the directory

I have a CakePHP project under the control of Mercurial. Currently, all files in the app/tmp versioned, which always change.

I do not want to manage these files.

I know I can stop by running hg forget app/tmp/*

But it will also forget the file structure. Which I want to save.

Now I know that Mercurial does not support version directories, just files, but CakePHP people were also smart enough to put an empty file called empty in every empty directory (I think for this reason).

So what I want to say is Mercurial to forget every file in app/tmp , except for files whose name is definitely empty.

What is a team for?

+4
source share
4 answers

Well, if nothing works, you can always just ask Mercurial to forget everything, and then return empty before committing:

Here is how I reproduced it, first create an initial repo:

 hg init md app md app\tmp echo a>app\empty echo a>app\tmp\empty hg commit -m "initial" -A 

Then add some files that we later want to get rid of:

 echo a >app\tmp\test1.txt echo a >app\tmp\test2.txt hg commit -m "adding" -A 

Then forget the files we don’t need:

 hg forget app\tmp\* hg status <-- will show all 3 files hg revert app\tmp\empty hg status <-- now empty is gone echo glob:app/tmp>.hgignore hg commit -m "ignored" -A 

Please note that all .hgignore means that Mercurial does not detect new files during addremove or commit -A , if you explicitly tracked files matching your ignore filter, Mercurial will track changes to these files.

In other words, even if I asked Mercurial to ignore app/tmp above, the empty file inside will not be ignored or deleted, since I explicitly asked Mercurial to track it.
+3
source

At least theoretically (I don’t have time to try this right now), pattern matching should work with the hg forget command. So, you can do something like hg forget -X empty , and in the directory ( -X means "exclude").

You might want to use .hgignore, of course.

+3
source

Since you only need to do this, as soon as I do this:

 find app/tmp -type f | grep -v empty | xargs hg forget hg commit 

from now on, just put this in your `.hgignore '

 ^app/tmp 
+2
source

Mercurial has built-in support for globbing and regexes, as described in the corresponding chapter in the book of mercury. Used by python regex .

This should work for you:

 hg forget "re:app/tmp/.*(?<!/empty)$" 
0
source

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


All Articles