How to ignore some folders in HG? - mercurial

Starting here,
I'm wrestling with this right now. I've got two folders: Source and SQL. Source has multiple project folders. The project folders in Source and SQL have bin folders. I want to ignore all files in bin folders under Source, but not under SQL. I thought one of these might do the trick:
glob:Source\*\bin\
glob:Source\*\bin
glob:Source\*\bin\*
glob:Source\*\bin*
glob:Source*\bin\
glob:Source\*bin\
But no dice on all of the above.
It seems I'll have to enter a line for each folder under Source where I expect to have a bin folder (and then update my .hgignore file whenever I add a new project).
glob:Source\Project1\bin\
glob:Source\Project2\bin\
#etc
If this is not the case, any advice would be appreciated.

Have you tried a regexp:
syntax: regex
^Source/.*/bin
Also, do remember that anything you've already added isn't affected by ignore rules, so you need the files to be untracked to test this stuff.
Lastly, consider making each project a separate repo -- that's the standard advice in DVCS land be it Mercurial or git. In svn multiple projects in the same repo isn't such a bad idea because you can have different parts of the working directory updated to different revisions, but with a DVCS all files are updated/checkedout to the same revision, which makes putting multiple Projects in the same repo a hassle in general and a really bad idea in some circumstances.

Looking at my .hgignore file, my slashes seem to to be the other way around (a forwrad slash instead of a backslash). i.e:
glob:*/bin/*
Try that maybe?

Related

Do all files have to be in the 'repository folder' when using Mercurial?

This is my first time using Mercurial so this may be a very newbie question...
If I create a repository, e.g. c:\HG1 do all my files need to be under that directory?
Or can i add files from a different folder e.g. 'C:\myotherfolder'?
If you can add from diff folder...how, can't seem to figure it out.
thanks.
p.s.
I'm coming from a non-distributed source control system so perhaps I'm just thinking about my workflows with that mindset.
Yes, all of the files to be tracked must be under the root repository folder.
No they don't, you can use a symlink (mklink on windows) in order to link another folder into your repository that is not in the same parent folder.
See my answer to a similar question here: https://stackoverflow.com/a/19473449/471924

Remove not-matching lines from hgignore

Is there an Mercurial extension that removes lines from .hgignore that aren't matching any files in the local repository.
There exists no extension or built in function that does this. You could jerry rig a script to do to find lines that are ignoring nothing without too much work, but consider that this is probably a bad idea.
Just because the .hgignore line isn't matching an files on your local repository doesn't mean it's not matching them on anyone else's repository. Within .hgignore files you'll often find patterns like .swp and .bak. You might not use vi (which creates .swp files) and you might not use an editor that creates '.bakfiles, but other do. Or perhaps your editor creates .swp files but you don't currently have any because you're not actively editing a file. Removing that line means you'd not be ignoring a .swp file next time you had one andhg addremove` would cause it to become tracked.

mercurial ignores sites/all/modules in Drupal Multi-site

I'm not going to get into the discussion on how to set up mercurial for a Drupal multi-site installation, but I've run across something that's boggling my mind.
I have a drupal multi-site installation which I'm trying to set version control up on. What I've done is to hg init in the Drupal Root, with an .hgignore that ignores drupal_root/sites/. This is what Is in my .hgignore, and it seems to be working fine:
# Glob syntax
syntax: glob
# Everything in sites
sites/*
This is working just fine, as mercurial finds everything else besides the sites folder. Now, inside the sites folder, the structure looks like this:
sites/
sites/all
sites/default
sites/domain1.com
sites/domain2.com
My problem is that when I do hg status inside sites, mercurial will not find sites/all/modules. I've tried multiple permutations of .hgignore, as I'd like to ignore sites/domain1.com/files, but nothing seems to work. I even deleted the repo, and started over without any .hgignore at all. sites/all/libraries and sites/all/scripts both show up just fine.
Could the .hgignore in the parent directory have something to do with it?
UPDATE: I just completely removed the sub-repo (I know it's not actually a sub-repo, but I'm limited here) deleted the repo in drupal root, and started over treating the entire installation as a single repo. Same thing, mercurial just will not find root/sites/all/modules.
UPDATE: #Ry4an - The behavior in the drupal root directory is correct. I'm trying to emulate sub-repositories since I'm stuck using Hg 1.3, which doesn't really implement them. So, my directory structure looks like this:
drupal_root/
.hg/
modules/
includes/
themes/
sites/
.hg/
all/
default/
domain1.com/
domain2.com/
So, I do want the repository inside drupal_root to ignore everything under drupal_root/sites, but I have a second repository inside drupal_root/sites that should handle everything there. That's the repo that's not finding everything.
What you're seeing is the behavior I'd expect. This glob rule:
syntax: glob
# Everything in sites
sites/*
ignores everything in sites, which includes 'sites/all', so Mercurial won't be looking down inside 'all' at all, so it won't see 'sites/all/modules'.
If you provide a full list of files and their paths annotated with what files you want ignored and what files you don't want ignored I'm sure someone can help you come up with the right rules, but it's not entirely clear from your question.
If you task is "ignore all, except one dir"
If you can write (and test) regexps
you can consult with this question and accepted answer in order to adopt regexp to your conditions
Another (slightly more inaccurate) solution can be
leave current "ignore all" pattern
add all files in sites/all/modules into repo by hand (hgignore ignore only untracked objects)
don't forget all new files, added later into modules, add explicitly to Mercurial (they will be ignored by rule)
Well, I feel like an idiot. The problem was that there was already a repository inside drupal_root/sites/all/modules. I don't remember putting it there, but it seems that mercurial ignores any directory that already contains a .hg directory. Thanks for the help everyone.

"factorizing" a mercurial repository on kiln

Summarized questions:
What is the simplest (and best) way to shift a group of files from an existing repository to a new sub repository, so those files can be integrated with other parent repositories, some of which may not yet exist?
Do files in subrepositories need to be in discrete folders, or can they exist alongside other files?
Detailed Questions:
I have begun the process of creating multiple repositories representing several projects that have shared components, and that is going well, thanks to SO and some helpful answers to my question here
As I move on to adding a second project I notice there are a few files in my projects that are duplicated, and are essentially the same thing, with enough similarity to warrant taking them out of a main project repository and creating a new subrepository so they can be
used by any new projects I begin, and
removed from other existing repositories, since they are identical.
I am assuming the best way is to simply create a new repository, move the files across on the local file system, push both repositories, and then create a .hgsub file and proceeed as in the answer to my earlier question. This would obviously then shift the files concerned to a subfolder in the local file system under each main project, which i can live with, but it does raise the hypothetical question - is it possible to have a list of files in a repository that are effectively part of a sub repository but reside alongside other files (i.e. not in a sub folder).
If I wanted to (for example) have a "acme.h" file in each project that is part of another repository could I do this? as it happens, I don't need to do this at this point in time, and in my current situation it would be better from a design point of view to have the files I need to "refactor" into another repository in their own subfolder, however that might not always be the case. I use refactor in quotes here, as strictly speaking it's more about refactoring duplicated files that is refactoring code - however the same principle applies.
hopefully my questions are succinct enough to be answered without too much more explanation.
Thanks for summary, makes it much easier to answer!
What is the simplest (and best) way to shift a group of files from an existing repository to a new sub repository, so those files can be integrated with other parent repositories, some of which may not yet exist?
You can use the convert extension to extract a directory from an existing Mercurial repository. You'll want to use the --filemap flag and in the filemap you include the directory you want and rename it to the root. See hg help convert for more info.
After you get a smaller repository with the
Do files in subrepositories need to be in discrete folders, or can they exist alongside other files?
They must be in their own folders. This is simply because that's how a repository looks like in Mercurial, Git, Subversion, ... When you're dealing with subrepositories, then Mercurial is not tracking the files inside the subrepo: it's just asking some (other) system to make a checkout of repository foo at some location.
So when your .hgsub file has
foo = foo
bar = [git]bar
baz = [svn]baz
then Mercurial will notice this on hg update and run
hg clone default-path-of-this-repo/foo foo
git clone default-path-of-this-repo/bar bar
svn checkout default-path-of-this-repo/baz baz
for your. This explains why subrepostories are directories in the outer repository: that's simply what a clone/checkout looks like these days.
As you can see, subrepositories can be of different types. It's conceivable that someone could add a RCS subrepository type for tracking individual files. They would then not have to live in a directory.

Can one Mercurial repository live inside another Mercurial repository?

Can one hg repo live inside another hg repo on my local file system?
I am pulling down the bitbucket wiki for 'sandbox', and I want to know if this should be placed in repos/sandbox/wiki or repos/sandbox-wiki.
Is the former okay to do?
Edit: See Subrepository.
The short answer is yes, but I can't imagine why you would want to.
In your example, I think you should go with:
repos/sandbox-wiki
[edit] Additionaly:
Yo Dowg, I herd you like repositories.
So we put a repo in your repo so you can version while you version
:-)
Yes and no. Depends on what you want to do. You can create repo 'sandbox/wiki' but files in this inner repos won't be commited in the outer 'sandbox' repo (#Jason is right). If you don't want to, no problem.
Try explicitly adding files from wiki repos in sandox and you'll get the message below. If you just add path to some directory containing an inner repo the files will just be ignored.
From sandox root directoy:
hg add wiki/myfile
abort: path 'wiki/myfile' is inside repo 'wiki'
Mercurial does not allow nested repositories, but there is at least one reason for them:
Imagine that you are working in a project: /MyProject. In this folder you put everything: code, documentation, tests, etc.
You want to backup your work because it is very important, so you create a repository for /MyProject. Then, overtime you use bundles to save the evolution of /MyProject and back up them in a USB flash memory so that you can recover everything just in case your hard drive breaks.
Remember that /MyProject contains everything. And among all those things, there are the main code and some auxiliary projects. You also want to track the progress of an auxiliary project that is in /MyProject/AuxiliaryProject, so you use Mercurial to track its evolution.
Also, you want to have a separate repository for the main code: /MyProject/Main
In this situation you want nested repositories: one big one for being able to back-up everything using bundles and child repositories for managing each subproject.
I think Mercurial should give the user several options when initializing a repository. For example:
- ignore nested repositories
- include nested repositories but ignoring .Hg folders (i.e. act as if there were no nested repositories but do not ignore the information contained in the nested respositories).
- include nested repositories and also include .Hg folders (makes sense for back-up purposes)
--------- Edit:
Subrepositories is a feature that is work in progress:
https://www.mercurial-scm.org/wiki/subrepos
Also, there is an extension named "forest" that might become obsolete in the future:
https://www.mercurial-scm.org/ForestExtension
You'd need to set up an .hgignore file in sandbox to exclude wiki because mercurial assumes that it is responsible for all descendants. This would probably generate more user confusion than it is worth.