Tracking Moodle CVS with git

Tracking Moodle CVS with git

by Dan Poltawski -
Number of replies: 9
[slightly OT] Now that 1.9 is out i'm starting to prepare for local release and i've finally got round to learning more about git.

So far i'm very impressed! I got the impression the git tools used to be rough round the edges.. not so any more, they are full of nice touches and its a joy to use. The documentation is great too, if you are thinking of trying git I highly recomend the users manual.

I have a few workflow-related questions i'd love to hear opinions of any other git users, especially since some of the tools a seem to have changed (e.g. cogito in moodledocs).

For local customisations i'm creating my own branch based on MOODLE_19_STABLe e.g.


git clone moodle
git branch danslocalversion MOODLE_19_STABLE


Then hack away committing along the way, e.g.

vim lib/moodlelib.php
git add lib/moodlelib.php
git commit -m 'hacked moodlelib'


Now obviously the real advantage for custom modifications is updating from upstream and reapplying my customisaitons.

For which i'm doing:

git rebase MOODLE_19_STABLE


And then if I want to test my local customisations on HEAD for 2.0 I do:

git rebase --onto cvshead MOODLE_19_STABLE


Does that workflow seem sensible?

How do you tend to 'store' your branches? Obviously the whole point of git is that its decentralised, but I still want to push my branches to a central repository so my team can work together without a steward and can carry out backups to prevent loosing all my work when my desktop blows up? How do you decide when to push a branch to a centrally?

What is the easiest way to find out what heads/tags a commit applies to?

Final question, I have git-cvsimported the cvs repository and I notice that the commit ids are different in my repo to Catalyst's repository which I don't understand.. should the generated SHA not be the same??
Average of ratings: -
In reply to Dan Poltawski

Re: Tracking Moodle CVS with git

by Myles Carrick -
Hey Dan,

I'm sure ML (or another of the Catalyst crew) will chime in with some further guidance re. why the hashes aren't matching. You're right about the cogito tools - I've not come across anyone really using them anymore.

Re. your workflow... I work with Martín's git repo at Catalyst, but...

I set up a branch to specifically track an existing branch, i.e. (using your names)
git branch --track danslocalbranch origin/MOODLE_19_STABLE

I can then check it out
git checkout danslocalbranch

Perform mods... then add new files en masse with
git add .

After modifying existing files, it's possible to add and commit in one step
vim lib/moodlelib.php
git commit -a -m 'hacked moodlelib'

Now if upstream has changed it's really easy
git pull
(it automatically will fetch the remote branch and merge).

Remember that with git, branches are cheap, so you can create branches, try a merge or rebase...and throw them out again if you don't want them.
I'm keen to start doing more with git - so am looking forward to other contributions on this topic.

If anyone wants to manage the cvs-to-git process each day for Contrib, I'd be their greatest fan!

MC

In reply to Myles Carrick

Re: Tracking Moodle CVS with git

by Martín Langhoff -
> anyone wants to manage the cvs-to-git process each day for Contrib, I'd be their greatest fan!

I thought about it, but contrib has a lot of projects in there. It'd be a "forest" of git imports. Doable, but needs a bit of smart scripting to automagically break things down into separate imports.
In reply to Martín Langhoff

Re: Tracking Moodle CVS with git

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Right now, I am setting up contrib-to-git for just one module I need to work on. So far it works fine. Once I have more experiences on using git, maybe I'll be able to set up complete git mirror of the contrib.
In reply to Dan Poltawski

Re: Tracking Moodle CVS with git

by Martín Langhoff -

Dan - your workflow is good, you can choose whether to rebase or merge, depending on the situation.

We merge "along" each _STABLE branch, and then, when there is a new release, do a manual rebase of the local patches on to the new _STABLE branch. When I say manual rebase, I mean extract all the local patches with

git-format-patch -o .patches mdl15-custom..origin/MOODLE_15_STABLE 

and then we open a new branch (mdl16-custom) and cherry pick those patches that we really want to rebase on top of the next release , using git-am.

I find it enormously useful to ensure the first line of the commit message is a good one, and prefix it with the area it affects ("mod/foo: revamped frob() to take $limit param"). So things look clear when I open up gitk, and the decisionmaking at rebase time (which is often half a year or a year after the code was written) becomes much easier.

