hg diff/status always returns zero?
Giorgos Keramidas
keramida at ceid.upatras.gr
Wed May 6 17:45:51 CDT 2009
On Wed, 6 May 2009 17:42:58 -0400, Stephen Rasku <mercurial at srasku.net> wrote:
>On Wed, May 6, 2009 at 16:54, Kevin Bullock wrote:
>> You can also do this e.g. in bash:
>> if [ ! -z "`hg status -admrn`" ]; then
>> # ...
>> fi
>
> That's cool.
>
> I want to use this functionality in cron. I can create a script
> that's called by cron but with a status return I can do something like
> the following in cron:
>
> 1 9-17 * * * (. .bashrc; cd $PROJECT; hg diff || pwd)
>
> This will send me the diffs and then append the current working
> directory to the e-mail. If there is no diff then I don't get an
> e-mail at all.
This is a good reason, but it may be less than enough to break backwards
compatibility of hg diff and hg stat.
For example, it is often a better idea to write complex conditionals in
shell scripts and call them from crontab, so you can get similar results
by:
1 9-17 * * * /etc/cron.d/mercurial/$PROJECT.sh
Then you can use arbitrarily complex checks in the shell script, without
having to rely on exit codes. I am using something similar to get email
notifications from rdiff-backup scripts:
* Create a `mktemp' file and assign it to $tmplog
* Register a shell trap to cleanup the $tmplog file on exit
* Run commands with their output redirected to $tmplog
* If an error code is returned or grep for error patterns in $tmplog
returns a match, display the $tmplog
This way the checks that control when to display output and how much of
the program output to send to stdout/stderr can be far more elaborate
than a simply `cmd1 || cmd2' check, at a small cost of writing them in a
shell script instead of the crontab itself.
Another reason, which may be more important than this crontab issue is
that the diff/stat commands have been returning 0 for a long time.
If we change that now, it may break everyone's integration of these
commands in their workflow, so such a change should be done with a lot
of care and a great deal of forward warnings. This way everybody will
have time to adjust their derivative tools.
More information about the Mercurial
mailing list