public void EndTransaction() { var transactionMessage = string.Join(Environment.NewLine, this.transactionMessageList); var messagePath = FileUtility.WriteAllText(transactionMessage, Encoding.UTF8, PathUtility.GetTempFileName()); try { var items = this.statCommand.ReadLines(true); if (items.Length != 0) { var propText = SvnRepositoryProvider.GeneratePropertiesArgument(this.transactionPropertyList.ToArray()); var updateCommand = new SvnCommand("update") { (SvnPath)this.BasePath }; var commitCommand = new SvnCommand("commit") { (SvnPath)this.BasePath, SvnCommandItem.FromFile(messagePath), propText, SvnCommandItem.FromEncoding(Encoding.UTF8), SvnCommandItem.FromUsername(this.transactionAuthor), }; updateCommand.Run(this.logService); commitCommand.Run(this.logService); FileUtility.Delete(this.transactionPatchPath); this.transactionAuthor = null; this.transactionName = null; this.transactionMessageList = null; this.transactionPropertyList = null; this.transactionPatchPath = null; } else { this.logService?.Debug("repository has no changes."); } } finally { FileUtility.Delete(messagePath); } }
public void RevertRepository(string author, string basePath, string repositoryName, string revision, string comment) { var baseUri = new Uri(basePath); var url = repositoryName == SvnString.Default ? UriUtility.Combine(baseUri, SvnString.Trunk) : UriUtility.Combine(baseUri, SvnString.Branches, repositoryName); var tempPath = PathUtility.GetTempPath(false); try { var checkoutCommand = new SvnCommand("checkout") { (SvnPath)url, (SvnPath)tempPath, }; checkoutCommand.Run(); var mergeCommand = new SvnCommand("merge") { new SvnCommandItem('r', $"head:{revision}"), (SvnPath)tempPath, (SvnPath)tempPath, }; mergeCommand.Run(); var commitCommand = new SvnCommand("commit") { (SvnPath)tempPath, SvnCommandItem.FromMessage(comment), SvnCommandItem.FromEncoding(Encoding.UTF8), SvnCommandItem.FromUsername(author), }; commitCommand.Run(); } catch (Exception e) { throw e; } finally { DirectoryUtility.Delete(tempPath); } }
public void Commit(string author, string comment, params LogPropertyInfo[] properties) { if (this.transactionName != null) { var diffCommand = new SvnCommand("diff") { (SvnPath)this.BasePath, new SvnCommandItem("patch-compatible") }; var output = diffCommand.ReadLine(); File.WriteAllText(this.transactionPatchPath, output); this.transactionMessageList.Add(comment); this.transactionPropertyList.AddRange(properties); return; } this.logService?.Debug($"repository committing {(SvnPath)this.BasePath}"); var result = string.Empty; var commentPath = PathUtility.GetTempFileName(); var propText = SvnRepositoryProvider.GeneratePropertiesArgument(properties); var updateCommand = new SvnCommand("update") { (SvnPath)this.BasePath }; var commitCommand = new SvnCommand("commit") { (SvnPath)this.BasePath, SvnCommandItem.FromMessage(comment), propText, SvnCommandItem.FromEncoding(Encoding.UTF8), SvnCommandItem.FromUsername(author), }; try { if (this.needToUpdate == true) { updateCommand.Run(this.logService); } result = commitCommand.Run(this.logService); } catch (Exception e) { this.logService?.Warn(e); updateCommand.Run(this.logService); result = commitCommand.Run(this.logService); } finally { this.needToUpdate = false; FileUtility.Delete(commentPath); } if (result.Trim() != string.Empty) { this.logService?.Debug(result); this.logService?.Debug($"repository committed {(SvnPath)this.BasePath}"); this.info = SvnInfo.Run(this.BasePath); this.repositoryInfo.Revision = this.info.LastChangedRevision; this.repositoryInfo.ModificationInfo = new SignatureDate(this.info.LastChangedAuthor, this.info.LastChangedDate); } else { this.logService?.Debug("repository no changes. \"{0}\"", this.BasePath); } }