views:

571

answers:

4

Hi gurus,

We're using CakePHP for a new application, and we use Mercurial as the source control tool. (Mercurial uses one .hgignore file in the root directory, unlike (for example) CVS that uses .cvsignore in any directory.)

I'd like to exclude the content of the app/tmp/ directory from the source control (since they change all the time, and can be regenerated), but I can't add "app/tmp/*" to .hgignore, since then the standard directories under tmp (cache, logs, sessions, tests, and also cache/models, cache/persistent...) would be missing from new clones made by "hg clone", resulting in errors.

Currently I have in my .htignore:

app/tmp/logs/*.log
app/tmp/cache/persistent/cake_*
app/tmp/cache/models/cake_*

It would be good to have a "standard" one that could be used in all projects. Can someone suggest a complete solution?

Thanks in advance!

A: 

If I understand the question correctly you want to ignore file in tmp, but not files in certain directories in tmp. If that's right then I think you can do so using this:

syntax: regexp
^tmp/(?!(cache|logs|sessions|test))

That says ignore anything that starts with tmp, unless the next part is cache, log, sessions, test. For these files:

.
`-- tmp
    |-- cache
    |   `-- afile
    `-- tmpfile

here is the hg stat result:

$ hg stat
? .hgignore
? tmp/cache/afile

I will note, though, that Cake is probably telling you not to put those files into source control based ont heir being in a tmp directory. Are you sure they're not something htat your build system is supposed to create? Sessions in particular sound pretty transitory.

Ry4an
A: 

Ry4an,

thanks for the answer, but tmp's subdirectories are put there by the cakephp framework (and are required).

I would like to ignore all files (except ones called "empty", also put there by cakephp), but not the directories themselves.

KKovacs
Please use the "add comment" link underneath an answer to respond to an author. Your post is not an answer and thus should not be posted as one. :)
Paolo Bergantino
Of course, you are right. To my defense, the FAQ said I needed 50 reputation to leave comments. I must have been mistaken.
KKovacs
Hmm, it allows me to comment some places (here) and not on others (for example on Ry4an's answer). I guess I'll figure it out in time... :)
KKovacs
+3  A: 

You can add

syntax: glob
app/tmp/**

to your .hgignore file and Mercurial will from that point on ignore all files under app/tmp/ with the exception of files tracked by Mercurial. See hg help patterns for more about file name patterns.

So if you do

% touch app/tmp/cache/.empty
% touch app/tmp/logs/.empty
% hg add app/tmp/cache/.empty
% hg add app/tmp/logs/.empty

and make a clone, then the app/tmp/cache and app/tmp/logs directories will be created and new files in those directories will be ignored. I think that is what you want?

This is also useful for tracking something like $HOME since you would want to ignore most files by default and only track explicitly added files.

Martin Geisler
That is exactly what I do when using CakePHP, but I use Git and not Mercurial. This way the folder structure is maintained but the actual contents of the directories are not saved.
RFelix
A: 

In my own checkouts (from SVN), when the site was deployed, the ./tmp/ directory needed to have some specific permissions.

I removed it from version control entirely, and my deployment script created the directories as required.

Alister Bulman