#!/usr/bin/perl -w
######################################################################
##
## description:
##   start-hook script to verify that client reports correct merge
##   capabilities.
##
## usage:
##   check-merge-capabilities.pl CAPABILITES
##   where
##     CAPABILITIES : colon separated list of capabilities
##
## exit value:
##   non-zero if client doesn't report mergeinfo capabilities
##
######################################################################
use strict;

## check number of arguments
if ($#ARGV != 0) {
    exit 1;
}

## read capabilities argument
my $capabilities = $ARGV[0];

## split on colon
my @capabilities = split(':', $capabilities);

## loop over capabilities and look for mergeinfo
my $mergeinfo = 0;
foreach (@capabilities) {
    if ($_ eq "mergeinfo") {
	## found it
	$mergeinfo = 1;
	last;
    }
}

## if mergeinfo capability was found then exit normally
if ($mergeinfo) {
    exit 0;
}

## otherwise output an error and exit non-zero
my $rule = 
    "ERROR: your subversion client is not indicating that it supports ".
    "subversion 1.5 style merge tracking.\n".
    "ERROR: therefore you will not be allowed to commit any changes.\n".
    "ERROR: upgrade your subversion client to ver. 1.5.0 or greater.".
    "ERROR: capabilities reported are [$capabilities]\n.";
printf STDERR "$rule";
exit 1
