The echo
isn't going to do anything since hook scripts only display STDERR and only if the hook fails. STDOUT is never displayed. Could that be an issue?
What you need to do is to print out STDERR, and purposefully fail your post-commit hook. Not a Windows batch script expert, and I don't have a Windows machine to test this on, but something like this:
@setlocal enableextensions enabledelayedexpansion
@echo off
SET str1=%1
echo STR1 = %str1% >&2
echo IF NOT x%str1:dev=% == x%str1%x >&2
IF NOT x%str1:dev=%==x%str1% (
pushd <path to working copy>
echo IN directory %CD% >&2
echo svn update >&2
svn update --username <svn_username> --password <svn_password>
echo update complete
)
endlocal
exit 1
The echo
commands will output to STDERR and the exit 1
will force your post-commit hook to fail. When you do a commit, you can see what's going on, and it may help you determine where your problem lies.
By the way, Don't use Windows batch scripts for hooks. Windows Batch is ...um... a quirky language. You can use either Perl or Python ( or even Ruby ) on Windows. These are way more powerful, flexible, and will work better for your hook scripts.
If you or your company insist on Microsoft only solutions ("Perl and Python are hacker languages." or "We don't use shareware here.") , try using PowerShell which comes with Windows.
Addendum
Ok, now it's giving me this:
Error: STR1 = D:\Repositories\<repository-name>
Error: IF NOT xD:\Repositories\<repository-name> ==xD:\Repositories\<repository-name>x
Shouldn't %1
have the whole path, including branches\dev
?
Now we know what the issue is:
There are two different things we're talking about:
- There's the virtual location in the repository. This is in the URL of the file and usually the result of what happens when you use the
svn
(or svnlook
command).
- there's the physical location in the repository. This is the actual directory where your repository sits on your server.
You are interested in the virtual location of the files and directories. What %1
actually is is the physical location of the repository -- what drive and directory.
The two have nothing to do with each other.
So, how can you tell if a commit was on dev
? Since it is possible for a single commit to be on multiple branches, and even on trunk at the same time, you would have to go through all the changes that took place on that commit. Usually, you use the svnlook changed
command:
svnlook changed -r %2 %1
Note that I use the %1
to point to the physical location of the repository while %2
is the revision that was changed.
This will give me a listing like this:
A /dev/foo/
A /dev/foo/foo.pl
U /test/bar/bar.pl
D /trunk/foo/bar/foobar.pl
The first letter in the output is whether something was added, deleted, or updated. The second is what was added, deleted, or updated. Something that ends with a /
is a directory and not a file.
You would have to parse the entire output, and verify that none of the changes took place on the dev branch.
How would you do this in standard Windows Batch? I'm not sure. It might be possible, but even with BASH shell, which is way more powerful, it would be a bit of a challenge. This is why I tell people to use Python or Perl or some full level scripting language.