Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial, stop versioning cache directory but keep directory

I have a CakePHP project under Mercurial version control. Right now all the files in the app/tmp directory are being versioned, which are always changing.

I do not want to version control these files.

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

But this will also forget the file structure. Which I want to keep.

Now I know that Mercurial doesn't version directories, just files, but the CakePHP folks were also smart enough to put an empty file called empty in every empty directory (I am guessing for this reason).

So what I want to do is tell Mercurial to forget every file under app/tmp except files whos name is exactly empty.

What would the command be for this?

like image 224
JD Isaacks Avatar asked Feb 26 '23 04:02

JD Isaacks


2 Answers

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

Here's how I reproduced it, first create 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 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 want:

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

Note that all .hgignore does is to prevent Mercurial from discovering new files during addremove or commit -A, if you have explicitly tracked files that match your ignore filter, Mercurial will still track changes to those files.

In other words, even though I asked Mercurial to ignore app/tmp above, the file empty inside will not be ignored, or removed, since I have explicitly asked Mercurial to track it.

like image 184
Lasse V. Karlsen Avatar answered Mar 25 '23 07:03

Lasse V. Karlsen


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

You may want to consider using .hgignore, of course.

like image 42
Andrew Avatar answered Mar 25 '23 09:03

Andrew