I tired of manually adding all the new files in my working copy of various projects in subversion so I started using this command:
svn add svn status | grep ? | awk '{print $2}'
… but I eventually grew tired of looking that up every time. I tried to make that into an alias, but because of the shell escaping it didn’t work as is. I did a bit of digging around and found a non-shell escaped version then added these lines to the bottom of my ~/.profile (I’m sure it would also work in ~/.bash_profile):
alias svnadderall="svn status | grep '^?' | cut -b 8- | xargs svn add"
alias svnridallin="svn status | grep '^!' | cut -b 8- | xargs svn remove --keep-local"
A quick breakdown of how this works:
alias svnadderall =
this is the command that tells bash what will happen when you typesvnadderall. You can change that to whatever you’d be more comfortable with. I used “adderall” and “ridallin” because I’m clever like that (I’ll eventually get sick of the puns, but the ADHD mnemonic will help me get in the habit of using them (yes, I know they’re not spelled correctly; they’re phonetic mnemonics)).svn status |
prints out the status of all your files and passes it togrep '^?' |
finds each line beginning with ? and passes it along tocut -b 8- |
trims off the first eight characters and returns the rest of the lines and passes it toxargs svn add
captures everything and runssvn add [whatever it was passed]
It’s the same for the svn remove except the grep is matching for lines that begin with ! and I’m using a --keep-local flag to prevent svn from trying to remove the file1 (which won’t exist, since it’s missing, remember?).
I tried changing the cut -b 8- to sed 's/^?[ ]+//' and even awk {print $2} but neither worked properly for some reason; the awk based version tried to svn add ? and the sed version sat there waiting for input.
On further consideration, I think cut -b 8- will be the safest. The file name won’t always be the second item in the svn status output. I can’t imagine any situation where that would be the case for non-versioned files, though there might be true for missing versioned files would have a secondary (or tertiary) flag.
If you’re editing your bash_profile or profile be sure to run source ~/.profile (or source ~/.bash_profile) if you want your shell to pick up your changes. You can also logout and log back in (or open a new Terminal.app tab or window) as well.
-
I don’t know if it’s an subversion v1.6 thing or not, but doing an
svn removeon files that do not exist on the file system would exit on the first error, in this case being that the file doesn’t exist. ↩