You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Chen锛锛? Jun锛锛? <ch...@hotmail.com> on 2006/08/19 10:29:38 UTC

BAD! 'svn diff' exits with 0 when some difference exists.

For SVN 1.3.2 .

I've just found that 'svn diff' command's exit-code is 0 even if it has 
found some difference. 

It's unbelievable, since 'cvs diff' returns non-zero if some difference is 
found, which is surely reasonable. 

The makefiles for my GNUmake-based make system stores a list of local 
directories that is under source control, so that my make system can 
automatically cd to that list of dirs and do 'cvs diff' or 'svn diff' in 
order to check whether some files has been locally modified. If 'cvs diff' 
or 'svn diff' returns non-zero, my make system immediately knows some local 
modification has existed and the make system stop running to notify its 
user. If 'svn diff' always return 0, it will be programmatically hard to 
know when difference occurs and stop the make system.

_________________________________________________________________
享用世界上最大的电子邮件系统― MSN Hotmail。  http://www.hotmail.com  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: BAD! 'svn diff' exits with 0 when some difference exists.

Posted by Branko Čibej <br...@xbc.nu>.
Peter Samuelson wrote:
> [Ben Collins-Sussman]
>   
>> I think this is intentional;  when the 'svn' binary returns 0, it
>> means "no error happened", and non-zero means "an error happened".
>> It's certainly not an error to print out a difference!  I might argue
>> that 'cvs diff' is being a bit strange when it does this.
>>     
>
> This has come up before (issue #2513), and it's been noted that the
> Unix utility 'diff' also returns 1 for differences found, 2 for error.
> So it's not CVS being weird, it's Unix diff being weird and CVS playing
> along.
>   

Plain diff basically mimics cmp in this respect, and behaves as it does
on the assumption that it makes it easier to use in tests in shell
scripts; e.g.,

    if [ cmp foo bar ]; then echo foo and bar differ; fi

The assumption is of course wrong, because such a test won't notice the
difference between a 1 and 2 exit code, so the test has to be more complex.

> I think it'd be better for svn diff to agree with diff and cvs diff,
> but I don't know whether that would break your 1.x compatibility
> contract.
>   

Yes, it would.

>>> If 'svn diff' always return 0, it will be programmatically hard to
>>> know when difference occurs and stop the make system.
>>>       
>
>   
>> How about just looking at stdout?  If anything is printed to stdout,
>> there's a difference.  Doesn't that make more sense anyway?
>>     
>
> Alternatively, 'svn status' is intended to be machine-parseable.
>   

Yes, but 'svn status' doesn't have all the different modes that 'svn
diff' has, so they're not interchangeable.

-- Brane

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: BAD! 'svn diff' exits with 0 when some difference exists.

Posted by Peter Samuelson <pe...@p12n.org>.
[Ben Collins-Sussman]
> I think this is intentional;  when the 'svn' binary returns 0, it
> means "no error happened", and non-zero means "an error happened".
> It's certainly not an error to print out a difference!  I might argue
> that 'cvs diff' is being a bit strange when it does this.

This has come up before (issue #2513), and it's been noted that the
Unix utility 'diff' also returns 1 for differences found, 2 for error.
So it's not CVS being weird, it's Unix diff being weird and CVS playing
along.

I think it'd be better for svn diff to agree with diff and cvs diff,
but I don't know whether that would break your 1.x compatibility
contract.


> >If 'svn diff' always return 0, it will be programmatically hard to
> >know when difference occurs and stop the make system.

> How about just looking at stdout?  If anything is printed to stdout,
> there's a difference.  Doesn't that make more sense anyway?

Alternatively, 'svn status' is intended to be machine-parseable.

Re: BAD! 'svn diff' exits with 0 when some difference exists.

Posted by Ben Collins-Sussman <su...@red-bean.com>.
On 8/19/06, Chen(陈�? Jun(军�? <ch...@hotmail.com> wrote:
> For SVN 1.3.2 .
>
> I've just found that 'svn diff' command's exit-code is 0 even if it has
> found some difference.

I think this is intentional;  when the 'svn' binary returns 0, it
means "no error happened", and non-zero means "an error happened".
It's certainly not an error to print out a difference!  I might argue
that 'cvs diff' is being a bit strange when it does this.

> If 'svn diff' always return 0, it will be programmatically hard to
> know when difference occurs and stop the make system.

How about just looking at stdout?  If anything is printed to stdout,
there's a difference.  Doesn't that make more sense anyway?