Git bz configuration

From Koha Wiki

Jump to: navigation, search
Home > Development
Home > Development > Git

Make sure you have python installed (I used 2.7.1).

Optionally, if you plan on sending bugs to bugzilla from git, you'll need to tell it your username and password or if you have Chrome or Firefox installed on your dev machine, and have logged into bugzilla at least once from that machine, git-bz can use that.

Contents

Get git-bz

In your home directory, run:

git clone git://gitorious.org/~slef/git-bz/slefs-git-bz.git git-bz

(slef's self-authenticating patched version of rangi's patched version git://gitorious.org/git-bz/git-bz.git, which fixes a bug in the official version. FIXME: when his patch is incorporated into upstream git-bz, update this link)

Configure git-bz

symlink git-bz somewhere that's in your $PATH. For example,

sudo ln -s ~/git-bz/git-bz /usr/local/bin/git-bz

will often work. You might need to add /usr/local/bin/ to your path. To do that edit ~/.bash_profile with your favorite editor and add :/usr/local/bin to the path.

PATH=$PATH:/usr/sbin:/usr/bin:/usr/local/bin
export PATH

Log out and back in and it should work.

Then change to your koha git checkout

cd ~/kohaclone

run:

git config bz.default-tracker bugs.koha-community.org
git config --global bz-tracker.bugs.koha-community.org.path /bugzilla3
git config bz.default-product Koha
git config --global bz-tracker.bugs.koha-community.org.bz-user U
git config --global bz-tracker.bugs.koha-community.org.bz-password PW

replacing U with your bugzilla username and PW with your bugzilla password. (These are --global to avoid keeping your username and password in the clear in the repository, but keeping them in your global .gitconfig isn't great either.) You need to set your user name and password regardless of whether or not you intend to upload patches using git-bz (FIXME: is this a bug?).

Now you are ready to do some work with git-bz

Using git-bz

Check out a branch, where xxxx is your bug number:

git checkout -b bug_xxxx origin/master

Apply a patch from bugzilla

git bz apply xxxx

<Test it>

Send a patch to bugzilla Simply attaches the last commit to the listed bug -- no need to git format-patch

git bz attach xxxx HEAD

With -e, allows editing of the attachments on the listed bug -- obsoleting old attachments, etc. (This operation can time out rather quickly, if you get a "traceback" from Python try once more and be quicker.)

git bz attach -e xxxx HEAD
  • HEAD attaches the last commit to the bug.

If you're signing off on a patch and want to attach the signed off patch to the bug you can use:

git commit --amend -s 

and then:

git bz attach -e xxxx HEAD

It is still considered good practice to send the signed off patch to the patches mailing list. This can be done with a single command:

git send-email  --to 'koha-patches@lists.koha-community.org'  origin/master

This assumes that you have called the remote for the officia Koha repo "origin" and that you have an up-to-date master branch from there.

This is also a good moment to open your bug in bugzilla using http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=xxxx url and change "Patch status" to "Signed Off"

Bugs with more than one patch

Getting the patches

If a bug has more than one patch, you can still get all of them the same way as described above:

git bz apply xxxx

This will walk you through all the patches and let you choose which ones you want to apply.

Signing off

If you are signing off more than one patch (after testing them, of course) you can do this:

git rebase 1stcommitid^ --interactive

This will give you an editor that displays the commits for the patches you are working on. Some lines will start with "pick" and you should replace that with "edit" and then save. Then do:

git commit --amend -s

and add [SIGNED-OFF] to the first line of the commit message. Then do:

git rebase --continue

to move on to the next patch/commit, and do

git commit --amend -s

Repeat this until you have been through all of them.

Attaching patches

Now it's time for attaching the patches to the bug. If you have two patches you can do this with:

git bz attach -e xxxx <commitid of first commit, e.g. b50ea9bd>^..

Uncomment the # before each patch you would like to obsolete before saving. You will have to be pretty fast here, if you dawdle git bz will bring back a nasty error, but you can simply rerun the command (making your edits faster this time) to avoid it.

If you have more patches/commits you can use e.g. HEAD~2, HEAD~commitid etc to specify the range of commits you want to include. See gitrevisions(7) for details. You will get to edit the commit message, obsoleting etc for each individual patch. See the general description above for how this works.

If you know you've 3 patches to attach, you can also use HEAD~2..HEAD to attach the 3 patches at once

Documentation

Full documentation can be found at http://git.fishsoup.net/man/git-bz.html

Troubleshooting

No patch applied

So, you have a bug, and type something like:

dpavlin@koha-dev:/srv/kohaclone$ git bz apply 7161
Bug 7161 - Open Library - Larger image, Read, borrow and checked-out status

and nothing happens after it? It's quite possible that bug doesn't have patch attached.

Or, if it does have file attached (which you can see under attachments) it might have application/octet-stream type instead of patch. Go into details > Edit details and check patch checkbox.

Now git-bz will work as expected:

dpavlin@koha-dev:/srv/kohaclone$ git bz apply 7161
Bug 7161 - Open Library - Larger image, Read, borrow and checked-out status

Open Library - Larger image, Read, borrow and checked-out status
Apply? [yn] y

Applying: Bug-7161 Open Library - Larger image, Read, borrow and checked-out status

Reset branch to clean master

Abort application of patches from e-mail

git am --abort

Remove all local changes and revert your checkout to clean upstream master

git reset --hard origin/master


git bz attach -e timeout

If you are not fast enough git bz attach -e might time-out on you with a long python stack trace similar to this:

dpavlin@koha-dev:/srv/koha_ffzg$ git bz attach -e 7161 HEAD
Traceback (most recent call last):
File "/usr/local/bin/git-bz", line 2142, in <module>
 do_attach(*args)
File "/usr/local/bin/git-bz", line 1622, in do_attach
 attach_commits(bug, commits, edit_comments=global_options.edit)
File "/usr/local/bin/git-bz", line 1572, in attach_commits
 bug.create_patch(description, body, filename, patch, obsoletes=obsoletes, status=status)
File "/usr/local/bin/git-bz", line 1188, in create_patch
 response = self.server.send_post("/attachment.cgi", fields, files)
File "/usr/local/bin/git-bz", line 948, in send_post
 return self.send_request("POST", url, data=body, headers={ 'Content-Type': content_type })
File "/usr/local/bin/git-bz", line 884, in send_request
 response = connection.getresponse()
File "/usr/lib/python2.6/httplib.py", line 990, in getresponse
 response.begin()
File "/usr/lib/python2.6/httplib.py", line 391, in begin
 version, status, reason = self._read_status()
File "/usr/lib/python2.6/httplib.py", line 355, in _read_status
 raise BadStatusLine(line)
httplib.BadStatusLine

To fix it, just re-try command and it should work.

testing with -3 flag set

The git bz from the previous repo is missing the -3 flag. It means that it run git am and not git am -3

if you want to add the -3 flag, just add the following patch to your git-bz setup:

From ae058a195b719724952c6bc6201729fe98501029 Mon Sep 17 00:00:00 2001
From: Paul Poulain <paul.poulain@biblibre.com>
Date: Fri, 4 Nov 2011 10:59:47 +0100
Subject: [PATCH] Add -3 parameter to git am
 
With this patch, the git am now automatically has a -3 parameter
That makes no difference for patches that applies directly, but is useful when it's not the case
---
 git-bz |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
 
diff --git a/git-bz b/git-bz
index 0d1fc91..9ebdf0a 100755
--- a/git-bz
+++ b/git-bz
@@ -1494,7 +1494,8 @@ def do_apply(bug_reference):
         f.close()
 
         try:
-            process = git.am(filename, _interactive=True)
+            #process = git.am(filename, _interactive=True)
+            process = git.am(filename, **{'_interactive': True, '3': True})
         except CalledProcessError:
             print "Patch left in %s" % filename
             break
-- 
1.7.5.4