简体   繁体   中英

Modification of pre-commit hook script

I have a script like this

#!/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 c   
ommitting again.” 1>&2
exit 1

If I have to track only cpp files from svnlook and throw error if condition fails,what else I should add with this script ? ) grep and find logic doesn't work**

So, explain exactly what you want:

  1. If all files are .cpp files, you want to check the commit comment. Otherwise, you want to ignore the comment.
  2. If some of the files are .cpp files, you want to check the commit comment. Otherwise, you want to ignore the comment.
  3. You only want .cpp files in your repository. Nothing else. And, you want to reject any commits that contain non-C++ file.

No matter what you're doing, you'll have to run the svnlook changed command and look at all fo the files that have been changed. Remember that there's only a single commit comment for all files committed.

I would be surprised if you're question involves reason #3. C development certainly requires Makefiles on the Unix side, and if you're using a IDE that allows you to specify the build without Makefiles, then there are some sort of project files that have to be stored.

You might want to checkout my kitchen sink pre-commit hook . This pre-commit hook will handle almost any situation you want. It uses a control file for configuration, so you don't have to modify the code.

Want to prevent people from anding any non-C++ files?

# Remove all permission
[file You don't have permission to add these files to the repository]
match = .*
access = read-only
users = @ALL

# Allow only files ending in .cpp
[file You don't have permission to add these types of files to the repository]
file = **/*.cpp
access = read-write
users = @ALL

# Users must be able to add directories
[file You don't have permission to add these types of files to the repository]
match = /$
access = read-write
users = @ALL

# Probably want to allow the addition of Makefiles too
[file You don't have permission to add these types of files to the repository]
match = [mM]akefile$
access = read-write
users = @ALL

Want to make sure the commit comment is valid?

[revprop You must add a VALID comment to your commits]
property = svn:log
value = .{10,}
type = regex

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM