Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you check if a mercurial repo is in a clean state?

Tags:

dvcs

mercurial

As a user, I usually use hg st to check the status of a repo, and verify that it is in a clean state, with no modified files.

Here I would like to do this programmatically. I know I can also use hg st for that, but the output is less than ideal for consumption by a computer program. Is there a better way to check whether a mercurial repo is in a clean state?

like image 934
static_rtti Avatar asked Jun 13 '12 08:06

static_rtti


2 Answers

If you issue the hg identify --id command, it will suffix the ID with a + character when the repository has modified files. (Note: this flag does not report untracked files.)

If you grep the output of this command for the + character, you can use the exit status to determine whether there are modifications or no:

$ hg init
$ hg identify --id | grep --quiet + ; echo $?
1
$ touch a
$ hg identify --id | grep --quiet + ; echo $?
1
$ hg add a
$ hg identify --id | grep --quiet + ; echo $?
0
like image 120
Laurens Holst Avatar answered Nov 04 '22 15:11

Laurens Holst


You should use hg summary:

$ hg init
$ echo blablabla > test.txt
$ hg summary
parent: -1:000000000000 tip (empty repository)
branch: default
commit: 1 unknown (clean)
update: (current)
like image 29
andref Avatar answered Nov 04 '22 16:11

andref