I wrote git-cvsexportcommit to merge into Moodle's CVS commits from git with guarantees that they were being merged exactly the way I meant them. And you can use the -m parameter to add a bug number to link to the tracker smile As long as the patch is exactly the same, git is very good in recognising that a merge from 'upstream' brings the same commits you already have.

As to why the import is different... long story, but cvs storage is ambiguous, so every time you do an import, you end up with a subtly different history. That's why I recommend that people track one common import (and I openly offer Catalyst's) so everyone is using the same hashes, and can merge with eachother easily. Importing from cvs is not "stable" (in the sense that it doesn't give consistent, reproduceable results) -- the cvs format is so horrible.

Having said that, if you are going to run your own import, the recommended strategy is to do an initial import with parsecvs and then daily incrementals with git-cvsimport.

And lastly... play with gitk's commandline options and the various search boxes in the gui. It's amazing. I am completely addicted to it -- everytime I am about to work on a given area of moodle, I quickly check what's been happening here. Or whether a given branch has done anything interesting with a module

gitk origin/MOODLE_15_STABLE origin/MOODLE_16_STABLE mod/journal

Or as numbers

git diff --stat origin/MOODLE_15_STABLE..origin/MOODLE_16_STABLE

Oh, and git grep. You can say, from any git clone, "did we have this function in 1.5?"

git grep 'function frob'  origin/MOODLE_15_STABLE

Right - I'm frothing at the mouth. Time to stop wink

Average of ratings: Useful (1)
In reply to Martín Langhoff

Re: Tracking Moodle CVS with git

by Dan Poltawski -
Thanks for the tips! cool

One thing which has struck me after reading your (and Myles') comments is the use of git branch --track. In most cases I do not think I wish to use this as I would prefer to merge manually periodically (and not be afraid to pull regularly).

I was going to setup my own cvs import since I have a cvs mirror just over there >>. But given the inconsistencies i'll just pull from Catalyst wink
In reply to Dan Poltawski

Re: Tracking Moodle CVS with git

by Martín Langhoff -

How do you tend to 'store' your branches?

We just run a shared team repository on a server - the 'moodle-r2.git' repo in git.catalyst.net.nz (though there's a private set of repos for projects that need them).

This guide is based on the practices we use @ Catalyst http://www.kernel.org/pub/software/scm/git/docs/cvs-migration.html -- the elearning team here was the first user of git using these strategies. Back when it was all a ball of C and Bash. I think everyone in the team here knows git internals end-to-end wink

Edit: I am also addicted to git stash and the bash autocompletion tricks (included by default on ubuntu 7.10). Try them!

In reply to Martín Langhoff

Re: Tracking Moodle CVS with git

by Dan Poltawski -
Hmm, i'm getting confused when pulling from different sources..

I can clone the Catalyst repo and pull my moodle updates from there:

 
git clone http://git.catalyst.net.nz/git/moodle-r2.git

git branch --no-track danslocalbranch origin/MOODLE_19_STABLE


But then once i've done my customisations I want to push it to my teams repo:
 
git push ssh://our.team.server/git danslocalbranch


But now one of my collegues has made my a change and I can't work out how to pull from our team server as well as pulling from upsteam (Catalyst repo)?
In reply to Dan Poltawski

Re: Tracking Moodle CVS with git

by Martín Langhoff -

Easy. When you did the initial clone, git created a "remote" comfiguration called "origin" so when you say "git pull" (or "git fetch" to do any merges by hand) git adds the default "remote", making it "git pull origin".

Now you need to register your repo, so say

git remote add ourrepo ssh://our.team.server/git

and now you can say

git fetch ourrepo # this brings in your colleague's changes
git merge ourrepo/ourcustombranch
git push ourrepo ourcustombranch

you can always look things up in the .git/config file. git remote just manipulates that file.

hth!

In reply to Martín Langhoff

Re: Tracking Moodle CVS with git

by Jonas Lagneryd -
Hi,
I do not know if this is the right place to ask this? Please direct me if not.

We are running Moodle 1.9 and have been adding some local code. Now as the project is developing we would like to use tracking. I am the manager of the project - WWW.CARD.COOP (built on a platform that integrates Moodle, Magento and Adobe Connect Pro) - and am thus buying services from others. It is hosted on a VPS on Siteground so far. So I wonder if you would have any good advice to give when taking the first steps to start tracking Moodle and also Magento with git? What to think of? Where is good competence regarding setting it all up?

Kind regards,
Jonas