0
votes

My Mercurial folder structure is like this, where "temp" is in the root of the folder.

temp
|   1world
|   world
|   world.txt
|           
+---sub1
|       1world
|       world
|       world.txt
|       
+---sub2
+---sub3
|       misc.txt
|       other
|       otherfile.txt
|       
\---sub4
        world

I would like to ignore everything in the temp folder and its subfolders, except for files which are named "world" (only "world" and not "1world" or "world.txt" etc.)

Using syntax: regexp in .hgignore, I can match temp > world using ^temp/(?!world$), but I'm not able to get the full regex string right (to match world in all temp subfolders as well).

Any guidance will be much appreciated!


Update

I managed to get the result I wanted by manually listing each folder as such:

^temp/(?!world$|sub1|sub2|sub3|sub4)
^temp/sub1/(?!world$)
^temp/sub2/(?!world$)
^temp/sub3/(?!world$)
^temp/sub4/(?!world$)

However, I would much prefer it if I could just match world in all subfolders with a pattern, as it's easy to forget to update .hgignore when things change.

1
Could you maybe also put how you're using the regex? There might be some other commands more suitable?Jerry
Hmm, .hgignore is a plain text file, so I just entered the regex there. Not sure if I answered your question..?Candice
Oh... I was just wondering because there's a page filled with different commands here.Jerry

1 Answers

0
votes

If you have to list all the folders anyway, you should just put . in your .hgignore, which means ignore everything, and then hg add the world files you want.

A .hgignore exists only to affect which unadded files you see when you do a hg status but if you have to add an entry for every file you want not-ignored then you're not seeing the world files that you need to add anyway. So instead of adding another line to your .hgignore just had add path_to_new_folder/world.

Once a file is added .hgignore has no effect on it at all.

So from the start the process would be:

echo . > `.hgignore   # create a new hgignore file with just a single got in it
hg add **/world       # add all the files named exactly world
hg commit             # commit those world files

Now it's still possible for you to forget to add new world files by forgetting to run hg add **/world again, but at least that's easier than having to remember to add another exception to your .hgignore.