tags:

views:

285

answers:

3

Hi,

I need some clarification about the behaviour of "svn switch". I'm using svn version 1.6.5.

From reading the manual, my understanding of the behaviour is that local changes will be preserved. So I would expect a locally-added file to still exist in my working directory after svn switch.

However, my colleagues and I have seen several instances where new files get deleted by the switch. Unfortunately, we can't figure out how to reproduce this.

Is there some circumstance (either a feature or a known bug) under which "svn switch" deletes locally-added files?

+4  A: 

I think it's a bad idea to switch, when you have uncommitted changes. First, commit your local changes to a branch with svn cp . <branch URL>, and then switch. There may be very tricky situations you can get into otherwise.

Imagine, that in a version you're switching to, the files you added locally already exist, and are completely different. Or, what if you added a whole directory of files, which can't be adequately merged with the files in the version you're switching to. Do you really want that one big conflict?

There's "S" state shown by svn status, meaning that different parts of your source tree have different versions. It happens exactly when SVN is confused with local changes during a switch. It just gets broken in a middle of switch, and then it's a pain in the neck to recover. Happened to me several times. That's why I always make sure, that my working copy has no local modifications before I run svn sw.

Ivan Krechetov
Thanks Ivan. When you say "commit your local changes to a branch with svn cp", presumably I should use a temporary, developer-specific branch? i.e. not the one I ultimately want to switch to, since my changes are not complete yet.
Yes. That would be some kind of your personal "work in progress" branch.
Ivan Krechetov
+2  A: 

It should not delete either locally added files or unversioned files. The edge cases are where a directory is moved or removed by the switch, but there should be a tree conflict in that case.

What I often do, if I think there may be tree conflicts, is to save a patch of my current changes. Then I know I can wipe out my working copy and start again if necessary, without losing my work.

svn diff > ../somewhere/safe/save.diff
# Break stuff
patch -p0 < ../somewhere/safe/save.diff
Andrew Aylett
hadn't thought of that :)
Pondidum
Thanks Andrew. I did try that in the past but the limitation of svn diff is that it doesn't show new files - only modified ones.
If you `svn add` a file, it'll appear in the diff, even before you check it in.
Andrew Aylett
A: 

The behaviuor of svn switch is very similar to svn update: if the target of the switch is a path in which some file is missing in respect of the working copy, those files will be deleted from the working copy.
Like Ivan said, you should commit your changes and then switch.

Davide Gualano