static bool ShouldCommitHooksRun(SvnHookArguments ha) { // By default always run the commit hooks bool runCommitHooks = true; SvnLookOrigin slo = new SvnLookOrigin(ha.RepositoryPath, ha.TransactionName); SvnChangeInfoEventArgs sciea; using (SvnLookClient slc = new SvnLookClient()) { bool gotLogInfo = slc.GetChangeInfo(slo, out sciea); Trace.WriteLineIf(!gotLogInfo, "Failed to GetLogInfo() for Commit, Commit Hooks NOT Ran"); // If we fail to get the log we're going to play it safe // and not run these commit hooks runCommitHooks = gotLogInfo; } if (runCommitHooks) { // If the magic keywords [ignoreall] or [ignorefileformathooks] // are found don't run these commit hooks. string logMessage = sciea.LogMessage; if (!string.IsNullOrEmpty(logMessage)) { IEnumerable<string> magicIgnoreKeywords = new string[] { "[ignoreall]", "[ignorefileformathooks]" }; runCommitHooks = !logMessage.ContainsAny(magicIgnoreKeywords); } } return runCommitHooks; }
/// <summary> /// pre-commitのロードを行います。 /// </summary> /// <param name="args">呼出パラメーター。</param> /// <returns>true:成功, false:失敗。</returns> public bool Load(string[] args) { if (!SvnHookArguments.ParseHookArguments(args, SvnHookType.PreCommit, false, out hookArgs)) { Console.Error.WriteLine("パラメーターが不正です。"); return(false); } return(true); }
public ReposHookEventArgs(SvnHookType ht, string[] args, string stdinText) { _args = args; _stdinText = stdinText; SvnHookArguments ha; if (SvnHookArguments.ParseHookArguments(args, ht, new StringReader(stdinText), out ha)) { _ha = ha; } }
public void InstallRevpropHook(Uri repositoryUrl) { string bat = Path.ChangeExtension(SvnHookArguments.GetHookFileName(repositoryUrl.LocalPath, SvnHookType.PreRevPropChange), ".bat"); File.WriteAllText(bat, "exit 0"); }
protected void InstallRevpropHook(string reposPath) { string bat = Path.ChangeExtension(SvnHookArguments.GetHookFileName(reposPath, SvnHookType.PreRevPropChange), ".bat"); File.WriteAllText(bat, "exit 0"); }
public ReposHookEventArgs(SvnHookType ht, string[] args, string stdinText) { _args = args; _stdinText = stdinText; SvnHookArguments ha; if (SvnHookArguments.ParseHookArguments(args, ht, new StringReader(stdinText), out ha)) { _ha = ha; } }
public IDisposable InstallHook(Uri reposUri, SvnHookType type, EventHandler <ReposHookEventArgs> hook) { if (reposUri == null) { throw new ArgumentNullException("reposUri"); } else if (!reposUri.IsFile) { throw new InvalidOperationException(); } string reposPath = reposUri.LocalPath; TempFileCollection tfc = new TempFileCollection(); string dir = Path.GetTempPath(); string suffix = Guid.NewGuid().ToString("N"); string args = Path.Combine(dir, suffix + "-args.txt"); string stdin = Path.Combine(dir, suffix + "-stdin.txt"); string done = Path.Combine(dir, suffix + "-done.txt"); string wait = Path.Combine(dir, suffix + "-wait.txt"); string errTxt = Path.Combine(dir, suffix + "-errTxt.txt"); string outTxt = Path.Combine(dir, suffix + "-outTxt.txt"); tfc.AddFile(args, false); tfc.AddFile(stdin, false); tfc.AddFile(wait, false); tfc.AddFile(errTxt, false); tfc.AddFile(outTxt, false); ThreadStopper stopper = new ThreadStopper(); string envPrefix = Path.GetFileNameWithoutExtension(SvnHookArguments.GetHookFileName(reposPath, type)) + "."; Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_FILE", args); Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_STDIN", stdin); Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_DONE", done); Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_WAIT", wait); Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDOUT", outTxt); Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDERR", errTxt); string file = Path.ChangeExtension(SvnHookArguments.GetHookFileName(reposPath, type), ".exe"); stopper.Start( delegate { try { while (!stopper.Cancel) { if (File.Exists(done)) { List <string> argCollection = new List <string>(); using (StreamReader fs = File.OpenText(args)) { string line; while (null != (line = fs.ReadLine())) { argCollection.Add(line); } } string stdinText = File.ReadAllText(stdin); File.Delete(args); File.Delete(stdin); ReposHookEventArgs ra = new ReposHookEventArgs(type, argCollection.ToArray(), stdinText); try { hook(this, ra); } catch (Exception e) { if (string.IsNullOrEmpty(ra.ErrorText)) { ra.ErrorText = e.ToString(); } ra.ExitCode = 129; } finally { if (ra.ErrorText != null) { File.WriteAllText(errTxt, ra.ErrorText); } if (ra.OutputText != null) { File.WriteAllText(outTxt, ra.OutputText); } File.WriteAllText(wait, ra.ExitCode.ToString()); } File.Delete(done); if (ra.Cancel) { break; } } Thread.Sleep(50); } } finally { Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_FILE", null); Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_STDIN", null); Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_DONE", null); Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_WAIT", null); Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDOUT", null); Environment.SetEnvironmentVariable(envPrefix + "SHARPSVNHOOK_OUT_STDERR", null); } GC.KeepAlive(tfc); File.Delete(file); }); File.Copy(Path.Combine(ProjectBase, "..\\tools\\hooknotifier\\bin\\" + Configuration + "\\HookNotifier.exe"), file); return(stopper); }