hg diff/status always returns zero?

Giorgos Keramidas keramida at ceid.upatras.gr
Wed May 6 15:31:44 CDT 2009


On Wed, 6 May 2009 15:55:07 -0400, Stephen Rasku <mercurial at srasku.net> wrote:
> On Wed, May 6, 2009 at 15:32, Ted Pavlic <ted at tedpavlic.com> wrote:
>>> It seems that "hg status" and "hg diff" always return zero
>>> regardless of whether there are changes or not.  Is this correct?
>>>  If so, is it deliberate?  I would like to call these functions from
>>> a script and having a non-zero return code when there are changes
>>> would simplify my development.
>>
>> When would you want it to return a non-zero value? Is it enough to
>> have new untracked files? Or would you want it to return non-zero
>> only if a tracked file was modified/deleted or a file was added?
>
> For "hg status" I would say the second case. Untracked files are, by
> definition, not part of the repository so it shouldn't affect the
> return value of "hg status".
>
> For "hg diff" it should return a non-zero status if any diffs are generated.

That's arguably wrong.  How would you distinguish between a non-zero
status that means "there are diffs" and a non-zero status that means "an
exception was thrown and hg displayed a traceback"?

I think Ted is right that it's not very clear why or when diff/status
should return non-zero for operations that didn't raise an exception,
so their current mode seems a good 'failsafe default'.




More information about the Mercurial mailing list