Why doesn't svn switch work in some cases?

In some cases if there are unversioned or ignored items in the working copy, svn switch can produce an error. The switch stops, leaving the working copy half-switched.

Note: If you take the wrong corrective action you can end up with an unusable working copy. Sometimes the user is instructed to do svn cleanup, but the svn cleanup may also encounter an error. Users can manually remove the directories or files causing the problem, and then run svn cleanup, and continue the switch, to recover from this situation.

Note that a switch from a clean checkout works without error. There are three ways of working if you are using svn switch as part of your development process:

  1. Fully clean your working copy of unversioned (including ignored) files before switching. WARNING! This deletes all unversioned dirs/files. Be VERY sure that you do not need anything that will be removed.
  2. Check and delete svn unversioned files:
    svn status --no-ignore | grep '[I?]' | sed
        's/[I?]//' svn status --no-ignore | grep '[I?]' | sed 's/[I?]//' | xargs rm
        -rf
  3. Keep a pristine clean checkout. Update that, then copy it, and switch the copy when a switch to another branch is desired.
  4. Live dangerously :). Switch between branches without cleaning up BUT if you encounter a switch error know that you have to recover from this properly. Delete the unversioned files and the directory that the error was reported on. Then use svn cleanup if needed and then resume the switch. Unless you delete all unversioned files, you may have to repeat this process multiple times.