RSS
 

Posts Tagged ‘Subversion’

Subversion and Git

30 Sep

They usually don’t play nice with each other. But what if we need a plugin/repository available for git AND for svn?

The "new" way

It used to work – but since a few weeks it doesn’t anymore.
It WAS possible to checkout any github rep via SVN. Sounds crazy, but that was really working:
https://svn.github.com/[user]/[repository]
Anyway – doesn’t seem to be to stable, yet. So I don’t use this approach anymore.

The classic way

This works no matter what Subversion or Git do. It relies on the fact that they don’t get mixed up.
We exclude the .git and .svn dirs from each others rep.

Let’s say we already have our svn rep. We also want it to be in git.
We first create an empty git rep in the root folder of the rep: "Git Create Rep here".

I assume you already have the following excludes in your global svn settings (called "global ignore pattern"):
_* .git .gitignore
As you can see, i also like to exclude all tmp files (starting with _ like "_test.php").

Create a .svnignore file in the root folder of the rep:

.svn
_*

We want to exclude tmp files as well as all svn related stuff.

Now add your files to git "master", commit them and synch with your newly created git rep. Usually the url is something like:
git@github.com:[user]/[repository].git

That’s it – your done!
They don’t interfere with each other. So there shouldn’t be any complications. Furthermore you can now chose which merging "engine" you want to use as they both work on the very same rep.

Live Example

Math Plugin: It is located in subversion (rep is not public, though) and in git. If I update the code, I just have to make sure, that i commit to both "sources". Otherwise one will be outdated.
Just to be sure you should consider ONE source the primary one. No matter what this should be the one to commit to, first.

 
No Comments

Posted in Git, SVN

 

Subversion and multiple CakePHP apps

02 Jul

A few days ago i already wrote about how to set up a svn for cake.
In this second part i will cover the aspect of managing several apps.

The Problem

We have several apps, each with its own cake and vendor folder. If you need to update from 1.3.1 to 1.3.2 you would need to do that for each of your cake cores. Woudn’t it be nice if you changed one and all others would be updated automatically?

The Solution

Lets say, our apps have the following svn rep. urls:
http://123.456.789.000/app1
and
http://123.456.789.000/app2

Both have the same structure:
/root/trunk/app/…
(/root/trunk/vendors/…)
(/root/trunk/cake/…)

Both vendor and cake folder we now want to substitute with our shared folders

Sharing Cake Core and Vendors

We now put our cake core in svn under the following url:
http://123.456.789.000/cake13

and vendors:
http://123.456.789.000/vendors

In both apps, we need to edit the properties for the /trunk folder with the following schema:
svn:externals svn_url local_folder
Result:
svn:externals http://123.456.789.000/cake13 cake
svn:externals http://123.456.789.000/vendors vendors

If you update the cake13 or vendors svn, both apps will get the updated version.
Especially if you have more than 2 apps, this will be very helpful.

Extending to other folders

/app/plugins is a very common folder where you should use svn:externals instead of just copying your plugins to all apps. One change in any plugin version will affect the other ones.

/app/libs can have subfolders, too. So /app/libs/lib/… could contain a "library of libs" for all apps.
The same goes for /app/views/helpers, /app/controller/components, /app/models/behaviors/ etc

Your test cases should be in "lib" folders then, too.
E.g:
/app/controller/components/lib/upload.php
/app/tests/cases/components/lib/upload.php
Both inside those shared lib folders which are attached with svn:externals (in this case parent folder "components").

This might make sense in some cases. Most of the time, though, it’s better to create some kind of "tools" plugin where you can combine all your "library" files (common libs, helpers, components, behaviors, …).
And the test cases are easier managed, as well.

Final tips

You don’t necessarily need seperate svns for each external folder. They could all reside in one.
E.g with "common" svn:

svn:externals http://123.456.789.000/common/cake13 cake
svn:externals http://123.456.789.000/common/subfolder1/subfolder2/vendors vendors

Any svn subfolder is valid

NEW: Use github reps as external svns

Now you can include github reps in svn reps. Its as easy as including
svn:externals https://svn.github.com/[user]/[repository]
in your folder properties.

This is especially useful, if you want to include one of the many cake plugins available at github without manually including it (changes would not be adopted).
Thats how i include my tools plugin in all my apps:
svn:externals https://svn.github.com/dereuromark/tools tools
(in my /app/plugins folder properties)

Note: Currently it does not seem to work the other way around. Although planned to be available very soon, it didn’t work for me committing to such a git-svn rep externally included.
But most of the time, a simple checkout is more than enough. If you need to change the rep, you can do that with git itself and then update the svn rep (it will get the changes then anyway).

 
3 Comments

Posted in CakePHP, SVN