mercurialmercurial-subrepos

Show if the revision of subrepos changed, or if they are dirty


I have a mercurial repository (main repo) with several sub repositories.

I need a mercurial command to show if the revision of a sub repo changed (including information on old and new revision) in the working copy or if the sub repo state is dirty.

How can I do this?


Solution

  • Most mercurial commands accept the -S or --subrepos flag. Thus by calling hg st -S you get a list of all changed files which include those in the sub-repos, if their state differs from the state recorded in the .hgsubstate file:

    $ cd opengfx/
    $ hg st
    $ hg id
    10065545725a tip
    $ cd ..
    $ hg st -S
    M opengfx/.hgtags
    M opengfx/Makefile
    A opengfx/lang/japanese.lng
    $ cat .hgsubstate 
    785bc42adf236f077333c55c58490cce16367e92 opengfx
    

    As to your wish to obtain the actual revisions, that's AFAIK not possible with one command. However you can always check the status of the individual sub-repos like above or can check them from the main repo by giving mercurial another path to operate on:

    $ hg id -R opengfx
    10065545725a tip
    

    In order to get the status of each repo compared to what is required by the parent repo, I'd resort to some simple bash:

    for i in $(cat .hgsubstate | cut -d\  -f2); do echo $i is at $(hg id -R $i) but parent requires $(cat .hgsubstate | grep $i | cut -d\  -f1); done
    

    which gives output like

    opengfx is at 10065545725a tip but parent requires 785bc42adf236f077333c55c58490cce16367e92
    

    In a similar fashion you can also check whether the state is modified by using hg st instead of hg id.