Git bz configuration

From Koha Wiki

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

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 http://git.koha-community.org/git-bz.git
cd ~/git-bz
git fetch origin
git checkout -b fishsoup origin/fishsoup

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. (If you're using the terminal in your virtual machine's desktop environment use ~/.profile instead of ~/.bash_profile.)

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

(An alternative to symlinking and adding /usr/local/bin/ to your path is simply to add /home/USERNAME/git-bz to your path using the model code snippet above.)

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 bz.default-product Koha
git config --global bz-tracker.bugs.koha-community.org.path /bugzilla3
git config --global bz-tracker.bugs.koha-community.org.bz-user U
git config --global bz-tracker.bugs.koha-community.org.bz-password PW
git config --global bz-tracker.bugs.koha-community.org.https true
git config --global core.whitespace trailing-space,space-before-tab
git config --global apply.whitespace fix

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

Bugs with one patch

Submitting a patch

This command 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.

Testing

Apply a patch from bugzilla

git bz apply xxxx

<Test it>

Signing off

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.

N.B. This is also a good moment to open your bug in bugzilla using the http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=xxxx url and change the bug's 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.


Easier way: put the following alias in your .git/config file:

[alias]
  so = "!f() { c=`expr $1 - 1`; git filter-branch -f --msg-filter \"cat && echo \\\"\nSigned-off-by: Your Name <you@example.org>\\\"\" HEAD~$c^..; }; f"

Until you have this alias defined, you can signed-off the number of patches you want with the following git command:

git so X

where X is the number of patches to sign-off

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, HEAD~commitid..HEAD 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^.. 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.

Known bugs

  1. --mail option can't send to other recipients - maybe should have a repository-specific configuration option?
  2. default statuses aren't the default bugzilla ones - maybe the koha-community ones should be added by a repository-specific configuration option and maybe activated automatically if it sees bugs.koha-community.org in use?
  3. not possible to apply patches without -3 - should have a config or option to suppress it.
  4. only handles ASCII characters in commit message

Known problems

$ /usr/local/bin/git-bz
-su: /usr/local/bin/git-bz : /usr/bin/python : mauvais interpr├ęteur: Aucun fichier ou dossier de ce type
$ ls /usr/bin/py*
/usr/bin/pydoc2.6  /usr/bin/pygettext2.6  /usr/bin/python2.6
# ln -s /usr/bin/python2.6 /usr/bin/python

But if the above happens, your python installation is probably broken and you just made the problem worse if there's a package manager...


Developer handbook

Personal tools