2011-07-06 2 views
5

패턴을 사용하여 커밋 확인을 확인하는 수은 용 간단한 후크가 필요합니다. 여기 내 후크입니다 :Tortoise Hg 로그 창에서 후크 출력을 표시하는 방법은 무엇입니까?

#!/usr/bin/env python 
# 
# save as .hg/check_whitespace.py and make executable 

import re 

def check_comment(comment): 
    # 
    print 'Checking comment...' 
    pattern = '^((Issue \d+:)|(No Issue:)).+' 
    if re.match(pattern, comment, flags=re.IGNORECASE): 
     return 1 
    else: 
     print >> sys.stderr, 'Comment does not match pattern. You must start it with "Issue 12323:" or "No Issue:"' 
     return 0 

if __name__ == '__main__': 
    import os, sys 
    comment=os.popen('hg tip --template "{desc}"').read() 
    if not check_comment(comment): 
     sys.exit(1) 
sys.exit(0) 

그것은 작동합니다. 콘솔에서 커밋 할 때 심지어 오류 메시지 'Comment does not match pattern. You must start it with "Issue 12323:" or "No Issue:"'을 표시합니다. 하지만 Tortoise Hg Workbench에서 커밋을 시도하면 시스템 메시지 (abort: pretxncommit.check_comment hook exited with status 1) 만 표시됩니다.

무엇이 잘못되었는지 사용자에게 알릴 필요가 있습니다. Tortoise Hg에게 훅의 출력을 보여줄 수있는 방법이 있습니까?

+0

그냥 추측하지만 sys.err 대신 sys.out에 글을 써 보았습니까? – bbaja42

+0

예. 도움이되지 않았다. –

답변

5

외부 후크가 아닌 인 가공 후크 으로 처리하여 작동 시켰습니다. 그러나 In-process hooks은 완전히 다르게 정의됩니다.

먼저 파이썬 파일에는 훅 정의에서 이름이 호출 할 단일 함수 만 있으면됩니다. 후크 기능은 ui, repohooktype 개체에 전달됩니다. 또한 후크 유형에 따라 추가 객체가 전달됩니다. pretrxncommit의 경우 node, parent1parent2이지만 노드에만 관심이 있으므로 나머지는 kwargs에 수집됩니다. ui 개체는 상태 및 오류 메시지를 제공하는 데 사용됩니다. check_comment.py

내용량 다음 hgrc에서

#!/usr/bin/env python 

import re 

def check_comment(ui, repo, hooktype, node=None, **kwargs): 
    ui.status('Checking comment...\n') 
    comment = repo[node].description() 
    pattern = '^((Issue \d+:)|(No Issue:)).+' 
    if not re.match(pattern, comment, flags=re.IGNORECASE): 
     ui.warn('Comment does not match pattern. You must start it with "Issue 12323:" or "No Issue:"\n') 
     return True 

, 상기 후크는이 같은 python:/path/to/file.py:function_name 정의 될 것이다 : pretxncommit

[hooks] 
pretxncommit.check_comment = python:/path/to/check_comment.py:check_comment 

.suffix_name는 전역 적 정의 후크 재정의 피하기 위해, 특히 저장소가 글로벌 저장소가 아닌 hgrc에 정의되어있는 경우에 특히 그렇습니다. 접미사는 동일한 후크에 대해 여러 응답을 허용하는 방법입니다.

0

등을 통해 제공되는 저장소에서 실행되는 경우. hgserve :
나는

서버에서 로그 TortoiseHg 워크 벤치 로그 팬에

  • 또는 cmd를 라인에서 동일한 출력

    • 을 보여주기 위해 pretxnchangegroup 스크립트에서이 작은 파이썬 함수를 사용

      def log(ui, string): 
          print(string) # will show up as "remote:" on the client 
          ui.status("{0}\n".format(string)) # will show up in the same hg process: hgserve ; append newline 
          return 
      
  • 관련 문제