Svn in Linux can only be submitted after a comment is forced

Source: Internet
Author: User
Tags comments commit stdin svn

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.