Automatic svn file addition/removal

subversion plus minusYou have files under version control, which are updated through a different mechanism (software update, another VCS such as git, …) or are using svn to archive automatically generated files? Then you are likely to constantly manually determine the appropriate svn add and svn rm commands. This can be automated…

The power of the Unix shell comes from the ability to daisy-chain simple commands, most of them reading from standard input and writing to standard output. The resulting pipeline can be very powerful. Here is an example. The output of svn status (which files need to be added or removed) can be processed by the stream editor sed to result in the right file names for the resulting svn add and svn rm commands with the help of xargs, which turns its standard input into command-line parameters for the given command.

So if you want to mark all newly-added files for addition to svn and all removed files for removal from the repository version, just issue the following two lines:

svn status | sed -n 's/^\?.......\(.*\)/\1@/p' | xargs -d '\n' svn add
svn status | sed -n 's/^\!.......\(.*\)/\1@/p' | xargs -d '\n' svn rm

The difference between the two commands (! vs. ? and rm vs. add) are highlighted in red for educational purposes. Enjoy the power of the shell!

Ein Gedanke zu „Automatic svn file addition/removal

  1. Marcel Waldvogel Autor des Beitrages

    The default xargs on MacOS X does not support the -d option. Install Homebrew and then run brew install findutils first to install the GNU version of xargs.

    By default, this is called gxargs. You can either change xargs to gxargs in the code above or run sudo ln -s gxargs /usr/local/bin/xargs. The latter may be more comfortable but may introduce incompatibilities, so use the ln method only if you know what you are doing!

Schreibe einen Kommentar