incoming exit status

Haszlakiewicz, Eric EHASZLA at transunion.com
Wed Nov 10 20:10:17 UTC 2010


>-----Original Message-----
>From: Vadym Chepkov [mailto:vchepkov at gmail.com]
>
>On Nov 10, 2010, at 1:19 PM, Haszlakiewicz, Eric wrote:
>
>>> -----Original Message-----
>>> From: mercurial-bounces at selenic.com [mailto:mercurial-
>bounces at selenic.com]
>>>
>>> I noticed hg incoming returns 1 if there are no any incoming changes.
>>> What is the reason? I don't think it's an error condition and it breaks
>>> ability to automate unattended builds.
>>
>> I think it's specifically so you can easily distinguish between the
>changes-available and no-changes-available cases.  I have scripts that
>depend on this so I don't have to try to decode the output, which would be
>very sensitive to the exact messages emitted and thus error prone.
>> Actual errors cause hg to exit with a return value higher than 1.
>>
>> eric
>>
>
>well, that does't work well with shell's "set -e"

It's not as simple as just running the hg incoming command, but you can always explicitly check for the return value:
hg incoming || _err=$?
if [ ! -z "$_err" -a $_err -gt 1 ] ; then
	exit $_err
fi

>and you can rely on output if you specify template, at least I would expect
>it will be predictable
>hg -q incoming --template "{rev} {files}\n"

That only affects what you get if there's actually changesets available, not what you see when there's nothing new to pull in. 

>either you have output or not, no?

No, "hg incoming" produces output all the time.

Regardless of whether the output is consistent or now, it's needlessly complex to have to parse it just to get a simple status about whether there were changes available.  
Trying to parse the output also opens you up to unusual text screwing with you.  e.g., say you look for the phrase "no changes found", but someone commits a change with a description that says something like "Fix the 'no changes found' message to say foo instead"
Also, even if you omit all potentially problematic data through a template, you're not even guaranteed that the output will say "no changes found" when there's nothing to pull in.
Someone can decide that they want to see messages in their native language:
> LC_MESSAGES=fr_FR hg incoming
comparaison avec https://myserver.example.com/foo
searching for changes
aucun changement trouv?

eric



More information about the Mercurial mailing list