How to get the remote server hg path? - mercurial

I have created a remote repo to push my local changes over ssl. I did hg showconfig --debug to find my remote hg path but it's output is messy. Can someone point me how to exactly find it?

hg paths gives the relationship between each path name and its url.
> hg paths
default = ssh://hg#example.org/repo
local = /local/path/to/repo
hg paths <name> gives the url for the name.
> hg paths default
ssh://hg#example.org/repo
> hg paths local
/local/path/to/repo
BTW, to get just the path names:
> hg paths -q
default
local
and hg paths -q <name> will always result in no output.

Related

How to set Mercurial upstream

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

Get tip changeset of remote Mercurial repository

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)".

hg diff local to remote file

This may be a silly question but when comparing a local to remote file, what is the path to the remote file?
Does hg want you to provide the head/revision you are referring to or something?
ie:
hg diff /local/file /remote?/file?
Mercurial doesn't do this. The only comparison with other repositories is hg incoming and hg outgoning which show which changesets differ between repositories. You can add the --patch option to either of those to see the patches that are the meat of those changesets, but you can't compare two versions of a file without having them in the same local clone.
From Hg man
hg diff [OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...
I am not sure if you can speak about a "remote file" in a DVCS: you need to fetch or clone a remote repo in order to be able to make any hg diff.
hg fetch, for instance, is described here.

How to use `hg cat` from an empty working directory?

I have a repo located at x:/projects/repo1. The working directory has been emptied using hg update null. I want to extract the latest version of some files from there to a local directory.
I tried this:
x:\projects\repo1> hg cat -o c:\sql\%s scripts\*.sql -r tip
I get this error:
scripts\*.sql: No such file in rev 14f07c26178b
The same command works fine if the working directory is not empty. Is there a good reason why this does not work? Or do you know another way of extract some files from there to a local directory?
The hg cat command is for single files. If you want multiple files use the hg archive command, which makes zipfiles or directories full of files. Here's your command:
x:\projects\repo1> hg archive --include scripts\*.sql -r tip c:\sql
It seems that hg cat doesn't support wildcard symbols in paths. So you should use the full file name:
hg cat -r tip scripts/foo.sql
When your working copy is up to date with the tip revision, your shell does wildcard substitution for you.
The hg manifest command also might be helpful for getting tracked file listings.
This answer is to your comment on Andrey's answer:
hg manifest takes a --rev argument that you can use to see the list of all files in your repository:
hg manifest --rev tip
To get the list of files matching a pattern at the tip, use:
hg stat --all --include *.sql --rev tip --no-status
hg stat -A -I *.sql --rev tip -n # using abbreviations.
From there you could redirect the output to a file and edit each line into a hg cat command like in your original question. It appears (to me, at least, having done some experimentation) that hg cat uses the contents of the working directory -- rather than the contents of the repository at the revision specified -- for glob-matching, so once you know the exact name of the file, you can hg cat it at any revision.

Storing a remote path by name in Hg

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.