Want to quickly add all missing files to an SVN repository from the command line? Here’s a recipe to do just that:
svn st | awk '{print "svn add "$2 }' | bash
Perform a check in, so that all modified files, and other file statuses are cleared, then you just pipe svn status into awk, which will prepare the svn add statements, and then pipe those into your shell to actually fire off the commands. Leave off the | bash part at first to make sure everything looks good to you, and then fire away.
If you don’t want to check in everything first, you could also add a little grep in the mix, to target just your new files, so you can do one big check in after the fact:
svn st | grep ? | awk '{print "svn add "$2 }' | bash && svn ci
This assumes you have the SVN_EDITOR environment variable set up in .bash_profile, so that it will stop and ask you for your check-in message: export SVN_EDITOR=/usr/bin/vi You could also just add the -m “My Commit Log Message” flag to the end of the last statement to skip all that.
::adjusts pocket protector::
The grep really isn’t necessary, you know…
awk can apply rules to lines based on lots of logic, for example a regular expression:
svn st | awk ‘/?/ {print “svn add “$2 }’| bash
Which would only act on lines that contained a question mark. Of course you could change the pattern to be more exact using:
/^?/
And if SVN didn’t use a question mark for that status, you wouldn’t need the backslash, but I didn’t invent the thing.