How should one deal with Mercurial's "nothing changed" error ($? = 1) for scripted commits?

Viewed 599

I'm cleaning up a client's tracking system that uses Mercurial (version 2.0.2) to capture state and automatically commits all changes every hour. I migrated it from cron to Rundeck so they will get status if/when things fail, which immediately caused the job to start filling Rundeck's failed jobs due to "nothing changed" errors. I immediately went to Google and I am surprised that this issue is raised, but I did not find answers.*

It seems like three should be a basic, clean sh or bash option (but their command line environment supports Python and pip modules if necessary).

My go-to responses for this type of thing are:

  1. issue the 'correct' command before issuing the command that might fail when things are OK, then failure of the command actually indicates errors
  2. read the docs and use the error codes to distinguish what's happening, implementing responses appropriately**
  3. do some variant of #1 or #2 where I issue the command and grep the output***

* I will concede that I struggle to search for hg material, in part because of the wealth of information, similarity to git, and my bad habit of thinking in git terms. That being said, I see the issue out there, including "[issue2341] hg commit returns error when nothing changed". I did not find any replies to this and I find no related discussion on StackOverflow.

** I see at https://www.selenic.com/mercurial/hg.1.html that hg commit "Returns 0 on success, 1 if nothing changed." Unfortunately, I know there are other ways for commit to fail. Just now, I created a dummy Mercurial (mq) patch and attempted a commit, getting "abort: cannot commit over an applied mq patch". In that instance, the return code was 255.

*** I suppose I can issue the initial commit and capture error code, stdout, and stderr; then process the text if return is 1 and error or continue as appropriate.

3 Answers
Related