EDIT: Updated to work with file paths containing whitespace, except for newlines. Tested in bash 3.2.17 on Mac OS X.
Also see these questions.
#!/bin/bash
OLD_IFS=$IFS
IFS=$'\n'
for path in $(svn st | awk '/^\?/ { $1=""; print substr($0, 2) }'); do
rm -r "$path"
done
IFS=$OLD_IFS
Let's break this down.
OLD_IFS=$IFS
IFS=$'\n'
Saves the old value of $IFS
(the shell's input field separator) and changes the value to a newline. This will let us loop over things containing spaces, only going to the next iteration when we hit a newline character.
for path in $( ...
Loop through the results of the command substitution inside $( )
.
svn st | awk '/^\?/ ...
Prints all lines from svn st
(same as svn status
) that begin with ?
.
{ $1=""; print substr($0, 2) }'
Removes ?
and leading whitespaces, leaving only the un-versioned paths in your working copy.
rm -r "$path"
Delete the path, passing -r
in case the path is a directory. There's no need to check if the path is a directory because an un-versioned directory can't contain versioned content.
IFS=$OLD_IFS
Restore the value of the shell's input field separator.