Bulk subversion update script using sed

If you use “svn from the command line to manage your Subversion project you might have trouble dealing with the unfriendly and time-consuming task of adding a large set of locally modified files to the subversion repository server. That is, those files detected as new (marked with a ‘?’ character) or locally modified (marked with a ‘M’):

$ svn status
M       project/README
?       project/main.c
?       project/lib
?       project/lib/connector.c

Same issue when propagating locally removed files to the server. In this case those files are marked with a ‘!’ character:

$ svn status
!       project/README.old

I use the following Bash script to automatically add new/modified files to the repository as well as mark for deletion those files that no longer exist locally:

#!/bin/bash
# Add new and locally files to be commited to Subversion repository
svn status | grep '^!' | sed -r 's/^\![ ]+//' | sed -r 's/.*/\"&\"/' | xargs -r svn delete

# Mark for deletion locally removed files
svn status | grep '^?' | sed -r 's/^\?[ ]+//' | sed -r 's/.*/\"&\"/' | xargs -r svn add

This is equivalent to use ‘svn add’ and ‘svn delete’ indivually for each file/directory.

Do not forget to commit your changes after running this script:

$ svn ci -m 'commit message'
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s