Subversion externals are a way to include other packages in your code that are maintained somewhere else.  For example, if I was developing an application that needed to send out mail, I could use SwiftMailer and define that as an external for my project. When I run ”svn up” it will grab files from the SwiftMailer project and copy them locally. (How to define externals is beyond the scope of this post. RTFM!)

One annoying part of externals is that even if there are no changes to your code, your Subversion status output will be filled with externals information. For example, I have included symfony as an external in my project and now the default status output is:

X      lib/symfony

Performing status on external item at 'lib/symfony'
X      lib/symfony/doc
X      lib/symfony/lib/plugins/sfDoctrinePlugin
X      lib/symfony/lib/plugins/sfPropelPlugin
X      lib/symfony/lib/vendor/lime

Performing status on external item at 'lib/symfony/lib/plugins/sfPropelPlugin'
X      lib/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel
X      lib/symfony/lib/plugins/sfPropelPlugin/lib/vendor/phing
X      lib/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator

Performing status on external item at 'lib/symfony/lib/plugins/sfPropelPlugin/lib/vendor/phing'

Performing status on external item at 'lib/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel'

Performing status on external item at 'lib/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator'

Performing status on external item at 'lib/symfony/lib/plugins/sfDoctrinePlugin'
X      lib/symfony/lib/plugins/sfDoctrinePlugin/i18n
X      lib/symfony/lib/plugins/sfDoctrinePlugin/web
X      lib/symfony/lib/plugins/sfDoctrinePlugin/lib/doctrine

Performing status on external item at 'lib/symfony/lib/plugins/sfDoctrinePlugin/i18n'

Performing status on external item at 'lib/symfony/lib/plugins/sfDoctrinePlugin/web'

Performing status on external item at 'lib/symfony/lib/plugins/sfDoctrinePlugin/lib/doctrine'

Performing status on external item at 'lib/symfony/doc'

Performing status on external item at 'lib/symfony/lib/vendor/lime'

This is obviously annoying as it obfuscates the part of the project that I’m working on. The switch command does have an option to ignore externals, aptly called –ignore-externals but I don’t want to have to type that in every time I run a svn st command.

After browsing around the net for a bit, I found this piece of bash script that will swap the defaults for me:

svn() {
        case "$1" in
                st|stat|status)
                        svnargs1=""
                        svnargs2="--ignore-externals"
                        for i in $@; do
                                if [ "--examine-externals" == "$i" ]; then
                                        svnargs2=""
                                else
                                        svnargs1="$svnargs1 $i"
                                fi
                        done
                        command svn $svnargs1 $svnargs2
                        ;;
                *)
                        command svn "$@"
                        ;;
        esac
}

What’s nice about this script is that I can run status on the externals as well by specifying –examine-externals — and they’ll be back, in all their annoying (yet sometimes needed) glory.

On my Mac, I just placed the code in /etc/bashrc and now it’s available as a layer over the svn binary. (You may need to restart your terminal session for it to take effect.)