Quand je devais faire ce que je suivi ce guide: http://www.troyhunt.com/2010/02/creating-subversion-pre-commit-hooks-in.html
J'ai écrit une application C# qui a appelé svnlook et a été tiré par le crochet de se engager au préalable pour vérifier si le chemin a été autorisé ou non.
Voici mon code, il devrait être facilement adaptable à votre situation:
class Program
{
static void Main(string[] args)
{
var repos = args[0];
var txn = args[1];
var log = GetSvnLookOutput(repos, txn, "log");
var changedPaths = GetSvnLookOutput(repos, txn, "changed");
var logValidation = GetLogMessageErrors(log.Replace("\r", "").Replace("\n", ""));
if (logValidation != null)
{
Console.Error.WriteLine(logValidation);
Environment.Exit(1);
}
if (log.Contains("Autoversioning commit"))
{
// this is an autoversion webdav client, enforce path rules
var changedPathsValidation = GetFileNameErrors(changedPaths);
if (changedPathsValidation != null)
{
Console.Error.WriteLine(changedPathsValidation);
Environment.Exit(1);
}
}
Environment.Exit(0);
}
private static string GetLogMessageErrors(string log)
{
if (string.IsNullOrEmpty(log))
{
return "Log message is required.";
}
return null;
}
private static string GetFileNameErrors(string changedPaths)
{
var changeRows = Regex.Split(changedPaths.TrimEnd(), Environment.NewLine);
foreach (var changeRow in changeRows)
{
var filePath = changeRow.Substring(4, changeRow.Length - 4);
if (filePath.ToLower().Contains("/code/"))
{
return "Autoversioning commits are not allowed inside /CODE/ folders. Use a SVN client for this.";
}
}
return null;
}
private static string GetSvnLookOutput(string repos, string txn, string subcommand)
{
var processStartInfo = new ProcessStartInfo
{
FileName = @"svnlook.exe",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
Arguments = String.Format("{0} -t \"{1}\" \"{2}\"", subcommand, txn, repos)
};
var process = Process.Start(processStartInfo);
var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output;
}
}
Pouvez-vous utiliser et ACLs accorder à tous les utilisateurs un accès en lecture seule aux branches que vous voulez protéger? Vous pouvez utiliser C# pour modifier le fichier de configuration ACL. –
Jetez un oeil à cette question pour voir si cela aide: http://stackoverflow.com/questions/8074143 –
Est-ce que ce doit être C#? J'ai un [crochet de pré-commit] (https://github.com/qazwart/SVN-Precommit-Kitchen-Sink-Hook) en Perl qui fait exactement ce que vous voulez. Il utilise un fichier de contrôle et le fichier de contrôle peut être stocké dans le référentiel. Vous pouvez donc modifier les autorisations de validation sans devoir accéder au serveur. Vous pouvez obtenir une version gratuite de Perl à partir de [ActiveState] (http://www.activestate.com/activeperl). –