Using Git with eZ Publish projects

In my spare time I've been hanging out with a bunch of Ruby/Rails people. They are a fun bunch however they don't seem to like it when you point out that MVC existed well before Rails. One thing that have put me onto is Git.

Git is a distributed revision control / software configuration management project. You may have heard of it, Linus Torvalds (that clever guy behind Linux) wrote it to manage kernel development. There is plenty to read about it on Wikipedia

So why Git?

This week I've been working on an eZ Publish 4.0 project that needed the ezApprove2 workflow extension. The version in the contribs says it has 3.7 support...the eZ projects site says it work with 3.x..no 4.0 except in the subversion repository on the projects site!

So I check it out svn co http://svn.projects.ez.no/ezapprove2/ezapprove2/ezp4/trunk/extension/ezapprove2 to investigate if it meets the requirements.

As part of this process I notice some bugs and being a good open source user I fix them, however I can't commit them back to the repository as I'm not a member of the project (I've applied). I've got other things to do and probably won't remember to commit the changes when and if my membership is approved. I've posted most the the patches to the forums in case anyone is looking at using it.

Git allows for distributed revision control, effectively I can have a local repository and make local commits. git-svn also allows for the sync a local git repository with a subversion one.

Here is what I've done so far...I'm new to this so any git experts out there I'm happy to hear any pointers from you!

Install git

I use kubuntu so installation was pretty painless
sudo apt-get install git-core git-svn git-gui

Create a directory for the repository

$ cd /var/www/ezpublish-4.0.0/extension/
$ mkdir ezapprove2
$ cd ezapprove2

Find the revision I want to check out from the subversion repository

$ svn log http://svn.projects.ez.no/ezapprove2/ezapprove2/ezp4/trunk/extension/ezapprove2 | head
------------------------------------------------------------------------
r2500 | tw | 2008-01-15 02:15:14 +1000 (Tue, 15 Jan 2008) | 1 line

- Fixed missing static in ezinfo.php
------------------------------------------------------------------------
r2487 | tw | 2008-01-12 01:02:47 +1000 (Sat, 12 Jan 2008) | 1 line

- Added eZ Approve 2 for eZ Publish 4 (PHP5 port)
------------------------------------------------------------------------

Initialise the git repository

$ git svn init http://svn.projects.ez.no/ezapprove2/ezapprove2/ezp4/trunk/extension/ezapprove2
Initialized empty Git repository in .git/


Check out the revision I want from subversion

$ git-svn fetch -r2500
A sql/mysql/schema.sql
A ezinfo.php
A settings/module.ini.append.php
A settings/collaboration.ini.append.php
A settings/design.ini.append.php
A settings/extendedattributefilter.ini.append.php
A settings/workflow.ini.append.php
A settings/ezapprove2.ini.append.php
A settings/site.ini.append.php
A translations/ger-DE/translation.ts
A translations/nor-NO/translation.ts
A INSTALL.txt
A doc/upgrade/UPGRADE_0.1-0.2
A doc/upgrade/UPGRADE_0.2-0.3
A doc/upgrade/UPGRADE_0.3-0.4
A doc/upgrade/UPGRADE_0.4-0.5
A doc/upgrade/UPGRADE_0.5-0.6
A doc/upgrade/UPGRADE_0.6-0.7
A doc/upgrade/UPGRADE_0.7-0.8
A doc/changelogs/CHANGELOG_0.1-0.2
A doc/changelogs/CHANGELOG_0.2-0.3
A doc/changelogs/CHANGELOG_0.3-0.4
A doc/changelogs/CHANGELOG_0.4-0.5
A doc/changelogs/CHANGELOG_0.5-0.6
A doc/changelogs/CHANGELOG_0.6-0.7
A doc/changelogs/CHANGELOG_0.7-0.8
A eventtypes/event/ezapprove2/ezapprove2type.php
A collaboration/ezapprove2/ezapprove2collaborationhandler.php
A modules/ezapprove2/ezapprovefunctioncollection.php
A modules/ezapprove2/function_definition.php
A modules/ezapprove2/select_approver.php
A modules/ezapprove2/view_approve_list.php
A modules/ezapprove2/module.php
A modules/ezapprove2/add_approver.php
A design/standard/templates/notification/handler/ezcollaboration/view/ezapprove2/author.tpl
A design/standard/templates/notification/handler/ezcollaboration/view/ezapprove2/approve.tpl
A design/standard/templates/collaboration/handlers/view/full/ezapprove2.tpl
A design/standard/templates/collaboration/handlers/view/line/ezapprove2.tpl
A design/standard/templates/collaboration/message/view/element/ezapprove2_comment.tpl
A design/standard/templates/workflow/eventtype/edit/event_ezapprove2.tpl
A design/standard/templates/workflow/eventtype/view/event_ezapprove2.tpl
A design/standard/templates/workflow/eventtype/ezapprove2/view_approve_list.tpl
A design/standard/templates/workflow/eventtype/ezapprove2/add_approver.tpl
A design/standard/templates/workflow/eventtype/ezapprove2/select_approver.tpl
A classes/ezapprove2event.php
A classes/ezapproveextendedfilter.php
A classes/ezxapprovestatususerlink.php
A classes/ezxapprovestatus.php
r2500 = 2528a77b6478e87833cc59e376965dbc03b5d775 (git-svn)

Checked out HEAD:
http://svn.projects.ez.no/ezapprove2/ezapprove2/ezp4/trunk/extension/ezapprove2 r2500

Now I want to create a local branch so I can distinguish which are my changes

$ git status
# On branch master
nothing to commit (working directory clean)
$ git checkout -b code_review
Switched to a new branch "code_review"
$ git status
# On branch code_review
nothing to commit (working directory clean)


Now I can fix the bugs add new files and commit locally

There was an issue in the default node plain view template which is used by the collaboration preview. To fix this I added a file ( design/standard/templates/node/view/plain.tpl ) to the extension that fixes the issue.

$ mkdir -p design/standard/templates/node/view
$ vi design/standard/templates/node/view/plain.tpl
$ git status
# On branch code_review
# Untracked files:
# (use "git add >file<..." to include in what will be committed)
#
# design/standard/templates/node/
nothing added to commit but untracked files present (use "git add" to track)

Like with subversion I had to add the new directory before I can make the commit to the git repository.

$ git add design/standard/templates/node
$ git status
# On branch code_review
# Changes to be committed:
# (use "git reset HEAD >file<..." to unstage)
#
# new file: design/standard/templates/node/view/plain.tpl
#
$ git commit -m'fixed "Placed in:" for items previously unpublished' design/standard/templates/node/view/plain.tpl
Created commit 0cc675c: fixed "Placed in:" for items previously unpublished
1 files changed, 45 insertions(+), 0 deletions(-)
create mode 100644 design/standard/templates/node/view/plain.tpl

So now we have made the change and have a local commit. I can go ahead and fix the bugs that I find, making local commits as I go. I can see the changes by checking the git log.


$ git log
commit e910175452f6d9b43331798926628e7bf0528d5c
Author: Bruce Morrison
Date: Fri Feb 29 16:42:57 2008 +1000

fixed "Placed in:" for items previously unpublished

commit d4f3036b90377b8c69d84dacaafff8e50680d61c
Author: Bruce Morrison
Date: Fri Feb 29 14:20:28 2008 +1000

Typo in const

commit cb0f79dc7da4ac86288c1c9e1fa06202b39c5ff1
Author: Bruce Morrison
Date: Fri Feb 29 14:19:44 2008 +1000

Fix for placement of a previously unpublished object that is edited

commit 842c439ce9ebe5f987c7807bf1d394306eafe681
Author: Bruce Morrison
Date: Fri Feb 29 14:17:31 2008 +1000

Fixed method definitions to match eZCollaborationItemHandler to stop strict messages

commit 4d7e93900c54feb7d91fb3d42cf94112aa3b7cbc
Author: Bruce Morrison
Date: Fri Feb 29 14:09:24 2008 +1000

Corrected typo in const

commit 2528a77b6478e87833cc59e376965dbc03b5d775
Author: tw
Date: Mon Jan 14 16:15:14 2008 +0000

- Fixed missing static in ezinfo.php

git-svn-id: http://svn.projects.ez.no/ezapprove2/ezapprove2/ezp4/trunk/extension/ezapprove2@2500 b9bbbbba-8235-4206-939b-838bdeb4db37


If I'm granted write access to the subversion repository I can simply run

$ git-svn dcommit

and each local commit is transformed into an svn one.

I can update my working copy from the svn repository by running

$ git-svn rebase


Not only can I make local commits I can do so offline, syncing the changes when I have access to the repository.

The following sites greatly assisted this process:

Comments

  1. Have you tried Bazaar or Mercurial?
    They both seem to have better support across all os's, and it's a lot more gui tools for them.

    ReplyDelete
  2. Hi André R.

    No, I haven't tried Bazaar or Mercurial.

    Having a Sys Admin background I'm more of a cmd line person so the lack of gui it's a real issue for me.

    There are two issues that git solves for me, the offline commits, and subversion bridging. Both Bazaar or Mercurial support offline commits but I've been unable to quickly find information about subversion bridging.

    I have found a couple of good posts discussing the various options:
    http://www.dribin.org/dave/blog/archives/2007/12/28/dvcs/
    http://www.dribin.org/dave/blog/archives/2007/12/30/why_mercurial/

    The latter talks about Mercurial having a svn bridge but that it's not as polished as git-svn.

    Cheers
    Bruce

    ReplyDelete
  3. Bruce,

    I and a lot of folks I know, make daily use of eZ Approve2. Thank you for going the extra mile to contribute your improvements and the great introduction to Git.

    //kracker

    ReplyDelete
  4. Hi bruce,

    You should have a look to svk.

    It's probably the closer solution to svn and enable decentralized and offline commit.

    http://svk.bestpractical.com/

    ReplyDelete

Post a Comment

Popular posts from this blog

eZ Publish Admin Prototype extension

eZ Publish 5 Virtual Machine

eZ Publish Admin redesign - Dashboard = OpenSocial?