One way to use the Symfony Standard Edition is to download the package, unpack it and start coding. When there is a version update you have to download the updated package and merge the changes into your project manually. It is always well-documented which changes have to be made so this shouldn’t be too tricky.

However there is a more convenient way to keep your project up-to-date. (At least in my eyes.) You can use git to do these updates. All you have to do is to setup the github repository of the Symfony Standard Edition here as a remote repository of your project.

So in order to start a new project I would do the following:

$ cd /path/to/my/project
$ git init .

To add the Symfony repository as a remote repository type:

$ git remote add symfony git://github.com/symfony/symfony-standard.git

The next step is to fetch the contents of the repository:

$ git fetch symfony

You can now see that you have the remote branches and tags in your local repository:

$ git branch -r
symfony/2.0
symfony/master
 
$ git tag
v2.0.0
v2.0.0-RC1
...
v2.0.0PR9
v2.0.1

Next you can checkout the branch into which you want to merge a certain Symfony version and execute the merge:

$ git checkout master
$ git merge v2.0.0-PR12

The PR12 version of the Symfony Standard Edition has been merged to your master branch now.

Let’s simulate how an update would be done. You can create a file called “deps” and write something to it. Then commit this change to the current branch:

$ echo "Some silly content" > deps
$ git add .
$ git commit -m "Some silly commit"
[master 365eee9] Some silly commit
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 deps

Also you can modify the app/config/parameters.ini and set a dummy database user and password:

$ vi app/config/parameters.ini
[ ... ]
$ git add .
$ git commit -m "parameters.ini changed"
[master 0d8a665] parameters.ini changed
 1 files changed, 2 insertions(+), 2 deletions(-)

The next step is to bring the project to version 2.0.1 of Symfony:

  1. $ git fetch symfony
  2. $ git merge v2.0.1
  3. Removing VERSION
  4. Removing app/cache/.gitkeep
  5. Auto-merging app/config/parameters.ini
  6. Removing bin/build.sh
  7. Removing bin/build_bootstrap.php
  8. Removing bin/vendors.sh
  9. Auto-merging deps
  10. CONFLICT (add/add): Merge conflict in deps
  11. Removing src/Acme/DemoBundle/Form/ContactForm.php
  12. Automatic merge failed; fix conflicts and then commit the result.

As you can see your changes to the parameters.ini have been merged automatically without any problems (5). However git could not merge the file “deps” (9-10) intelligently with the recent version and therefore asks you to solve the conflicts manually (12).
The point is that git shows you which files need your attention and you don’t forget any update advice given by the official release notes. Therefore I think this way is safer than updating your project manually.

The last step in the update process is to update the vendors and clear the (production) cache:

$ bin/vendors install
$ app/console cache:clear --env dev
$ app/console cache:clear --env prod

I hope this post could give you some inspiration for version management with Symfony and the usage of git in general. :)

Tags: , , ,

RELATED POSTS

COMMENTS

Ruben de Vries 05 Sep 2011 | 12:06

I used this aproach a while back and I noticed that if I didn’t delete my local repo afterwards and recreated it withouth fetching the remote that doing ‘git push –tags’ would also push the symfony tags into my list of tags … do you have the same problem or am I doing something wrong?

Sebastian Hörl 05 Sep 2011 | 22:15

Yes, git push –tags will copy all tags to the remote repository. This isn’t what you want in most cases. In order to push only one tag to the repository you can simply use “push” with your tag name:
git push repository_name v1.0.0
This way you can even use local tags and only push those tags to the repository that you want to have there.

Just as a note: Tags in git are only simple references which map a more or less senseful name like “v1.2″ or “stable” to a certain commit like “b223a323…”. Because of that it is totally comprehensible why –tags also pushes those tags to the remote repository which don’t really belong to your own project. It’s simply because they keep their meaning and still do what they are intended for. The tag v2.0.0 from the Symfony repository will stand for *that* certain commit to the Symfony project no matter where it is used.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">