How do you check if the mercury repo is clean?

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

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

+7
source share
4 answers

If you issue the hg identify --id , it will be the suffix of the identifier with the + symbol when files are changed in the repository. (Note: this flag does not indicate unplayable files.)

If you select the result of this command for the + symbol, you can use the exit status to determine if there are any changes or not:

 $ 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 
+6
source

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) 
+3
source

Most major programming languages ​​have an HG API that you can access.

0
source

This answer may be useful for other people looking for this topic:

I agree with @Steve \ Kayes comment above that hg status is a good command for programmatic consumption.

Here is an example of how to use it in a bash script:

 #!/bin/bash set -e cd /path/to/hg-repo repo_status='hg status | wc -l' if [ $repo_status -ne 0 ]; then echo "Repo is not clean" else echo "Repo is clean" fi 
0
source

Source: https://habr.com/ru/post/917944/


All Articles