problems with empty directories and "hg clean"

Ondrej Certik ondrej at
Tue Mar 25 17:48:00 CDT 2008

On Tue, Mar 25, 2008 at 10:43 PM, Dirkjan Ochtman <dirkjan at> wrote:
> Ondrej Certik <ondrej <at>> writes:
>  > I am not even reporting this as a bug, as I think it's just a feature.
>  > But how would you suggest me to improve my usage of Mercurial, so that
>  > I don't accidentaly delete empty directories? I find it inconsistent,
>  > that "hg st" doesn't report them, but "hg clean" does delete them.

>  I use HG to manage the configuration of my servers but I don't do it
>  directly. I version control a directory tree which I recursively copy
>  into the file system, not just /etc.

So you version control all "/" ? Or just part of it and then you copy
it to the "/"?

>  For me, this approach makes it easier to reuse a repository, eg,
>  hg clone old-config new-config
>  ...for a new system.

You clone it and then you copy it? Interesting approach. I mainly use
it for backups, but as I said - unfortunately I cannot rely on it,
empty directories are not handled by mercurial.

>  According to manual it's no bug, it's a feature (C). Mercurial don't
>  handle directories at all. It just handle files. You can just try to add
>  some file empty to this directory (like ".empty") and add it using hg add.

Right. But as you said - mercurial doesn't handle directories, yet "hg
clean" deletes them. I find it confusing and weird.

>  I usually put versioned .keep files in my empty directories...

Right. But then you need to go through the whole /etc and find all
empty directories and add .keep files to all.

I decided not to run "hg clean" on my /etc, as this fixes my problem.
I understand there are probably good reasons for not versioning
directories, but
honestly, I found more troubles than advantages with this approach.

But one solution occured to me. If we could create an option to "hg
st" to show empty directories, something like "hg st --dirs" (maybe
even make this default?) and then another command to create all those
.keep files and add them to hg, then I think it could be managable.
But doing this by hand on all my servers, well, that's not an option
for me.


More information about the Mercurial mailing list