Part of my software build process includes getting the hash of the working directory parent into a C++ string for inclusion in the “version” output. This is done by using hg identify -i to get the global revision id, and copying this output into a .h file for inclusion. I do this in a Windows batch file:
setlocal enabledelayedexpansion
for /f "tokens=1 delims=;=" %%a in ('hg identify -i') do (
echo const std::string revision^(_T^("%%a"^)^); > rev.h
)
Which will output something like this into the file:
const std::string revision(_T("3b746fd492c6"));
If the working directory has any uncommitted changes, the hash has a + appended, making the string "3b746fd492c6+". This allows me to easily check whether the version of software I have built is controlled or not – if the string includes a + then the software is not reproducible from the repository.
However, hg identify adds a + to denote uncommitted changes, but it does not recognised untracked files. If I commit all changes but forget to add that all-important “do stuff” class, hg identify will not indicate this.
So my question is: how can I get the required functionality?
How can I simulate hg identify recognising new and removed files?
Ideally I would like to not have to use extensions, but will consider them as an option.
Update
Following on from Oben Sonne’s suggestion of using a combination of hg st and hg id -r . I have come up with the following batch file which produces quite a nice result:
@echo off
set REPOMODS=
for /F %%a IN ('hg st -n') DO set REPOMODS=+
for /f "tokens=1 delims=;=" %%a in ('hg identify -i -r .') do (
echo const std::string revision^(_T^("%%a%REPOMODS%"^)^); > rev.h
)
%REPOMODS% is empty unless there is anything in the output of the hg st, in which case it is +. I’ve done a few tests and it seems to work.
Is there another solution which requires less faffing in batch files? Or is this the best I’ll get?
How about simply checking if the output of
hg stis empty? If not, add a+yourself to the version (if not already given byhg id).UPDATE: To prevent the double
+issue, you could runhg id -r ., which never gives you a trailing+.