4

I tried to use Trac with Git.

  1. I've configured Git plugin - it shows repository and changesets in "Browse Source" tab correctly.
  2. Turned on CommitTicketUpdater plugin, configured it: turned off authentication, set not to use any brackets, left keywords to default.
  3. Added some tickets.
  4. Done commits with message containing "close #5".

Trac sees ticket number (in changesets it is marked red and linked to ticket) but doesn't close ticket no 5. What might be wrong?

TIA

j08691
  • 204,283
  • 31
  • 260
  • 272
alekwisnia
  • 2,314
  • 3
  • 24
  • 39

5 Answers5

0

I had the same problem. The git CommitTicketUpdater plugin seems to expect square brackets around the term by default, like [closes #5] See also the trac.init for commit_ticket_update_envelope in this blog entry

peller
  • 4,435
  • 19
  • 21
0

If it helps, I filled my trac ini with the following:

[ticket] commit_ticket_update_commands.close = close

The official documentation claims that if you leave 'commit_ticket_update_commands.close =' empty, commiter update will use some default keywords in order to decide if it must close the ticket, but that doesn't work for me. The only thing that works is to explicitly set some keyword in that field, e.g (commit_ticket_update_commands.close = close)

jon
  • 1
0

If I follow the documentation, you should try with closes #5. If it still doesn't work, try to detect if the post-commit-hook is correctly configured.

The #XXX is a standard Trac/Wiki syntax to reference the XXX ticket, on the other hand, the [YYYY] will reference the YYYY commit, it will always work even if no post-commit-hook are defined.

Be sure to activate the post-commit-hook by following this link

Cédric Julien
  • 78,516
  • 15
  • 127
  • 132
  • It's unfortunate if it doesn't recognize `close #5`, Git commit message standards often use the imperative mood. – Dietrich Epp Jun 20 '11 at 12:14
  • Actually I tried most of the keywords listed in documentation, including "closes", "closed", also tried "refs", "see" etc. – alekwisnia Jun 20 '11 at 12:19
  • @alekwisnia : it seems to be that the post-commit-hook is not correctly configured or launched – Cédric Julien Jun 20 '11 at 12:20
  • @Cédric Julien: how to check if it is launched or if configuration is ok? – alekwisnia Jun 20 '11 at 12:22
  • @Cédric Julien: It seems, that links on this site are broken. I understand that I should add some lines in .git/hooks/post-commit. – alekwisnia Jun 20 '11 at 12:36
  • @alekwisnia : you're right, tyhe sublinks are down, this one is still valid : http://www.opencoder.co.uk/2010/03/trac-adding-git-mylyn-and-post-commit-hooks/ – Cédric Julien Jun 20 '11 at 12:51
  • 1
    If you want to verify that your post-commit hook is being launched correctly, add a line to the end of it that looks something like this: `date >> /home/username/hook.log` (make sure the file listed is writable by all users). That should add a timestamp to the specified logfile every time the hook is run. Do a test commit and see if a new timestamp gets logged. – bta Jun 20 '11 at 18:03
  • Ok, I've done that, no result (no date is written to log file). – alekwisnia Jun 21 '11 at 12:48
  • @alekwisna- That indicates that the script is not being called. Make sure that the scripts contain the appropriate `#!` line and are marked as executable. – bta Jun 22 '11 at 00:05
  • That documentation link is for subversion integration, not git – peller Sep 17 '13 at 01:47
0

I gave up Trac, switched to Redmine. It's now a little bit better - commits with given ticket's Id reference to tickets, but again - "fixes #1" doesn't close ticket number 1... Afaik Redmine doesn't need hooks..

alekwisnia
  • 2,314
  • 3
  • 24
  • 39
  • Yeah, kinda silly that Trac needs a git post-receive hook that runs "trac-admin TRAC_ENV changeset added". It could just check for new commits every so often. – Adam Monsen Apr 05 '12 at 17:45
0

how are you using the trac repository? Usually you have trac running on a server where you push to. The post-commit hook does not get run after a push.

You need a post-receive hook in this case. I made a a few changes to the post-receive hook in the git-plugin package, since it had some bugs. (f.ex. you can only make one change/second to a ticket in trac, so I had to add a sleep(1), since when you push all your commits would get processed in the same seccond. And you can also supply a number of worked hours)

This post-receive hook can be found on my github: https://github.com/JensTimmerman/TRAC-SVN-to-GIT-migration/blob/master/hooks/trac-post-receive-hook.py

you have to install this to /path/to/your/.git/hooks/post-receive and make sure it's executable (chmod +x /path/to/your/.git/hooks/post-receive in linux) and change the "TRAC_ENV = '/home/jens/tractest/'" to point to your trac environment.

edit:

If you're not hosting your git repository on the same server as you're running trac on you can do a pull to a temporary git repo and push again to the one trac uses with a cron job or so. This will then again trigger the post-receive hook on your real repository and update your trac.

I have this in place:

a64609@chaos:~/git$ ls
gitcron.log  realrepo  syncgit.sh  tmprepo

where tmprepo is just a location where i pull and push to and realrepo has my post-receive hook. with syncgit.sh:

cd /home/username/git/tmprepo;
git pull;
git push real;

and the remote 'real' of tmprepo set to

a64609@chaos:~/git/tmprepo$ git remote -v show
origin  https://JensTimmerman@github.com/hpcugent/easybuild.git
real    ../realrepo/

and everything get's synced by a crontab entry (put this in crontab -e)

*/3 * * * * /hhome/username/git/syncgit.sh  >> /home/username/git/gitcron.log 2>&1
Jens Timmerman
  • 9,316
  • 1
  • 42
  • 48
  • Here's an idea: create a bare clone mirror (with the necessary post-receive hook) on the server with Trac. You could push to the mirror hourly with a cron job. – Adam Monsen Apr 05 '12 at 17:46
  • Here's a better one, use your local repo, and push to the server, (with the post-receive hook) when you have reached some stable form. – Jens Timmerman Apr 10 '12 at 08:54
  • 1
    Yep, that works if you host the git repo on the same server as Trac. So I'd say "different", not "better". :) My suggestion is handy if your repo is hosted elsewhere (like Github). – Adam Monsen Apr 11 '12 at 23:13
  • 2
    AdamMonsen: You are right, and that's in fact how I have it set up myself. I didn't consider this to be the best way to solve things, but since you've mentioned it I added it to my answer. – Jens Timmerman Apr 12 '12 at 08:05