2011-10-21 3 views
3

this Mercurial extension을 수정하여 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 확장자와 관련이 있으며 여기서는 도움이되지 않는 것처럼 보입니다.

커밋 메시지를 어떻게 설정할 수 있습니까?

답변

6

나는 후크를 사용하는 방법을 찾지 못했지만, extensions.wrapcommand을 사용하고 옵션을 수정할 수있었습니다.

결과 확장 소스를 여기에 포함 시켰습니다.

커밋 메시지에 사례가없는 것을 감지하면 내 버전은 사용자에게 메시지를 입력하거나 경고를 무시하거나 커밋을 중단하라는 메시지를 표시합니다.

사용자가 사례 번호를 지정하여 프롬프트에 응답하면 기존 커밋 메시지에 추가됩니다.

사용자가 'x'로 응답하면 커밋이 중단되고 변경 사항은 미결 상태로 유지됩니다.

사용자가 Enter를 누르는 것만으로 응답을 받으면 커밋은 원래의 caseless 커밋 메시지로 진행됩니다.

또한 nofb 옵션을 추가했습니다. 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라는 이름의 파일에 소스를 복사,이 확장을 사용하려면 : 여기

는 확장 기능입니다. 그런 다음 (환경 설정이 무엇이든 또는 hgrc) 당신의 Mercurial.ini 파일에서 [extensions] 섹션에 다음 줄을 추가 :

fogbugzreminder=[path to the fogbugzreminder.py file] 
0

변경 집합을 수정하지 않고 커밋 메시지를 수정할 수 없습니다.

bugid가 누락되면 커밋을 거부하는 사전 커밋을 조사해 보시기 바랍니다.

+0

은 내가 extensions.wrapcommand를 사용하여 필요한 무엇을 달성 할 수 있었다. 내 대답을 확인 :) –

관련 문제