I would like to know how to get the list of files that are being committed on the pre-commit hook.
If that list doesn't contain a specific file in a specific path, then I want to reject the commit.
Use svnlook
in a pre-commit.
svnlook changed
gives the changed paths of the commit. Compare this against your list. And reject it if path is found/not found. One simple example for pre-commit could be.
#!/bin/sh
REPOS="$1"
TXN="$2"
SPATH="specific/path"
FOUND=$(svnlook changed -t "$TXN" "$REPOS" | tr -d '\n' | grep -E ".*$SPATH.*")
if [ "$FOUND" != "" ]
then
echo "Reject commit!" 1>&2 && exit 1
else
exit 0
fi
Here I removed newlines and grep for the interested path. If path is not found, recject the commit exit 1
. User will see what you echo there.
The hook scripts should use the svnlook
command and not svn
. The svnlook
command can take the transaction number of the commit (if this is a pre-commit hook, you need to use the transaction number. If this is a post-commit hook, you need the revision number).
Do a svnlook -h
to see all of the subcommands. Here's a list of them:
author
- Retrieve the user ID of the committercat
- Prints out a file specifiedchanged
- Prints out the files and directories changeddate
- Prints out the timestamp of the commitdiff
- Prints out the diff of all the filesdirs-changed
- Prints out the directories changed (filesize
- Prints out the filesize in bytes`history
- Prints out the history (more like svn log
)info
- Prints out the information of a filelock
- Prints out the lock informationpropget
- Gets a particular property.proplist
- Lists all properties.tree
- Prints out the directory structureuuid
- Prints out the UUID of the repositoryyoungest
- Prints out the last revision number.Looks like svnlook changed
is what you want.
Two very important things about svnlook
:
svnlook
command cannot change any data, just display it. Some people look to see how you can change a property value with svnlook
. Answer, you can't.svnlook
takes the Repository Directory Location as an argument, and not the URL of the repository. This means svnlook
can only run on the server itself.