Note: You are currently viewing documentation for Moodle 3.3. Up-to-date documentation for the latest stable version of Moodle is probably available here: Git tips.

Development:Git tips

From MoodleDocs
Revision as of 22:18, 2 June 2009 by Iñaki Arenaza (talk | contribs) (Another interesting thread)

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.



Many developers find git a useful tool to help them with moodle development, here some tips and workflows can be shared to help others.

Thorough Resolved Bug QA review with git

The power of having fast access to all of moodle commit history means we can search and checkout any point in moodle source code history which allows us to powerfully QA a bug.

Please note this workflow might not be ideal for all scenarios (for example if lots of work has been done in the same area since).

Example Workflow to QA MDL-16600:

First checkout a new branch for us to work on testing the bug in MOODLE_19_STABLE. We can delete this branch later, its less dangerous than playing any of our 'live' branches.

$ git checkout -b QA-MDL-16600 origin/MOODLE_19_STABLE
Branch QA-MDL-16600 set up to track remote branch refs/remotes/origin/MOODLE_19_STABLE.
Switched to a new branch "QA-MDL-16600"

Now search for any commits related to this bug fix:

$  git log --grep='MDL-16600'
commit 1c2c8b09469ac27a3829e7267f399356a05b9810
Author: tjhunt <tjhunt>
Date:   Fri Sep 26 05:49:06 2008 +0000

    MDL-16600 forcedownload broken for file resources.

In order to test that these commits fixed the bug, we will revert this commit, and then try to reproduce the reported bug:

$ git revert -n 1c2c8b09469ac27a3829e7267f399356a05b9810 

Once we've reproduced the problem, we will reset our repository back to HEAD:

git reset --hard HEAD

Now if the bug is fixed, it can be closed and we can delete our branch:

git branch -D QA-MDL-16600

Backporting stuff from cvshead to stable git branches

I (Penny) have to do this all the time and it sucks. So I made a script to make it suck less.

http://cvs.moodle.org/contrib/tools/devtools/bugstogitformatpatch?view=markup

This little perl script takes a list of bug numbers, and generates patches that you can apply with git-am

I backported Tim's roles UI work and this is how I did it.

# make a new branch to work on
$ git checkout -b mdl19-rolesbackport origin/MOODLE_19_STABLE

Now create some file that contains a list of bug numbers... In the case that there's only one, you can do:

$ echo MDL-xxxxx | bugstogitformatpatch --otherargs

Else you can do either of:

$ cat myplan | bugstogitformatpatch --otherargs
$ bugstogitformatpatch --grepfile myplan

This file could be a whole file with documentation and everything, but the script does expect the bug numbers to be one per-line (but accepts other junk on the same line) and start with MDL-xxxx

The script has some other options, like where to put the patches it generates, and what the revlog spec should look like (by default it will just do origin/cvshead, but you can restrict it to a different branch or even abcdefg..12345678 if you want, anything git-log can understand - see man git-rev-parse).

See --help for more information.

Now the script will run and actually much faster than I expected, for Moodle's entire history. It will spit out git-format-patch formatted patches, which you can then happily apply with git-am.

TIP: For a large feature that goes into HEAD, it may happen that someone commits bugfixes to HEAD after you've backported it, which you'll then subsequently want to apply. To get around this, I did...

$ git tag rolesbackportedtohead origin/cvshead

After I was done... then the next time I wanted to run the script, I just used --revlist rolesbackportedtohere..origin/cvshead to only look at patches after the last time.

More tips please

(Please add your own tips here!)

See Also