tags:

views:

87

answers:

3

I'm trying to wrap a standard sequence of steps in a shell script (linux/bash) and can't seem to figure out how to tell if the execution of svn status returned anything. For example

~/sandbox/$svn status
?       pat/foo
~/sandbox/$echo $?
0

If I delete the foo file, then the

svn status

return nothing, but the echo $? is still 0

I want to not do some steps if there are uncommitted changes.

Pointers greatly appreciated.

+1  A: 

I have implemented something similar a while back. You should not rely on the return value of svn status, but parse its output instead. For example you should look for lines starting with "M", "A", "D", etc. You can use perl to help you with this. Based on the result of that parsing you'll certainly know if there are changes or not.

Btw it's not normal for svn status to return 0 if there are no changes - after all this return code simply signifies that no errors occurred.

Bozhidar Batsov
+1  A: 

Why not test the result from svn status -q? Something like:

result=`svn status -q`
[ -z "$result" ] && echo "No changes" && exit 1

echo "Changes found"
exit 0
qor72
Yes, I took this idea and ended up with something very similar:[code]if [ -z "$(svn st)" ]; then echo "working copy is pristine"else echo "working copy has changes" exit;fi[/code]
fishtoprecords
+1  A: 

Or you could try

svn status | grep [AMCDG]
echo $?

should return 0 if there are changes and 1 if there are none

DrewM