Say I have cloned a repo to a directory called ~/trunk and I want to share a branch named my-new-branch to the directory ~/my-new-branch. How would I do that with the hg share extension?
This is what I've been doing:
cd ~
hg share trunk my-new-branch
But then when I cd into the new directory I have to hg up to the branch?
Confused.
IMO
shareis a very useful command which has some great advantages overclonein some cases. But I think it is unfortunately overlooked in many instances.What
sharedoes is to re-use the 'store' of Mercurial version control information between more than one local repository. (It has nothing directly to do with branching.)The 'store' is a bunch of files which represents all the history Mercurial saves for you. You don't interact with it directly. Its a black box 99.99% of the time.
sharediffers from the more commonly-usedclonecommand in thatclonewould copy the information store, taking longer to run and using potentially a lot more disk space.The "side effect" of using
sharerather thancloneis that you will instantly see all the same commits in everysharedrepository. It is as if push/pull were to happen automatically among all thesharedrepos. This would not be true withclone, you'd have to explicitly push/pull first. This is quite useful but something to be mindful of in your workflow because it may surprise you the first time you use it if you are only used toclone.If you want to work in multiple branches (named or unnamed) of your project simultaneously, either
cloneorsharewill work fine. Once you have created the second repository, yes you need toupdateit to whatever changeset you want to begin working on.Concrete example using
share:As soon as you commit something in
working1that commit will be visible in the history ofworking2. But since they are not on the same branch this has no real immediate effect onworking2.working2will retainpath\to\source\repoas its default push/pull location, just likeworking1.My own practice has been to create numerous locally
sharedrepositories (quick, easy, saves space) and work in various branches. Often I'll even have a few of them on the same named branch but set to different points in history, for various reasons. I no longer find much need to actuallyclonelocally (on the same PC).A caveat -- I would avoid using share across a network connection - like to a repo on a network drive. I think that could suffer some performance or even reliability issues. In fact, I wouldn't work off a network drive with a Mercurial repo (if avoidable) in any circumstance. Cloning locally would be safer.
Secondly -- I would read the docs, there are a few weird scenarios you might encounter; but I think these are not likely just based on my own experience.
Final note: although share is implemented as an "extension" to Mercurial, it has been effectively a part of it since forever. So there is nothing new or experimental about it, don't let the "extension" deal put you off.