Let's say I have this alias defined in mercurial config:
pushb = push -B `cat .hg/bookmarks.current`
How can I view what command will be called after all substitutions apllied?
Example:
My .hg/bookmarks.current file contains some_bookmark text. How can I view that when I call hg pushb it'll actually call hg push -B some_bookmark?
When you use -B <bookmark> in push and this local bookmark exist, you can see
pushing to ...
searching for changes
...
exporting bookmark <bookmark>
in push output in case of correct expansion or
bookmark <bookmark> does not exist on the local or remote repository!
in latest string in case of problem and getting bad name. Anyway, your can see resulted bookmark's name in both cases
Related
Question title is pretty much the question. Here's a look at what I get:
I am trying to export a mercurial repository to git, but to a different directory. hg gexport works just fine without the --cwd parameter, but I don't want that -- I want to change the working directory to another one, but strangely, it says unknown command when I use that command line switch.
Any ideas?
Real hgexport is not native hg command, it's part of hggit extension
According to wiki, this part ("Using hg-git to interact with a hg repository with git") is outdated and may not reflect current state of extension
>hg gexport --cwd $PATH work in my own tests without errors (so-so, see below) with command-line expanded accordingly to requirements
hg gexport --cwd i:\Work\Personal!whyhq\ -R i:\Work\Personal!whyhq\site
without -R gexport will not find source hg-repo after cdto target location
And last, but not least: even properly used, hgexport in current hggit
hg id
15457fc67631 0.8.13
do nothing (nothing changed on target). I suppose, for getting git-repo from hg you have to use trivial hg push <git-URL> today (yes, it work, with minimal tricks on your side: branch_bookmark_suffix = $STRING in .hgrc)
Side note
If you have hggit extension enabled (globally or per-repository) hg-repo is mirrored automagically into bare git-repo (at least it seems so) in .hg/git directory, you can just copy&rename it
When I run hg log -r remote/project I get the last commit on that bookmark.
How can I get a full list of commits from the head of that bookmark?
This is not (easily) possible in general. You can approximate it with hg incoming from an empty repository, but hg incoming actually does a complete pull of the difference and throws the contents away; it does not scale for large repositories. Any solutions that are both practical and general involve ssh-ing into the remote machine or setting up a separate server process on the remote machine.
An intermediate approach uses hg incoming --bundle FILE -T '' (the -T '' part is to suppress normal output). This will store the difference between your local version in an overlay repository called FILE; you can then use hg log -R FILE to perform normal log commands on the overlay repository (and you can also pull from it, as though it were a snapshot of the original remote). This still relies on you having a significant portion of the repository on your local machine, or it will result in a full download of the remote repository.
I need a mercurail template/keyword "hostname" to get the name (or IP) of the computer where the repo is located. as far as i read the wiki, namely "Chapter 11. Customizing the output of Mercurial", hg help templates, and the web, I think it should be similar to the date keyword, dynamicly expanded. How can i define my own template/keyword?
Thank you verry much
The following extension should do the trick:
from mercurial import templatekw
testedwith = "3.5"
_ipname = None
def showipname(repo, ctx, templ, **args):
""":ipname: String. The hostname of the machine that the repository
resides on."""
import socket
global _ipname
if not _ipname:
_ipname = socket.gethostname()
return _ipname
def uisetup(ui):
templatekw.keywords["ipname"] = showipname
Then use (say):
hg log -r . -T '{node|short} at {ipname}\n'
Note that the value of socket.gethostname() may depend on your internet connectivity. If you need the value in /etc/hostname or something else that identifies your machine, use that method instead.
To use an extension, put it in a file, say ipnametempl.py somewhere, then add the following lines to your .hgrc:
[extensions]
ipnametempl=/path/to/ipnametempl.py
This can be either your user/global hgrc or the .hg/hgrc in your repository (the latter if you only want to enable it for a specific repository). See hg help hgrc to find out where the user/global hgrc files are on your system.
Either the repository is local to your machine (then you can get the absolute path via hg root) and query the name via the normal system tools. You can embed those also in your templates:
$ hg log -r. --template="{branch}-{rev} from $(hostname) running debian $(cat /etc/debian_version)"
trunk-22248 from MYHOSTNAME running debian 8.2
Or you know already the URL (remote path) in order to operate with it as you need to specify it as argument to hg pull/clone/outgoing/incoming
If the remote URL is not explicitly specified on the command line it is specified in your .hgrc in the [path] section. When there is a remote repository at all, then usually a default = URL is defined there.
If you need the URL printed, then install hooks for clone, pull and push (and maybe outgoing and incoming) which prints the $URL as available in those hooks - or maybe just the changegroup hook. Check http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html#sec:hook:changegroup and hg help config.
For our project, we have two repositories: Main and Automated Testing. In the Testing repository, we allow multiple heads, so one commonly used "hg push -f" when pushing to the Testing repository. But using "push -f" is a bad habit, as one may accidentally use this for other repositories, too.
So I am looking for some configuration option, preferably on the repository side, which allows pushing multiple heads without using -f -- does Mercurial provide such an option?
(I know that I can install a hook to an repository to prevent it being the target of a forced push, but I would like to get rid of the need to use -f altogether.)
A simple solution (unfortunately needed per-client) is to setup an alias in your ~/.hgrc as follows:
[alias]
testboardpush = push -f ssh://example.com/testboard
You can then use hg testboardpush to push your commits to the automated testing repository, instead of getting into the bad habbit of using push -f.
If you have multiple repositories with multiple testboard locations, you can instead setup your alias inside your ~/.hgrc file as follows:
[alias]
testboardpush = push -f testboard
And then for each HG repository's .hg/hgrc file, have the lines:
[paths]
testboard = ssh://example.com/testboard
With this setup, typing hg testboardpush will always push to the correct place for the particular HG repository you are currently working in (or fail with an error if the path hasn't been setup).
Unfortunately, it does not appear you can do this from the server side without a custom version of HG; in particular, my reading of the push implementation in the localrepo.py file of the HG sources indicates it unconditionally checks for new heads using discovery.checkheads (and aborts) unless the force argument is set.
I want to commit separately different parts of the same file.
I want to commit line 2 first with the message (changeset 1) and the 4th line with the message (changeset 2). How do I do it?
I am using Mercurial Distributed SCM (version 3.5.2+20151001)
You can do this with the interactive option to commit.
First add the following to your ~/.hgrc file:
[ui]
interface = curses
Then use:
hg commit -i
This will tell commit to allow you to interactively select what files or (by drilling into the file) select sub file changes.
You can use this multiple times, selecting individual changes in the files.
Note: without the addition to your .hgrc, hg commit -i will ask you for each file and not allow you to drill into and select individual file changes.
The interactive option is also being implemented in other mercurial commands such as restore (you can select what changes are to be restored) and the new experimental amend command. It is very powerful and easy to use.