3

このMercurial拡張機能を変更して、コミットメッセージにFogBugzケース番号を追加するようにユーザーに促すようにしています。理想的には、ユーザーがプロンプトが表示された後に数字を入力するだけで、コミットメッセージに自動的に追加されるようにしたいと思います。

これが私がこれまでに得たものです:

def pretxncommit(ui, repo, **kwargs):
    tip = repo.changectx(repo.changelog.tip())
    if not RE_CASE.search(tip.description()) and len(tip.parents()) < 2:
        casenumResponse = ui.prompt('*** Please specify a case number, x to abort, or hit enter to ignore:', '')
        casenum = RE_CASENUM.search(casenumResponse)        
        if casenum:
            # this doesn't work!
            # tip.description(tip.description() + ' (Case ' + casenum.group(0) + ')')
            return True
        elif (casenumResponse == 'x'):
            ui.warn('*** User aborted\n')
            return True
        return True
    return False

私が見つけられなかったのは、コミットメッセージを編集する方法です。tip.description読み取り専用のようですが、ドキュメントや例で変更できるものは見当たりません。コミットメッセージの編集に関して私が見た唯一の参照は、パッチとMq拡張機能に関係しており、それがここで役立つとは思えません。

コミットメッセージを設定する方法について何かアイデアはありますか?

4

2 に答える 2

6

フックを使って方法を見つけることはできませんでしたがextensions.wrapcommand、オプションを使用して変更することでそれを行うことができました。

結果の拡張機能のソースをここに含めました。

コミットメッセージで大文字と小文字が区別されないことを検出すると、私のバージョンでは、大文字と小文字を入力するか、警告を無視するか、コミットを中止するようにユーザーに求めます。

ユーザーがケース番号を指定してプロンプトに応答すると、既存のコミットメッセージに追加されます。

ユーザーが「x」で応答すると、コミットは中止され、変更は未処理のままになります。

ユーザーがEnterキーを押すだけで応答した場合、コミットは元のケースレスコミットメッセージで続行されます。

また、ユーザーがケース番号なしで意図的にコミットした場合にプロンプ​​トをスキップするnofbオプションを追加しました。

拡張子は次のとおりです。

"""fogbugzreminder

Reminds the user to include a FogBugz case reference in their commit message if none is specified
"""

from mercurial import commands, extensions
import re

RE_CASE = re.compile(r'(case):?\s*\d+', re.IGNORECASE)
RE_CASENUM = re.compile(r'\d+', re.IGNORECASE)

def commit(originalcommit, ui, repo, **opts):

    haschange = False   
    for changetype in repo.status():
        if len(changetype) > 0:
            haschange = True

    if not haschange and ui.config('ui', 'commitsubrepos', default=True):
        ctx = repo['.']
        for subpath in sorted(ctx.substate):
            subrepo = ctx.sub(subpath)
            if subrepo.dirty(): haschange = True

    if haschange and not opts["nofb"] and not RE_CASE.search(opts["message"]):

        casenumResponse = ui.prompt('*** Please specify a case number, x to abort, or hit enter to ignore:', '')
        casenum = RE_CASENUM.search(casenumResponse)        

        if casenum:         
            opts["message"] += ' (Case ' + casenum.group(0) + ')'
            print '*** Continuing with updated commit message: ' + opts["message"]          
        elif (casenumResponse == 'x'):
            ui.warn('*** User aborted\n')
            return False    

    return originalcommit(ui, repo, **opts)

def uisetup(ui):    
    entry = extensions.wrapcommand(commands.table, "commit", commit)
    entry[1].append(('', 'nofb', None, ('suppress the fogbugzreminder warning if no case number is present in the commit message')))

この拡張機能を使用するには、ソースを。という名前のファイルにコピーしますfogbugzreminder.py。次に、Mercurial.iniファイル(またはhgrc、好みに応じて)で、[extensions]セクションに次の行を追加します。

fogbugzreminder=[path to the fogbugzreminder.py file]
于 2011-10-21T20:50:22.057 に答える
0

チェンジセットを変更せずにコミットメッセージを変更することはできません。

バギッドが省略された場合にコミットを拒否するprecommitフックを調べることをお勧めします。

于 2011-10-21T20:42:13.803 に答える