2

We are trying to write a mercurial pre-commit hook which should work with both commandline and TortoiseHg.

The idea of the hook is to connect to JIRA and get the list of activities assigned to the developer, and show the activities in a list from which the developer can choose one. The JIRA ID and summary will then be put in the commit comment.

Now, we have the basic parts of most of the functionality figured out, but are missing a way to show a list. We've tried to show a basic QtWidget with input field and a button (using PyQt4), and using the command line the window appears, we can enter text and press the button to print the text (or send it out with ui.status).

In TortoiseHg (version 2.7.1) it doesn't work that well. The hook fires and the window opens but it appears as if control is not properly passed on. The input field on the new window doesn't get active, we can't see when we type text, but when clicking the button the contents are printed to ui.status. More worringly is that TortoiseHg stops updating the graphics, so when the window is closed there is a blank spot in the TortoiseHg window and THG doesn't respond to any input. We have to use the process explorer to shoot it down.

Any hints as to how to write a hook which opens a window which we can interact with under TortoiseHg?

Hook definition:

pre-commit = python:e:\repos\SCM-TOOLS\hg-hooks\user.py:hook

Python code:

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *


class AppForm(QMainWindow):
    def __init__(self, ui, parent=None):
        QMainWindow.__init__(self, parent)
        self.u = ui
        self.create_main_frame()      


    def create_main_frame(self):        
        page = QWidget()        

        self.button = QPushButton('Test', page)
        self.edit1 = QLineEdit()

        vbox1 = QVBoxLayout()
        vbox1.addWidget(self.edit1)
        vbox1.addWidget(self.button)
        page.setLayout(vbox1)
        self.setCentralWidget(page)

        self.connect(self.button, SIGNAL("clicked()"), self.clicked)

    def clicked(self):
        self.u.status (str(self.edit1.text()))

def hook(ui, repo, **kwargs):
    app = QApplication(sys.argv)
    form = AppForm(ui)
    form.show()
    app.exec_()
    sys.exit(1)

Edit: In addition to this working in TortoiseHg and from the commandline it should also work in Eclipse and IntelliJ, therefore the suggested TortoiseHg plugins are not a full solution.

1 Answers1

0

This task would normally be handled differently in Tortoise products as they already have a defined issue tracker plugin interface. This is defined here.

From the user point of view, they get a new button on the commit window which presents them with a list of issues to choose from. This then adds the appropriate text to the commit message.

There are two tortoise issue tracker plugins for Jira: 1, 2

I know that they say that they are TortoiseSvn plugins but they should work for TortoiseHg too - we use the TurtleMine one with no issues.

Steve Kaye
  • 6,262
  • 2
  • 23
  • 27
  • Thank you for the suggestion - I totally hadn't seen that would work. I managed to get JiraTorto to work from TortoiseHg itself and via thg from the command line. For some reason I can't get it to work via hg from the command line. I'll keep the question unanswered for a while in case somebody comes up with other suggestions. I would still like to hear a solution for the Python problem. – Peter Kristiansen Sep 18 '13 at 13:00
  • You won't get JiraTorto to work via `hg` from the command line because it is specifically a Tortoise plugin, not a Mercurial one. – Steve Kaye Sep 18 '13 at 13:17
  • Correct. Though there is a JiraToroBrowser.exe that I can see referenes to that for SVN you can use as your commit editor. When I try it then using hg commit it brings up a window where I can choose from my JIRA issues. The OK button does nothing though. I would like to vote up your answer because it is a good one (but my Reputation is too weak). After consulting the developers it proves they also need the functionality to work in Eclipse and IntelliJ which i cannot get to work for the plugins. I'll go back and edit the original question to reflect this. – Peter Kristiansen Sep 19 '13 at 08:41