You 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!
One response to “Automatic svn file addition/removal”
The default
xargs
on MacOS X does not support the-d
option. Install Homebrew and then runbrew install findutils
first to install the GNU version ofxargs
.By default, this is called
gxargs
. You can either changexargs
togxargs
in the code above or runsudo ln -s gxargs /usr/local/bin/xargs
. The latter may be more comfortable but may introduce incompatibilities, so use theln
method only if you know what you are doing!