By default Hg will not warn you about the files created, but not yet added. This can result in a situation where you have created a commit, but that commit does not include newly created files. Everything seems fine, but the push is incomplete.... and you transfer to a new machine and you're missing files, or your colleagues are confused. This happened to me a couple of times, so I looked for ways to avoid it in the future. Admittedly, it's not hard to check for status every time before a commit, but you can still forget it sometimes. I usually dealt with this with an com --amend option after realizing I forgot to hg add, but there is a saying "if something bothers you more then 3 times within a week, make sure to fix it." So, here's how.

First, you will need my command line utility. It's a trivial thing that only returns a status code based on whether there was some standard input piped in. AnyStdIn.zip This will only work on 64-bit OS-es (Windows). Make sure it's on your Path system variable.

Second, you need to modify your .hg/hgrc file inside the repository that you want this hook to be relevant to. I prefer to have this for all repos, so I put it inside mercurial.ini file. What this does is creates a "hook" that will fire before the commit event, it will list all "untracked files", and if there are any they will be piped into AnyStdIn.exe, which will return status code 1 and abort the commit.

[hooks]
precommit.No_Untracked_Files = hg st -u | AnyStdIn

 

And... that's it. If there are untracked files, the message will be something like:

abort: precommit.No_Untracked_Files hook exited with status 1

If for any reason you'd want to avoid this check you'd have to temporarily comment this hook's line.


If you're finding this article helpful, consider our asset Dialogical on the Unity Asset store for your game dialogues.


Log In:




Comments (0)