Icon_search

Batch add/remove files to Subversion

Posted on 01/13/2009 by Travis
 | 

Recently, I was thinking how great it would be to have some script that I could run for a project to automagically add all new files (or remove all deleted files) with subversion. I know, I know, git is the new hotness, so why am I still using subversion? Well, all of our projects here at Plexus are tracked with subversion, and it would be more trouble than it's worth to convert (not to mention re-training everyone who uses it).

Well, I found a great little one-line script that would do exactly what I wanted here. The only problem was that I would never remember that whole line of code, plus I didn't want to type all of that out every time I wanted to run it. So, I decided to add an alias to my .bash_profile file so that I could call that script with just one word.

I played around with single and double quotes for a while trying to get it to act correctly as an alias. The script uses awk, which worked great on the command line, but was backfiring in my alias. Finally, with some Googling and help from Colin, I figured out that the dollar sign in the awk call needed to be escaped. After that, it all worked great.

Here are the two lines that I added to my .bash_profile file:

The first alias will run svn st, get all of the files with a ? next to them (new files that aren't part of the subversion project), then add them to the repository. The second functions similarly, but will svn rm all files that have been deleted from the project.

*NOTE: Make sure you've added an svn:ignore to your project so that it doesn't check in any files that you don't want in the repository.

Tagged:  svn, subversion, bash