RSS
 

Archive for the ‘VersionControl’ Category

Finally – SVN becomes more GITish

17 Oct

The change we all had waited for soo long.

SVN becomes more GITish

With the release of all new 1.7 the thousands of .svn folders are finally history!
Only a single .svn file in the root folder remains. Yes, most of you will immediately think of GIT :)
Well, now SVN uses a sqllite DB to work the same way.
The speed increased, as well.

All you need to do on windows:
- Update TortoiseSVN
- Rightclick on the root folder of your svn folder and select “SVN update working copy”

Details:
tortoisesvn.net/tsvn_1.7_releasenotes.html

Numbers wanted?

To demonstrate how huge this step in the right direction is:
“cake2.0rc3″ – the current 2.0 head – consists of 1518 files.

Before the upgrade to tortoisesvn1.7 the complete folder consisted of 4100 files in 5100 folders. So almost twice as much svn crap – overall 38 MB in size.
After the upgrade the folder counts 2826 files in 848 folders (wow!). File size is now down to 32 MB.

I really like it. Copying/Moving is now so much easier. I had just recently written a script which could delete all tmp folders (.svn) from a directory recursively to be able to merge it into other folders.
This is now history. Merging finally works as easy as in GIT.
Backuping and remote copying is now so much faster due to less structural overhead.

 
No Comments

Posted in SVN

 

SVN and Auto Checkout after Commit

30 Dec

VersionControl is a great thing. But if you work as a web developer you got one problem. Often its better to view a web page in the production environment. And in the most cases its a grate think to have the current development revision online in a production like development environment, so you can show people the current work.

When I started to use subversion, I wanted to have an automatic way to check out the repository to the webroot. And there is a nice way to do this:

The SVN repository has hooks to do work after special events.

If you list your SVN directory you can find a folder called ‘hooks’. This folder contains some “callback” script for all SVN actions.

total 36
-rwxrwx--- 1 root subversion 2769 Aug 3 17:29 post-commit
-rwxrwx--- 1 root subversion 1690 May 29 21:54 post-lock.tmpl
-rwxrwx--- 1 root subversion 2307 May 29 21:54 post-revprop-change.tmpl
-rwxrwx--- 1 root subversion 1606 May 29 21:54 post-unlock.tmpl
-rwxrwx--- 1 root subversion 2982 May 29 21:54 pre-commit.tmpl
-rwxrwx--- 1 root subversion 2038 May 29 21:54 pre-lock.tmpl
-rwxrwx--- 1 root subversion 2764 May 29 21:54 pre-revprop-change.tmpl
-rwxrwx--- 1 root subversion 1980 May 29 21:54 pre-unlock.tmpl
-rwxrwx--- 1 root subversion 2758 May 29 21:54 start-commit.tmpl

The script post-commit is executed by the user of the subversion server after every commit action with the params:
"$REPOS" "$REV"

If you want to have a development website which is up to date all the time you must ensure that the user who runs the subversion server (in my case the user “subversion”) has rights to access the webroot of the development website.
The best way to do this is to add a group (in my case the group “subversion”) with the following command executed by root:
groupadd subversion

After this we add the user of the subversion server (in my case “subversion”) and the user of the webserver (in my case “www-data”) to this group subversion by typing in as root:
usermod -a -G subversion www-data
usermod -a -G subversion subversion

now you can add your fancy commands to the post-commit script.

for a simple checkout it is as simple as:
/usr/bin/svn update /var/www --username username --password password

have fun!

 

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).

 
4 Comments

Posted in CakePHP, SVN

 

CakePHP and Subversion

18 Jun

A Quick How-To about properly setting up a svn for your cake app.

First of all, we need to drop a “trunk” folder into our svn:
/trunk

inside this trunk, we now add
/app (actual app)
/vendors (global vendors)
/cake (cake core)

Now, before committing the first time, we want to make sure that only non-transient files are actually under svn. That means, we need to exclude temporary files as well as all config files containing passwords and other private settings.

a) database.php
You will need to exclude this file in the properties of the parent folder “/trunk/app/config/”.

With tortoise, its as easy as right-clicking on the folder and adding
svn:ignore database.php
But under linux it shouldn’t be that much harder.

b) tmp folder
Exclude all subfolders and files within “/trunk/app/tmp” with
svn:ignore *
But don’t forget to manually add the subfolders like “cache” as well their subfolders (for cache: “persistant”, “models”, “views”).
Now apply the same ignore property on those subfolders, too.

The Result:
/tmp
/tmp/cache
/tmp/logs
/tmp/cache/persistant
/tmp/cache/models
/tmp/cache/views
are all under svn – but any tmp file (either in /tmp directly or in one of the subfolders) will be not.

c) configs – the probably most difficult part

It is never a good idea to submit keys (Akismet, SMTP, FacebookAPI, …) to svn.
so we need to find a solution for this.
This is my advice:

Include both “config.php” and “config_private.php” in exact this order in your bootstrap (with file_exists() in order to prevent errors!). Now all settings in the private config override the public one.

One example:

# config.php
$config['Email'] = array(
	'use_smtp' => 0,
	'smtp_port' => 25,
	'smtp_timeout' => 20,
	'smtp_host' => '',
	'smtp_username' => '',
	'smtp_password' => '',
);
 
# config_private.php
Configure::write('Email.smtp_password', '123');
//...

This way every developer can use his own private keys and settings without publishing them in the svn.

Hot tips

With Tortoise you can export your properties and easily import it for other upcoming projects (for each folder separately). I save my /config/ exlusions in “config.svnprops” for example.

The same properties can be applied to multiple folders at once by selecting all folders and then right-click on them. This helps to quickly ignore any files in the 3 tmp-subfolders.

Outlook

Soon I will talk about how to manage several apps with the same libraries (like cake and vendors folder).

 
No Comments

Posted in CakePHP, SVN