[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn switch to an incorrect branch deletes modified local files

From: Karl Fogel <kfogel_at_red-bean.com>
Date: Wed, 23 Apr 2008 19:51:28 -0400

Aaron Eppolito <aarone_at_apple.com> writes:
> I've posed this warning on Apple's internal svn mailing list and a few folks
> have suggested I file it as a bug. It seems policy is to bring it up in this
> forum first. I've searched through the bugs and the ~950 matches on "switch"
> on this list and haven't heard mention of the problem.
>
> In very short summary, if you inadvertently switch a subdirectory to a branch/
> tag/head of the root level, it will DELETE all files in the subdirectory,
> INCLUDING locally modified files.
>
> A concrete example:
>
> [myproject/Subdirectory/Files]% svn stat
> M file1.cpp
>
> [myproject/Subdirectory/Files]% svn switch https://svnserver/myproject/trunk
> D file1.cpp
> D file2.cpp
> D file3.h
> A //// the entire trunk's directory structure...

Yes, "D file1.cpp" will fly by in the output, but 'file1.cpp' is still
there on disk -- it is preserved (as a now-unversioned file) precisely
because it was in a modified state when still versioned.

> I understand that what I should have done was this:
> [myproject/Subdirectory/Files]% svn switch https://svnserver/myproject/trunk/
> Subdirectory/Files
>
> That said, svn has enough information to know that switching to a new working
> copy rooted in the current directory is not the right thing. It should have
> warned, saying something like "This directory does not correspond to https://
> svnserver/myproject/trunk".

No, switching to a new working copy rooted in the current directory is
fine -- people do it all the time, and Subversion has no way to know
whether it's right or wrong for your given situation.

> At the very least, it shouldn't be deleting files with modifications!

It's not, see above :-).

In case you're in any doubt, here's a reproduction script:

----------------------------------------------------------------------
#!/bin/sh

# Modify the next line to point to your Subversion tree.
SVNDIR=/home/kfogel/src/subversion

SVN=${SVNDIR}/subversion/svn/svn
SVNSERVE=${SVNDIR}/subversion/svnserve/svnserve
SVNADMIN=${SVNDIR}/subversion/svnadmin/svnadmin
URL=file:///`pwd`/repos

rm -rf repos wc *-wc import-me

${SVNADMIN} create repos

echo "### Making a Greek Tree for import..."
mkdir import-me
mkdir import-me/trunk
mkdir import-me/tags
mkdir import-me/branches
mkdir import-me/trunk/A
mkdir import-me/trunk/A/B/
mkdir import-me/trunk/A/C/
mkdir import-me/trunk/A/D/
mkdir import-me/trunk/A/B/E/
mkdir import-me/trunk/A/B/F/
mkdir import-me/trunk/A/D/G/
mkdir import-me/trunk/A/D/H/
echo "This is the file 'iota'." > import-me/trunk/iota
echo "This is the file 'A/mu'." > import-me/trunk/A/mu
echo "This is the file 'A/B/lambda'." > import-me/trunk/A/B/lambda
echo "This is the file 'A/B/E/alpha'." > import-me/trunk/A/B/E/alpha
echo "This is the file 'A/B/E/beta'." > import-me/trunk/A/B/E/beta
echo "This is the file 'A/D/gamma'." > import-me/trunk/A/D/gamma
echo "This is the file 'A/D/G/pi'." > import-me/trunk/A/D/G/pi
echo "This is the file 'A/D/G/rho'." > import-me/trunk/A/D/G/rho
echo "This is the file 'A/D/G/tau'." > import-me/trunk/A/D/G/tau
echo "This is the file 'A/D/H/chi'." > import-me/trunk/A/D/H/chi
echo "This is the file 'A/D/H/omega'." > import-me/trunk/A/D/H/omega
echo "This is the file 'A/D/H/psi'." > import-me/trunk/A/D/H/psi
echo "### Done."
echo ""
echo "### Importing it..."
(cd import-me; ${SVN} import -q -m "Initial import." ${URL})
echo "### Done."
echo ""

${SVN} cp -q -m "Create branch 'mybranch'." \
       ${URL}/trunk ${URL}/branches/mybranch

${SVN} co -q ${URL}/trunk trunk-wc
${SVN} co -q ${URL}/branches/mybranch branch-wc

cd trunk-wc
${SVN} rm -q iota
${SVN} ci -q -m "Delete iota from trunk."
cd ..

cd branch-wc
echo "A modification to iota on the branch." >> iota
${SVN} switch ${URL}/trunk
cd ..

echo ""
echo "###"
echo "### You just saw 'iota' appear to be deleted. But look,"
echo "### if we run 'cat branch-wc/iota', the file is still,"
echo "### there, although it is no longer versioned:"
echo "###"
echo ""
cat branch-wc/iota

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: dev-help_at_subversion.tigris.org
Received on 2008-04-24 01:51:49 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.