Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

svn moving directories to reorganize repo

Tags:

svn

I have a svn repo containing main directories like this:

/apples/
/bananas/
/pears/

In my working copy, those are actually subdirectories of a much bigger tree...

/food/fruit/apples
/food/fruit/bananas
/food/fruit/pears
/food/veggies/asparagus
/food/veggies/broccoli

I would like to reorganize my repo so that /food/ is in fact the root of the repo... but my working copy is a live server, so I need to be very careful not to break anything, even for a minute. It's also a really large tree, so rolling back a mistake could potentially create a noticeable downtime.

If this were just moving folders within the repo, I think I'd know how to use svn move with repo arguments (and I assume that is still step #1?)... but I'm not sure how to apply the change to the working copy, then add the parent folders, while not screwing up the existing working files.

MY ANSWER: thanks to A.H.

1) Make sure the repo is up-to-date and then move the branch within the repo. This can be done using svn move commands on the repo itself or through actions on a working copy. This does not affect the live working copy (don't svn update yet!). This is the easy part.

2) svn switch the branch to the new location. In this example, whereas fruit was previously the root of the repo:

svn switch https://host/svn/fruit /food/fruit

I didn't know much about svn switch previously, but this wasn't too tricky. This changes all the .svn metadata, but does not affect actual files.

3) Here's the tricky part. You need to take these steps in rapid succession for minimal downtime (they're each very fast):

mv /food/fruit /food/fruit-temp
svn co --depth immediates https://host/svn/ /food/
rm -rf /food/fruit
mv /food/fruit-temp /food/fruit
svn update --set-depth infinity /food/

What's happening here is that the checkout with --depth immediates creates the metadata for the contents of /food/ and creates the /fruit/ subdir but not its contents (we need to use rm -rf so we can get rid of the .svn folder inside fruit, but that's all that's there). Then we just swap the real content back in, and the parent and child are now stitched together. Once the mv is done, we're back online. The set-depth infinity extends the scope of the working copy to what you'd expect. Finally we can svn add the child's siblings (eg- veggies).

like image 438
dlo Avatar asked Oct 05 '11 19:10

dlo


People also ask

How do I move a directory in svn repository?

Moving files and folders select the files or directories you want to move. right drag them to the new location inside the working copy. release the right mouse button. in the popup menu select Context Menu → SVN Move versioned files here.

What does svn relocate do?

The --relocate option causes svn switch to do something different: it updates your working copy to point to the same repository directory, only at a different URL (typically because an administrator has moved the repository to another server, or to another URL on the same server).

How do I move files in svn without losing history?

If you right-drag the folder and use "SVN move versioned item(s) here", then you keep the history.


1 Answers

My first tip is to do start with a fresh working copy which is NOT live. In that working copy (WC) you can try out things without any danger. Thats what working and copy really means ;-)

Another tip: Use the second working copy to rearrange the existing structure step by step into the structure you want. After everything is in place, check in. Please keep in mind that rearrangements must be done using the svn commands.

Then use another working copy to check, that your last checkin did indeed what you indented.

Then you can update your live working copy OR simple switch that last WC with the live site using the normal mv command.

Step by step:

svn co $URL new-wc
cd new-wc
svn mkdir food
svn mkdir food/fruit
svn mv apples food/fruit
svn mv bananas food/fruit
svn mv pears food/fruit
svn ci

Now checkout a fresh WC to verifiy - the live WC is still unchanged!

cd ..
svn co $URL verify-wc
# take time and verify

Now switch the live WC and the verify WC in the filesystem - this is fast if they are on the same filesystem!

mv live-wc live-wc-old
mv verify-wc/food/fruit live-wc

Now the live WC is fixed. An alternative for the ast block can be:

cd live-wc
svn switch $URL/food/fruit

This should do nothing time consuming - but please check this with a backup copy first :-)

like image 140
A.H. Avatar answered Sep 25 '22 00:09

A.H.