2 thoughts on “Cool Bash One-Liner: SVN add all unadded files

  1. This is really handy, I’m glad I came across it! This tip becomes even more useful if you transform it into a bash function and place it in ~/.bashrc or someplace similar. Here’s my version:

    function svnaddall () {
    svn status $@ | grep “^?” | awk ‘{ print $2 }’ | xargs svn add

    The $@ passes any arguments on to ‘svn status’, which allows you to add only specific files and directory hierarchies without cd-ing to each directory and running the command. For example, ‘svnaddall foo.txt bar’ would avoid anything in any other part of the hierarchy under the current directory. Typing ‘svnaddall’ with no arguments has the same effect as your one-liner.

  2. After posting, I realized that handling path names with spaces in them is tricker, but still doable. Here’s one way: (Note: bash uses $IFS as the delimiter for splitting strings.)

    function svnaddall () {
    export IFS=$’\n’ # set Bash internal field separator to end-of-line char
    for resource in `svn status $@ | grep “^?”`
    svn add “`python -c \”print ‘$resource'[1:].strip()\”`”
    export IFS=$ORIG_IFS # Restore previous internal field separator

Comments are closed.