I created local hg repository for new project: hg init ; hg addremove,
then I created empty upstream repo, and pushed first version there: hg push https://remoterepo.
Now, I want to set that https://remoterepo as default upstream, so I can just do hg push/pull without giving it.
I was surprised Google did not give me a straight answer with "set mercurial upstream", and I didn't find a direct answer here at SO either. So, for the benefit of all the people using SO as a howto, what's the right way to do this?
You can do that by adding the upstream URL to /project/.hg/hgrc like this:
[paths]
default = ssh://test#bitbucket.com/repos/something
upstream = ssh://test#bitbucket.com/repos/something_else
and now upstream is an alias for repo something_else which you can then pull from or push to:
hg pull upstream
hg push upstream
Reference
hg help urls:
URLs can all be stored in your
configuration file with path aliases
under the [paths] section like so:
[paths]
alias1 = URL1
alias2 = URL2
...
You can then use the alias for any
command that uses a URL (for example
hg pull alias1 will be treated as
hg pull URL1).
Two path aliases are special because
they are used as defaults when you do
not provide the URL to a command:
default
default-push
Related
My .hg/hgrc file has the line:
default = http://some/remote/repository
Is there a quick command to print the tip revision of that repository (which may or may not be inside my local repository)?
You can use the identify command like this:
$ hg identify $(hg paths default)
This is one of the few commands that can operate on a remote repository. If you need more information about the remote repository, then I suggest you take a look at hg incoming.
The following returns the latest changeset number (tip) of a remote repository:
hg identify --id http://www.myrepo.com
hg id default
This is a shorter form of "hg identify $(hg paths default)".
We're trying to clone a Mercurial repository A where it references a subrepository B that's moved hosts. We'd like to update .hgsub in A to point to the new location of B, but it's a chicken and egg problem if we can't hg clone A in the first place.
Does anyone know how to work around this?
$ hg help subrepos
...
Remapping Subrepositories Sources
---------------------------------
A subrepository source location may change during a project life,
invalidating references stored in the parent repository history. To fix
this, rewriting rules can be defined in parent repository "hgrc" file or
in Mercurial configuration. See the "[subpaths]" section in hgrc(5) for
more details.
$ man hgrc
...
subpaths
Defines subrepositories source locations rewriting rules of the form:
<pattern> = <replacement>
Where pattern is a regular expression matching the source and replacement is the replacement string used to
rewrite it. Groups can be matched in pattern and referenced in replacements. For instance:
http://server/(.*)-hg/ = http://hg.server/\1/
rewrites http://server/foo-hg/ into http://hg.server/foo/.
All patterns are applied in definition order.
...
So, you can do it in .hgrc in a [subpaths] section.
First note that clone is init + pull + update and that subrepo cloning is part of the update step, not the pull step. This means that you can avoid clone failing simply by skipping the update step:
$ hg clone -U <url>
Now the problem is reduced to "how do I update to a revision with a problematic .hgsub/.hgsubstate file?" There are two possibilities here:
remap subrepos using the [subpaths] feature (see hg help subrepo and hg help config)
manual update and repair
A "manual update" can be done like this:
$ hg revert -a -r default -X problematic-file
[adding a bunch of files]
$ hg debugrebuildstate -r default
Now you can manually fix-up your subrepos and .hgsub and commit. Be sure to test your fix with a clone before pushing it.
Also, see this mailing list thread on the topic: http://markmail.org/thread/ktxd2rsm7avkexzr
It could be easier to tamper with DNS as a quick workaround (e.g. hosts file on Windows) and then fix .hgsub.
When a project is started with
mkdir proj
cd proj
hg init
[create some files]
hg add file.txt
hg commit
hg push ssh://me#somewhere.somehost.com/proj
now when hg path is issued, nothing will show. How do we actually change the repository so that it is as if it is cloned from me#somewhere.somehost.com/proj ? Is it just by editing .hg/hgrc and adding
[paths]
default = ssh://me#somewhere.somehost.com/proj
because that feels like too low level an operation to do (by editing a text file)
It's the only way to do it in this situation. There are plenty of other cases where you have to edit the hgrc by hand, like setting up hooks or enabling extensions, so it's not as if it's unusual.
(As you probably already know, hg clone will set the path entry in the clone to point back to the original.)
In git I can git remote add x http://... then git pull x how can I do this in hg?
I was told to add the following to .hgrc:
[paths]
x = http://...
so I added the above to /path/to/repo/.hgrc then tried hg pull x and got the following error:
abort: repository x not found!
where x was mozilla and http:// was http://hg.mozilla.org/labs/jetpack-sdk/
The hgrc file is in /path/to/repo/.hg/hgrc (note there's no period in front of the name). It looks like you created a file called .hgrc in the root of the repository, which Mercurial doesn't recognize.
You could also do hg clone http://hg.mozilla.org/labs/jetpack-sdk which would create a local repository and pull all of its files in one step.
I've forked a Mercurial repository, and now I want to pull the changes from the main repository into my fork. If this were git, I would do something like...
git remote add upstream <url>
git pull upstream master
How do I do this sort of thing in Mercurial?
You could also modify your hgrc file in your repo
default = ssh://hg#bitbucket.org/<my_user>/<my_repo>
upstream = ssh://hg#bitbucket.org/<other_user>/<other_repo>
Then you can do
hg pull upstream
If you cloned the repository from the one you want to pull changes from, you can simply do:
hg pull
If you cloned the repository from another repository, you can:
hg pull <location of repository to pull from>
You'll then need to update your working copy:
hg update
That's the basics, anyway. More details are available in the Mercurial: The Definitive Guide
Have you tried the pull command?
hg pull http://master.com/master
If that does not work, please elaborate.
You could also modify your hgrc file in your repo to use the special path names default and default-push.
default-push = ssh://hg#bitbucket.org/<my_user>/<my_repo>
default = ssh://hg#bitbucket.org/<other_user>/<other_repo>
Then you can pull from upstream (aka default) with
hg pull
and push to fork (aka default-push) with
hg push