-1

I'm gonna try to be as forthcoming as I can about my problem.

I'm on a Windows computer. The SVN repository is on a Linux machine.

I access the Linux machine remotely, using Putty and logging in as root. Everything is done through the command line.

Now, I have to set up a pre-commit hook that won't allow special characters like [éáú] on source code files. In order to do that, I set out to find out how to setup a pre-commit hook.

Here's what I've done:

  1. Found a script
  2. Went to the hooks folder in the repository. Removed the extension of the file pre-commit.tmpl
  3. Pasted the script there and saved
  4. Ran the chmod command on file pre-commit.tmpl

Then I tried commiting a change to the repository and I got:

Commit blocked by pre-commit hook (exit code 255) with no output

Alright, I figured something was wrong in how I set up the pre-commit file, so I removed the script and added a simple echo "hello world".

Now the commit goes through, but the echo message doesn't show up at all. If I put exit 1 at the end of the script, I get error code 1 and the echo message still doesn't show up.

I have literally searched high and low on the internet and have found no solution to my problem.

What I need:

  • An explanation as to why the echo messages are not showing up
  • If possible, a step-by-step on how to set up and test a simple script

For example, I've seen a lot of scripts where there's something like this:

#!/bin/bash
REPOS="$1"
TXN="$2"

What am I supposed to put in REPOS and in TXN? I assume in REPOS I should put the repository path? What about TXN?

Any help is appreciated.

Cheers

Błażej Michalik
  • 4,474
  • 40
  • 55
tyranius
  • 19
  • 3
  • `$1` and `$2` are variables representing the first and second arguments to the script. Presumably SVN runs your script with those correctly. You don't need to do anything there most likely. What those *mean* depends on the hook and the SVN hook documentation should tell you. – Etan Reisner Sep 10 '15 at 12:44
  • http://svnbook.red-bean.com/en/1.7/svn.ref.reposhooks.pre-commit.html – Etan Reisner Sep 10 '15 at 12:49
  • I've already read that Etan, it didn't help. Actually, not even something as simple as echo "hello world" exit 1 is working – tyranius Sep 10 '15 at 14:13
  • Did you see the bit about `standard error`? – Etan Reisner Sep 10 '15 at 14:17
  • In that page, or in the SVN book in general? What I really want to do now is at least make the echo message show up. It's so simple yet I can't get it to come out. I tried in Windows and in the Linux machine, no dice. _echo "Testing" >&2_. Why doesn't this work grrr? – tyranius Sep 10 '15 at 14:32
  • Did you output to stderr *and* exit with a failure? Because that's what the docs say you should need to do. – Etan Reisner Sep 10 '15 at 15:00

1 Answers1

1

Billet of the pre-commit hook (*Nix-adopted)

Always failing

#!/bin/bash 
echo You failed 1>&2
exit 1

commit sample

>svn commit -m "Changes"
Sending        Folder1\Folder2\Folder3
Sending        Folder4
svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 1) with output:
You failed

Note correct redirection of output in echo

About $REPO and $TXN (already linked) SVN Book chapter have full explanation

The command-line arguments passed to the hook program, in order, are:

  1. Repository path
  2. Commit transaction name

because these parameters are needed for most often used in pre-commit hooks commands, like svnlook

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110