Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial "hg status" and relative paths

Tags:

mercurial

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?

like image 765
pachanga Avatar asked May 07 '09 07:05

pachanga


People also ask

What is hg status?

hg status shows the status of a repository. Files are stored in a project's working directory (which users see), and the local repository (where committed snapshots are permanently recorded). hg add tells Mercurial to track files. hg commit creates a snapshot of the changes to 1 or more files in the local repository.

What does hg commit do?

Use the command hg update to switch to an existing branch. Use hg commit --close-branch to mark this branch head as closed. When all heads of a branch are closed, the branch will be considered closed.

How do I know my Mercurial version?

If you already have Mercurial installed, make sure you have version 1.7 or later. To check, enter hg --version at the command line.


2 Answers

To see workspace status relative to the current directory you can always use "." (a single dot) as the argument of "hg status", i.e.:

% hg root                   # root of the workspace /work/foo  % pwd                       # current directory is <root>/src /work/foo/src  % hg status                 # no argument, see all files M etc/foo.conf              # all files are shown with paths M src/foosetup.c            # relative to workspace root % 

The difference when you explicitly ask for the current working directory is that the relative filename paths use that as their starting point:

% hg status .               # see only files under current path M foosetup.c % 
like image 168
Giorgos Keramidas Avatar answered Sep 17 '22 13:09

Giorgos Keramidas


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 
like image 30
richq Avatar answered Sep 18 '22 13:09

richq