1 |
#!/bin/sh |
2 |
# |
3 |
# $MidnightBSD$ |
4 |
# http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/detect-merge-conflicts.sh |
5 |
|
6 |
# A pre-commit hook to detect changes that look like forgotten |
7 |
# conflict markers. If any additions starting with '>>>>>>>' |
8 |
# or '<<<<<<<' are found, the commit is aborted with a nice |
9 |
# error message. |
10 |
# |
11 |
|
12 |
REPO=$1 |
13 |
TXN=$2 |
14 |
|
15 |
SVNLOOK=/usr/local/bin/svnlook |
16 |
|
17 |
# Check arguments |
18 |
if [ -z "$REPO" -o -z "$TXN" ]; then |
19 |
echo "Syntax: $0 path_to_repos txn_id" >&2 |
20 |
exit 1 |
21 |
fi |
22 |
|
23 |
# We scan through the transaction diff, looking for things that look |
24 |
# like conflict markers. If we find one, we abort the commit. |
25 |
SUSPICIOUS=$($SVNLOOK diff -t "$TXN" "$REPO" | grep -E '^\+(<{7} \.|>{7} \.)' | wc -l) |
26 |
|
27 |
if [ $SUSPICIOUS -ne 0 ]; then |
28 |
echo "Some parts of your commit look suspiciously like merge" >&2 |
29 |
echo "conflict markers. Please double-check your diff and try" >&2 |
30 |
echo "committing again." >&2 |
31 |
exit 1 |
32 |
fi |
33 |
|
34 |
# No conflict markers detected, let it fly! |
35 |
exit 0 |