2011-12-19 8 views
2

cppファイルに対してのみSVNログメッセージを強制するにはどうすればよいですか?前もって感謝します。CPPファイルの強制ログメッセージ

これが私の現在のフックスクリプトです:

 #!/bin/sh 
     REPOS=”$1" 
     TXN=”$2" 
     # Make sure that the log message contains some text. 
     SVNLOOK=/usr/local/bin/svnlook 
     $SVNLOOK log -t “$TXN” “$REPOS” | grep “[A-z a-z]” && exit 0 
     echo “Please write a log message describing the purpose of your changes and then  
     try committing again.” 1>&2 
     exit 1 

答えて

1

this exampleに触発さ:

#!/bin/env python 
" Example Subversion pre-commit hook. " 

def command_output(cmd): 
    " Capture a command's standard output. " 
    import subprocess 
    return subprocess.Popen(
     cmd.split(), stdout=subprocess.PIPE).communicate()[0] 

def files_changed(look_cmd): 
    """ List the files added or updated by this transaction. 

"svnlook changed" gives output like: 
    U trunk/file1.cpp 
    A trunk/file2.cpp 
    """ 
    def filename(line): 
     return line[4:] 
    def added_or_updated(line): 
     return line and line[0] in ("A", "U") 
    return [ 
     filename(line) 
     for line in command_output(look_cmd % "changed").split("\n") 
     if added_or_updated(line)] 

def check_cpp_files(look_cmd): 
    " Check C++ files in this transaction. " 
    def is_cpp_file(fname): 
     import os 
     return os.path.splitext(fname)[1] in ".cpp .cxx .h".split() 
    cpp_files = [ 
     ff for ff in files_changed(look_cmd) 
     if is_cpp_file(ff)] 
    return len(cpp_files) 

def main(): 
    usage = """usage: %prog REPOS TXN 

Run pre-commit options on a repository transaction.""" 
    from optparse import OptionParser 
    parser = OptionParser(usage=usage) 
    parser.add_option("-r", "--revision", 
        help="Test mode. TXN actually refers to a revision.", 
        action="store_true", default=False) 
    errors = 0 
    try: 
     (opts, (repos, txn_or_rvn)) = parser.parse_args() 
     look_opt = ("--transaction", "--revision")[opts.revision] 
     look_cmd = "svnlook %s %s %s %s" % (
      "%s", repos, look_opt, txn_or_rvn) 
     if check_cpp_files_for_tabs(look_cmd) > 0: 
      # check the length of the commit message :D 
      # if not correct, print the error on sys.stderr.write("Please write a log message describing the purpose of your changes and then  
    try committing again.") 
    except: 
     parser.print_help() 
     errors += 1 
    return errors 

if __name__ == "__main__": 
    import sys 
    sys.exit(main())