When developing WordPress plugins, SVN is still used. It’s only used for plugin deployment though, not really during development. So your typical actions are just add files, remove files, tag a directory and commit. I always found adding and removing files such a hassle, so here’s a short script that does it for you.
Background: I regularly release updates to my plugin Stackable, and I find adding and removing SVN files bothersome. And when that happens, automate it!
Creating the SVN Add/Remove Files Script
In my setup, I have an SVN
directory where I store all my code. I have this structure:
SVN
├── my-plugin-code
Go to the SVN
directory, and create a new file called svn-add-remove.sh
vim svn-add-remove.sh
Then when the editor opens, add this inside:
#!/bin/bash
svn status | grep '^!' | awk '{print $2}' | xargs svn delete
svn status | grep '^?' | awk '{print $2}' | xargs svn add
Save and close the file (in vim, press the esc
key, then type in :wq
then hit enter
.
Now you’ll need to make the script executable:
chmod a+x svn-add-remove.sh
You should end up with this directory structure:
SVN
├── my-plugin-code
├── svn-add-remove.sh
Using the SVN Add/Remove Files Script
Now when you add new files in SVN, just head over to your my-plugin-code
folder, then do this:
../svn-add-remove.sh
This will add all the new files, and remove all the deleted files. It’s a real time saver!