Add a script in the hooks directory.
#! /Usr/bin/env python
#-*-Encoding: UTF-8 -*-
######################################## #################################
# File Name: pre-commit.py
# Author: LookBack
# Email: admin # dwhd.org
# Version:
# Created Time:, Monday, January 1, September 28, 2015
######################################## #################################
# SVN check hooks before submission
# Function:
#1. Enter the submission comments forcibly. The content is more than 10 bytes.
#2. The format of mandatory comment is: xxx
#3. Check the submitted files to filter files that cannot be submitted
######################################## #################################
Import sys
Import OS
Import re
Def main (argv ):
(Repos, txn) = argv
Badlist = (". * config \. php $ ",". */php/cache ",". * test "," config \. js $ "," ^. *\. db $ ")
Message = "". join (OS. popen ("/usr/bin/svnlook log '% s'-' % s'" % (repos, txn )). readlines ()). strip ()
If len (message) <10:
Sys. stderr. write ("Enter the modified content submitted this time, more than 10 bytes. \ n ");
Sys. exit (1)
If message. find (':') <1:
Sys. stderr. write ("Enter comments according to the specifications. Format: function name: modify description. \ n ");
Sys. exit (1)
Changelist = OS. popen ("/usr/bin/svnlook changed '% s'-' % s'" % (repos, txn). readlines ()
For line in changelist:
For pattern in badlist:
If re. search (pattern, line ):
Sys. stderr. write ("Please do not add % s to the version Library. \ n" % line [1:]. strip ());
Sys. exit (1)
Sys. exit (0)
If _ name _ = "_ main __":
Main (sys. argv [1:])
Find out the meaning of this script based on the content in the system's built-in pre-commit.teml:
The pre-commit hook is invoked before a Subversion txn is
# Committed. Subversion runs this hook by invoking a program
# (Script, executable, binary, etc.) named 'pre-commit '(for which
# This file is a template), with the following ordered arguments:
#
# [1] REPOS-PATH (the path to this repository)
# [2] TXN-NAME (the name of the txn about to be committed)
#
# [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.
#
# If STDIN contains the line "LOCK-TOKENS: \ n" (the "\ n" denotes
# Single newline), the lines following it are the lock tokens
# This commit. The end of the list is marked by a line containing
# Only a newline character.