Does 'svn switch' ever delete locally-added files?
Asked Answered
A

3

15

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?

Acosta answered 11/12, 2009 at 10:51 Comment(0)
D
11

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.

Detoxicate answered 11/12, 2009 at 10:54 Comment(3)
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.Acosta
Yes. That would be some kind of your personal "work in progress" branch.Detoxicate
This doesn't really work if the path to your project within your repository has changed (due to the admin moving it), since the reason you are switching is to check in your work.Lenis
O
7

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
Orthorhombic answered 11/12, 2009 at 11:1 Comment(2)
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.Acosta
If you svn add a file, it'll appear in the diff, even before you check it in.Orthorhombic
N
0

The behaviour of svn switch is very similar to svn update: If the target of the switch is a path in which some file is missing with respect to the working copy, those files will be deleted from the working copy.

Like Ivan said, you should commit your changes and then switch.

Nosewheel answered 11/12, 2009 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.