0

I find the best solution for my problem here: Howto fix subversion «!» status

But now, I just wish to write a small script to do that.

Like this:

svn status | grep '\!' | awk '{print $2}' | xargs svn revert

svn status | grep '\!' | awk '{print $2}' | xargs svn delete

But in one line.

Because, after the svn revert, "svn status | grep '!'" return no results. Rational.

I think that I found a solution: Putting the data passed to xargs twice in one line but I'm little rusty in English and command line isn't my strong skills.

Community
  • 1
  • 1

2 Answers2

1
svn status | grep '\!' | awk '{print $2}' | tee list.$$ | xargs svn revert
xargs svn delete < list.$$
rm list.$$

The tee command is like a T pipe fitting; one copy of the output goes to each named file and another to standard output. Here, I've named just one file. This forces all the reverts to happen before any of the deletes.The name list.$$ is a simple way of protecting the script from trampling on the files of other processes; there are programs like mktemp that can be used to create more secure, less predictable names. OTOH, if you aren't running in hostile environments, it is unlikely to matter. If you're being really careful, you'll create a trap to ensure the file is cleaned up:

tmp=${TMPDIR:-/tmp}/list.$$
trap "rm -f $tmp; exit 1" 0 1 2 3 13 15

svn status | grep '\!' | awk '{print $2}' | tee $tmp | xargs svn revert
xargs svn delete < $tmp

rm $tmp
trap 0

There are other tricks that could be tried, but at least some of them don't guarantee the sequential operation. For example, process substitution in bash:

svn status | grep '\!' | awk '{print $2}' | tee >(xargs svn revert) | xargs svn delete

Each file will be both reverted and deleted, but the sequencing is not predictable.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
1

Both commands in one line. Note the complete loss of xargs. Not that xargs isn't wonderful, it is just not needed here.

x="$(svn status | grep '\!' | awk '{print $2}')"; svn revert "$x" && svn delete "$x" || echo "no svn delete $?"

Note that the svn delete will not run if the svn revert fails. The "no svn delete" indicates one of the svn commands failed.

Gilbert
  • 3,740
  • 17
  • 19