Obviously I can do something like cat .hg/hgrc on *nix to see the paths I have configured, but is there a built-in Mercurial command? A Google search for "hg list configured urls" didn't seem to have any useful results, and neither does hg help urls (that I noticed).
Is there any command that will display the urls I have configured?
hg paths is what you are looking for. hg help paths will give you more information.
The correct answer is indeed hg paths as smooth reggae wrote, but so you know, there's also the showconfig command, which will show you any section(s) of the combined config files.
There's not much point in using hg showconfig paths, which is longer to type, but it's useful for quickly checking the value of other configuration settings.
Related
I often have trouble finding the hgrc files loaded by Mercurial.
I know the possible locations are documented at http://linux.die.net/man/5/hgrc, but there are quite a few of them, and they vary from platform to platform, and they depend on things like the "Mercurial installation directory" which is yet another thing to have to track down. And sometimes, it seems like it's loading hgrc files from locations that are not on that list at all!
It would be great if I could get Mercurial to tell me which hgrc files it's loading, so I don't have to spend time searching for them. Basically, I'd like to be able to pass hg an option, like hg -debug-hgrc-paths and have it print the full path to each hgrc file that it loads. Much like how you can get gcc to print the header file search paths it is using with gcc -v -E. Does anyone know of such an option?
It might be more than you actually need but
hg --debug showconfig
will tell you quite a bit about what values are being set from where.
Is there any Mercurial command or Python API that could yield the repo name? This will help developing cross-repo scripts.
The only related solution that I found is to parse the .hg/hgrc [paths] section 'default' config option.
[paths]
default = ssh://server//path/tools
There must be a more elegant solution, I think.
There is no real concept of a "repository name" in Mercurial (a repository doesn't "know" or care about its own name). I think you mean "last past component of the default pull path"?
If so, then parsing the output of hg path default would be the most direct way to get that information.
However, you should note that the default path can (and often is) changed: think of cloning a local clone time for testing:
$ hg clone http://server/lib-foo
$ hg clone lib-foo lib-foo-test
$ hg clone lib-foo-test lib-foo-more-testing
The lib-foo-more-testing clone has a default push path back to lib-foo-test.
This means that parsing hg paths default wont be much more reliable than using basename $(hg root) — both can be completely different from the (base)name of the repository that was originally cloned.
If what you really want is to get an "identity" for a repository, then you should instead use
$ hg log -r 0 --template "{node}"
The first changeset hash in a repository will normally uniquely identify the repository and it will be stable even when clones change names. (If a repository has two or more roots, then the zeroth changeset can in principle differ between clones. People will have to actively try to make it differ, though.)
If you want to get last segment of path for remote default alias, processing output of hg path default will be better choice
If you want to get local directory name of you mercurial repository, I haven't good solution, except checking code of Notify extension (in which, after some tricks, you can get project-name)
I have configured hg log in ~/.hgrc to only list commits from the current branch by default:
[defaults]
log = --branch .
However, occasionally I'd like to really see commits from all branches. Is there a way to tell hg log when invoked form the command line to not use the configured defaults but fall back to the built-in behavior? As a brute-force solution ignoring ~/.hgrc altogether for this particular invocation of hg log would be fine for me.
I'm aware that defaults are deprecated in favor of aliases, but aliases cannot be created with the same names as existing commands, which is what I want in order to not have to learn new command names, esp. when ~/.hgrc settings are to be shared by multiple developers.
Edit: Not being able to create aliases with the same names as existing commands was a regression that has been fixed.
You should be able to use --config to override the setting in your .hgrc:
hg --config defaults.log= log
From the man page:
--config set/override config option (use 'section.name=value')
I have gone through the bug reports on the Mercurial website and cannot find any workarounds for this, the response being a blanket "this is deprecated".
Personally, not learning the commands to me is not a valid reason for not migrating away from default command values. A possible alternative would be to move away from per-repository settings and have some settings at the user level, so you can set your own defaults / aliases.
Defaults are now deprecated, so you should likely remove this and specify the arguments each time. Confirmed in the documentation:
https://www.mercurial-scm.org/wiki/Defaults
(defaults are deprecated. Don't use them. Use aliases instead)
Try:
[alias]
blog = log --branch
Usage:
hg blog <branch name>
hg blog default
I know I'm resurrecting an old question here, but this statement
aliases cannot be created with the same names as existing commands
is incorrect.
In your .hgrc file in the [alias] section, you can, for example, have:
[alias]
add = add --dry-run
This will make the add command always do a dry-run, instead of actually recursively adding all unknown files in the repository.
It seems the best solution to my use-case indeed it to temporarily ignore the ~/.hgrc file altogether. This can be done by setting HGRCPATH to an empty string, which causes Mercurial to only read the .hg/hgrc file from the current repository:
HGRCPATH="" hg log
There are two project in which I collaborate, they live in different servers, A and B.
While A has the hg program in /opt/mercurial/bin/hg, B has it in /usr/local/bin/hg.
When I want to pull/push changes to either remote, I have to manually modify .hgrcfile in order for the option remotecmdto point to the right location of hg.
I would like to know if it is possible to setup different remotecmdpaths for different remotes so that I don't have to manually change the path of the hgprogram everytime I need to do some remote operation.
I saw this question: Setup platform-dependent hgrc but it seemed to me that there should be a more native (something like a built-in setting) way to do this. So far I haven't been able to find it, so any help will be welcome :)
Thanks!
Ideally you just get the hg binary into your $PATH on both servers and you don't have to think about it anymore. That can be done in the system's /etc/profile or in your .ssh/enviironment on that remote server. Most people never even need to think about remotecmd.
If they're separate projects (or even separate clones locally of the same project) you can set the remotecmd in the .hg/hgrc file within each repository -- settings don't just have to be in your ~/hgrc file.
Also be aware that --remotecmd is available as a command line option for push and pull, so you could use that and even combine it with something like:
[alias]
pusha = push --remotecmd /opt/mercurial/bin/hg
and then you can just do hg pusha
Really though, just try to get hg into your path like everyone else does.
I'm looking for a way to set .hgrc configuration items without actually editing the text file. I'm trying to standardize the setup of the hgrc across multiple developers and I would like a command like
hg --config ui.username=foo
but which also saves that config change into the hgrc file.
It seems like this should be something that should be supported directly in the vanilla hg command, but I can't find it anywhere.
Someone -- either you or Mercurial -- will have to edit the configuration file if you want the config change to be saved :-)
And if you can call Mercurial with
hg --config ui.username=foo
then you should also be able to do
echo '[ui]' >> ~/.hgrc
echo 'username = foo' >> ~/.hgrc
which will save the config change, not matter how the ~/.hgrc file happens to look like (it is okay to have multiple [ui] sections).
Mercurial 3.0 and later has the hg config --edit command that opens an editor with the user config file. Still not quite what you're asking for, but at least this makes it easier to edit the file interactively.
This form:
hg --config ui.username=foo
Doesn't save anything. It sets the value for just the one run.
Also you can use /etc/mercurial/hgrc for system wide settings if that helps anything.
There is an extension that helps with this, https://bitbucket.org/alu/hgconfig/wiki/Home
After installing that hgext, you can do things like this.
% hg showconfig paths
paths.default=ssh://hg#bitbucket.org/alu/hgconfig
% hg config paths.upstream $(hg showconfig paths.default)
% hg config paths.default $(hg showconfig paths.default | sed 's|/alu/|/nassrat/|')
% hg showconfig paths
paths.default=ssh://hg#bitbucket.org/nassrat/hgconfig
paths.upstream=ssh://hg#bitbucket.org/alu/hgconfig
The only gotcha is this overrides the builtin config command, you can either tweak the code to change the command name, or live with it. Fortunately, it probably would not matter if your use case is simply to set and get specific configs.