Search code examples
mercurial

Mercurial "hg status" and relative paths


I'm using both mercurial and git for different projects and like them both. What I find a bit annoying about mercurial is that "hg status" shows paths relative to the repository root, not to the current directory(unlike git). Can this behaviour be tweaked somehow?


Solution

  • The usual workaround is to run:

    hg status $(hg root)
    

    For older versions of Mercurial, prior to 1.7, you could use this hack, adding to your repository's ".hg/hgrc" file:

    [alias]
     sst = status /path/to/root
    

    That needs the alias extension enabled, so you may have to add "alias=" to your ~/.hgrc file.

    Starting with Mercurial 1.7, the alias extension learned about the "!" escape to use shell commands, so you can now have a global alias that does this:

    [alias]
    sst = !hg status $($HG root) $HG_ARGS
    

    Don't use st = !hg status $(hg root), since that creates an infinite loop, running hg status over and over. It looks like a bug in the alias parsing - if you want to alias hg status to show the path from the root, then the following incantation works in the global $HOME/.hgrc:

    [alias]
    __mystatus = status
    st = !hg __mystatus $($HG root) $HG_ARGS