2
# ====================================================================
3
# Copyright (c) 2000-2004 Collab Net. All rights reserved.
5
# This software is licensed as described in the file COPYING, which
6
# you should have received as part of this distribution. The terms
7
# are also available at http://subversion.tigris.org/license-1.html.
8
# If newer versions of this license are posted there, you may use a
9
# newer version instead, at your option.
11
# This software consists of voluntary contributions made by many
12
# individuals. For exact contribution history, see the revision
13
# history and logs, available at http://subversion.tigris.org/.
14
# ====================================================================
17
require 5.004; # This is when locale support was added.
18
# This 'use encoding' and setting the LANG environment variable has the
19
# desired effect of handling the comparison of extended characters and
20
# preventing a commit. However, if any of the files in conflict have
21
# extended characters in them this is the error displayed by the client:
23
# Commit failed (details follow):
24
# svn: MERGE request failed on '/svn/play/martinto/trunk'
25
# svn: General svn error from server
27
# It should list the file names which are in conflict. But it does stop the
30
$ENV{'LANG'} = 'en_GB.UTF-8';
32
# Please check the path to svnlook is correct...
34
if ($^O eq 'MSWin32') {
35
$svnlook = '"c:\Program Files\subversion\bin\svnlook.exe"';
37
$svnlook = '/usr/local/bin/svnlook';
40
# This script can be called from a pre-commit hook on either Windows or a Unix
41
# like operating system. It implements the checks required to ensure that the
42
# repository acts in a way which is compatible with a case preserving but
43
# case insensitive file system.
45
# When a file is added this script checks the file tree in the repository for
46
# files which would be the same name on a case insensitive file system and
49
# On a Unix system put this script in the hooks directory and add this to the
52
# $REPOS/hooks/check-case-insensitive.pl "$REPOS" "$TXN" || exit 1
54
# On a windows machine add this to pre-commit.bat:
56
# perl <path-to-script>\check-case-insensitive.pl %1 %2
57
# if errorlevel 1 goto :ERROR
60
# echo Error found in commit 1>&2
63
# You may need to change the setting of $svnlook to the path to the
64
# executable on your system.
66
# Turn on debug by adding up to three -debug options as the first options in
67
# the list. The more -debug options the more output. If you specify more
68
# than one the output goes into a file.
70
# If you have any problems with this script feel free to contact
71
# Martin Tomes <martin@tomes.org.uk>
73
# Bugfixes and some debug code added by Jeremy Bettis <jeremy@deadbeef.com>
76
# Shift off any debug options.
78
while (@ARGV and $ARGV[0] =~ /^-d(ebug)?$/) {
83
# If there is too much debug output to STDERR subversion doesn't like it, so,
84
# if a lot of output is expected send it to a file instead.
86
if ($^O eq 'MSWin32') {
87
open(STDERR, ">c:/svnlog.txt")
88
or die "$0: cannot open 'c:/svnlog.txt' for writing: $!\n";
90
open(STDERR, ">/tmp/svnlog.txt")
91
or die "$0: cannot open '/tmp/svnlog.txt' for writing: $!\n";
95
# Fetch the command line arguments.
97
die "usage: $0 [-d [-d [-d]]] repos txn [--revision]\n";
103
# Jeremy Bettis <jeremy@deadbeef.com> wrote the $flag code and has this to
106
# The reason I did that was so that I could test the hook without actually
107
# doing a commit. Whenever I had a commit that succeeded in making a bad file
108
# or directory, or when a commit took too long I just did a sequence of
109
# operations like this:
111
# svnlook youngest path
112
# (it tells me that HEAD is 987 or whatever)
113
# check-case-insensitive.pl -debug path 987 -r
114
# and then the check-case-insensitive.pl passes -r to svnlook instead of
117
# Of course when it gets down to # Get the file tree at the previous revision,
118
# then it doesn't work, but most of my problems were found before that point.
119
my $flag = '--transaction';
120
$flag = shift if @ARGV;
122
# Each added path put here.
125
# The file tree as a hash, index lower cased name, value actual name.
128
# Command being executed.
131
print STDERR "LANG=", $ENV{'LANG'}, "\n" if ($debug and defined($ENV{'LANG'}));
132
# Get a list of added files.
134
$cmd = "$svnlook changed \"$repos\" $flag $txn";
135
print STDERR "$cmd\n" if ($debug);
136
open(SVNLOOK, $openstr, $cmd)
137
or die("$0: cannot open '$cmd' pipe for reading: $!\n");
147
print STDERR "Added " . ($#added + 1) . " items:\n";
148
foreach my $itm (@added) {
149
print STDERR " $itm\n";
154
print STDERR "No files added\n" if ($debug);
155
# No added files so no problem.
159
# Get the shortest directory name which has changed, this will be the path
160
# into the repository to use to get the history.
161
$cmd = "$svnlook dirs-changed \"$repos\" $flag $txn";
162
print STDERR "$cmd\n" if ($debug);
163
open(SVNLOOK, $openstr, $cmd)
164
or die("$0: cannot open '$cmd' pipe for reading: $!\n");
169
print STDERR " ", $_, "\n" if ($debug > 2);
170
if (length($_) < $shortest) {
172
$shortest = length($_);
176
# There isn't a leading slash on $changed but there is a trailing one. When
177
# it is the root of the repository the / is a pain, so always remove the
178
# trailing slash and put it back in where needed.
181
# Use the history of $changed path to find the revision of the previous commit.
182
$cmd = "$svnlook history \"$repos\" \"$changed/\"";
183
print STDERR "$cmd\n" if ($debug);
184
open(SVNLOOK, $openstr, $cmd)
185
or die("$0: cannot open '$cmd' pipe for reading: $!\n");
196
# Get the file tree at the previous revision and turn the output into
197
# complete paths for each file.
199
$cmd = "$svnlook tree \"$repos\" \"$changed/\" --revision $lastrev";
200
print STDERR "$cmd\n" if ($debug);
201
open(SVNLOOK, $openstr, $cmd)
202
or die("$0: cannot open '$cmd' pipe for reading: $!\n");
205
print STDERR "tree: '", $_, "'\n" if ($debug > 2);
206
next if (/^\/{1,2}$/); # Ignore the root node. Two /'s at root of the repos.
207
if (/^(\s+)(.*)\/$/) { # Is a directory.
208
$#path = length($1)-2; # Number of spaces at start of line is nest level.
210
my $name = join('/', @path) . '/';
212
if ($changed eq '') {
215
$index = $changed . '/' . $name;
217
$tree{lc($index)} = $name; # Index the hash with case folded name.
218
print STDERR "\$tree{lc($index)}=$name (dir)\n" if ($debug > 1);
219
} elsif (/^(\s+)(.*)$/) { # This is a real file name, not a directory.
220
$#path = length($1)-2; # Number of spaces at start of line is nest level.
225
$name = join('/', @path) . '/' . $2;
228
if ($changed eq '') {
231
$index = $changed . '/' . $name;
233
$tree{lc($index)} = $name; # Index the hash with case folded name.
234
print STDERR "\$tree{lc($index)}=$name\n" if ($debug > 1);
241
foreach my $newfile (@added) {
242
print STDERR "Checking \$tree{lc($newfile)}\n" if ($debug > 1);
243
# Without the following line it gets the lc() wrong.
244
my $junk = "x$newfile";
245
if (exists($tree{lc($newfile)})) {
246
$failmsg .= "\n $newfile already exists as " . $tree{lc($newfile)};
249
if (defined($failmsg)) {
250
print STDERR "\nFile name case conflict found:\n" . $failmsg . "\n";