Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVN pre-commit hook for avoiding changes to tags subdirectories

Is there anybody who has clear instructions on how to add a pre-commit hook that avoids changes to tags subdirectories?

I already searched the internet quite a bit. I found this link: SVN::Hooks::DenyChanges , but I can't seem to compile things.

like image 805
Wim Deblauwe Avatar asked Jan 21 '09 07:01

Wim Deblauwe


People also ask

What is pre-commit hook in SVN?

A pre-commit hook is a feature available in the Subversion version control system that allows code to be validated before it is committed to the repository. The PHP_CodeSniffer pre-commit hook allows you to check code for coding standard errors and stop the commit process if errors are found.

Why use pre-commit hook?

Better commit quality = better code quality The goal of pre-commit hooks is to improve the quality of commits. This is achieved by making sure your commits meet some (formal) requirements, e.g: that they comply to a certain coding style (with the hook style-files ).

How pre-commit hook works?

We run our hooks on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements. By pointing these issues out before code review, this allows a code reviewer to focus on the architecture of a change while not wasting time with trivial style nitpicks.

How are pre-commit hooks set?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.


1 Answers

I don't have enough reputation to "comment" on Raim's answer above, but his worked great, with one exception, his grep pattern is wrong.

I simply used the below as my pre-commit hook (I didn't have an existing one, you'd need to merge in that case):

#!/bin/sh  REPOS="$1" TXN="$2"  SVNLOOK=/opt/local/bin/svnlook  # Committing to tags is not allowed $SVNLOOK changed -t "$TXN" "$REPOS" | grep "^U\W.*\/tags\/" && /bin/echo "Cannot commit to tags!" 1>&2 && exit 1  # All checks passed, so allow the commit. exit 0 

The only problem with Raim's grep pattern is that it only matched "tags" if it was at the "root" of your repo. Since I have several projects in my repo, the script as he wrote it allowed commits on tag branches.

Also, be sure to chmod +x as indicated, otherwise you'll think it worked b/c the commit failed, but it failed b/c it couldn't exec the pre-commit hook, not because the hook worked.

This was really great, thanks Raim. Much better and lighter weight than all other suggestions as it has no dependencies!

like image 155
apinstein Avatar answered Sep 30 '22 09:09

apinstein