public XmlReader GetXmlReader(string command, SvnCommandOptions options) { return(DoSvnAction(delegate() { XmlReader xReader; string output = null; try { _bubbleOutput = false; _errorOutput.Clear(); output = Run(command, options, true); xReader = new XmlTextReader(new StringReader(output)); xReader = XmlReader.Create(new StringReader(output), new XmlReaderSettings() { CloseInput = true }); } catch (Exception ex) { _process_StandardErrorMessageReceived(this, new EventArgs <string>(output ?? "")); throw new Exception(string.Format("Error occurred while attempting to load SVN result XML. {0}", string.Join(" ", _errorOutput.ToArray())), ex); } finally { _bubbleOutput = true; } return xReader; })); }
public XmlDocument GetXml(string command, SvnCommandOptions options) { return(DoSvnAction(delegate() { XmlDocument objXml = new XmlDocument(); string output = null; try { _bubbleOutput = false; _errorOutput.Clear(); output = Run(command, options, true); objXml.LoadXml(output); } catch (Exception ex) { _process_StandardErrorMessageReceived(this, new EventArgs <string>(output ?? "")); throw new Exception(string.Format("Error occurred while attempting to load SVN result XML. {0}", string.Join(" ", _errorOutput.ToArray())), ex); } finally { _bubbleOutput = true; } return objXml; })); }
private string GetXmlValue(string command, SvnPath path, string xpath, Revision revision) { XmlDocument objXml = new XmlDocument(); XmlNode objNode; string strValue = string.Empty; SvnCommandOptions options = _defaultOptions.Clone(); options.Revision = revision; options.Paths.Add(path); objXml = _command.GetXml(command, options); objNode = objXml.SelectSingleNode(xpath); if (objNode != null) { switch (objNode.NodeType) { case XmlNodeType.Attribute: strValue = objNode.Value; break; default: strValue = objNode.InnerText; break; } } else { throw new Exception(string.Format("Value for xpath '{0}' in SVN {1} output not found.", xpath, command)); } return(strValue); }
/// <summary> /// Commits changes to working copy <paramref name="paths"/>. /// </summary> /// <param name="paths"></param> public void Commit(List <string> paths, string comment) { SvnCommandOptions options = _defaultOptions.Clone(); options.Comment = comment; paths.ForEach(p => options.Paths.Add(SvnPath.CreateWCPath(p))); _command.Run("commit", options); }
private SvnHelper(SvnCommandOptions defaultOptions) { _defaultOptions = defaultOptions; _command = new SvnCommand(); _command.ErrorMessage += new EventHandler <EventArgs <string> >(_command_ErrorMessage); _command.OutputMessage += new EventHandler <EventArgs <string> >(_command_OutputMessage); _command.DebugMessage += new EventHandler <EventArgs <string> >(_command_DebugMessage); }
/// <summary> /// Reverts a working copy specified by <paramref name="path"/> to its original state. /// </summary> /// <param name="path">Working copy path.</param> /// <param name="depth">Affective depth of the command.</param> public void Revert(string path, DepthType depth) { SvnCommandOptions options = _defaultOptions.Clone(); options.Depth = depth; options.Paths.Add(SvnPath.CreateWCPath(path)); _command.Run("revert", options); }
/// <summary> /// Checks out the <paramref name="uri"/> to the <paramref name="workingCopyPath"/>. /// </summary> /// <param name="uri"></param> /// <param name="workingCopyPath"></param> public void CheckOut(string uri, string workingCopyPath, Revision revision) { SvnCommandOptions options = _defaultOptions.Clone(); options.Revision = revision; options.Paths.Add(SvnPath.CreateSvnPath(uri)); options.Paths.Add(SvnPath.CreateWCPath(workingCopyPath)); _command.Run("checkout", options); }
/// <summary> /// Updates the working copy specified in <paramref name="path"/> to the specified numeric <paramref name="revision"/>. /// </summary> /// <param name="path">Working copy path to update.</param> /// <param name="revision">Numeric revision to which the working path will be updated.</param> /// <param name="depth">The depth to which the operation will apply.</param> public void Update(string path, Revision revision, DepthType depth) { SvnCommandOptions options = _defaultOptions.Clone(); options.Revision = revision; options.Depth = depth; options.Paths.Add(SvnPath.CreateWCPath(path)); _command.Run("update", options); }
public string Run(string command, SvnCommandOptions options) { return(DoSvnAction(delegate() { string result; result = Run(command, options, false); return result; })); }
/// <summary> /// Exports the <paramref name="depth"/> of the <paramref name="revision" /> of the <paramref name="uri"/> to the <paramref name="localPath"/>. /// </summary> /// <param name="uri">URI to export.</param> /// <param name="revision">Repository revision to export.</param> /// <param name="depth">Depth of the export.</param> /// <param name="localPath">Local path to which the files will be exported.</param> /// <param name="force">Whether or not to force overwrite existing files. Required if target directory exists, even if empty.</param> public void Export(string uri, Revision revision, DepthType depth, string localPath, bool force) { SvnCommandOptions options = _defaultOptions.Clone(); options.Revision = revision; options.Depth = depth; options.MiscArgs.Add(force ? "--force" : null); options.Paths.Add(SvnPath.CreateSvnPath(uri)); options.Paths.Add(SvnPath.CreateWCPath(localPath)); _command.Run("export", options); }
private void ScheduleChange(string command, bool noignore, string[] paths) { SvnCommandOptions options = _defaultOptions.Clone(); options.IgnoreStandardExcludes = !noignore; foreach (var path in paths) { options.Paths.Add(SvnPath.CreateWCPath(path)); } _command.Run(command, options); }
public SvnCommandOptions Clone() { SvnCommandOptions clone = new SvnCommandOptions(); clone.CacheAuthCredentials = this.CacheAuthCredentials; clone.IgnoreStandardExcludes = this.IgnoreStandardExcludes; clone.Password = this.Password; clone.Username = this.Username; clone.WorkingDirectory = this.WorkingDirectory; return(clone); }
/// <summary> /// Gets a list of items in the specified <paramref name="path"/>. /// </summary> /// <param name="path">Path of which the contents will be listed.</param> /// <param name="revision">Revision to list.</param> /// <param name="depth">Desired depth of the listings.</param> /// <returns></returns> public List <SvnItem> List(SvnPath path, Revision revision, DepthType depth) { List <SvnItem> result = new List <SvnItem>(); SvnItem item = null; SvnCommandOptions options = _defaultOptions.Clone(); options.Depth = depth; options.Revision = revision; options.Paths.Add(path); XmlReader xReader = _command.GetXmlReader("list", options); while (xReader.Read()) { if (xReader.NodeType == XmlNodeType.EndElement) { continue; } switch (xReader.Name.ToLower()) { case "entry": item = new SvnItem(); result.Add(item); item.Type = GetItemType(xReader.GetAttribute("kind")); item.Commit = new SvnCommit(); break; case "name": item.Name = xReader.ReadString(); break; case "size": item.Size = xReader.ReadElementContentAsInt(); break; case "commit": item.Commit.Revision = int.Parse(xReader.GetAttribute("revision")); break; case "author": item.Commit.Author = xReader.ReadString(); break; case "date": item.Commit.Date = xReader.ReadElementContentAsDateTime(); break; } } return(result); }
/// <summary> /// Returns whether or not the specified <paramref name="path"/> is a working copy. /// </summary> /// <param name="path">The local path to check.</param> /// <returns></returns> public bool IsWorkingCopy(string path) { try { SvnCommandOptions options = _defaultOptions.Clone(); options.Paths.Add(SvnPath.CreateWCPath(path)); options.Depth = DepthType.Empty; _command.GetXml("status", options); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Checks the path status for any items that have changes (add, modify or delete) /// with the option of including unversioned files. /// </summary> /// <param name="path">Working copy path to check.</param> /// <returns></returns> public bool PathHasChanges(string path, bool includeUnversioned) { XmlDocument objXml = new XmlDocument(); XmlNodeList lstNodes; SvnCommandOptions options = _defaultOptions.Clone(); options.Paths.Add(SvnPath.CreateWCPath(path)); objXml = _command.GetXml("status", options); string strFilter = "@item='deleted' or @item='added' or @item='modified' or @item='missing'"; if (includeUnversioned) { strFilter = string.Concat(strFilter, " or @item='unversioned'"); } lstNodes = objXml.SelectNodes(string.Format("//wc-status[{0}]", strFilter)); return(lstNodes.Count > 0); }
/// <summary> /// Schedules appropriate changes to working copy: adds unversioned files and deletes missing files. /// </summary> /// <param name="path">Working copy path to modify.</param> /// <param name="noIgnore">Whether not to ignore the default ignores.</param> public bool ScheduleChanges(string path, bool noIgnore) { XmlDocument xmlDoc; XmlNodeList xmlNodes; XmlNode objStatusNode; List <string> lstDeletes = new List <string>(); List <string> lstAdds = new List <string>(); string nodePath, nodeAction; int skip = 0, take = 10; DoDebugMessage("retrieving working copy status"); SvnCommandOptions options = _defaultOptions; options.Paths.Add(SvnPath.CreateWCPath(path)); xmlDoc = _command.GetXml("status", options); xmlNodes = xmlDoc.SelectNodes("//entry[wc-status/@item!='normal']"); if (xmlNodes.Count > 0) { foreach (XmlNode node in xmlNodes) { objStatusNode = node.SelectSingleNode("wc-status"); nodeAction = objStatusNode.Attributes["item"].Value; nodePath = node.Attributes["path"].Value; switch (nodeAction) { case "missing": DoVerboseMessage("found missing item: {0}", nodePath); lstDeletes.Add(nodePath); break; case "unversioned": DoVerboseMessage("found unversioned item: {0}", nodePath); lstAdds.Add(nodePath); break; default: DoDebugMessage("ignoring action '{0}' on path '{1}'", nodeAction, nodePath); break; } } if (lstAdds.Count > 0) { skip = 0; DoDebugMessage("scheduling add changes in chunks of '{0}'", take); while (lstAdds.Count > skip) { DoDebugMessage("scheduling the next {0} adds", take); ScheduleChange("add", noIgnore, lstAdds.Skip(skip).Take(take).ToArray()); skip += take; } } if (lstDeletes.Count > 0) { skip = 0; DoDebugMessage("scheduling delete changes in chunks of '{0}'", take); while (lstDeletes.Count > skip) { DoDebugMessage("scheduling the next {0} deletes", take + skip); ScheduleChange("delete", false, lstDeletes.Skip(skip).Take(take).ToArray()); skip += take; } } return(true); } else { return(false); } }
private string Run(string command, SvnCommandOptions options, bool asXml) { EmbeddedProcessStartInfo startInfo = new EmbeddedProcessStartInfo(); StringBuilder sbArguments = new StringBuilder(); bool blnIncludeAuth = false; string strArg; _output = new StringBuilder(); startInfo.FileName = "svn.exe"; startInfo.WorkingDirectory = options.WorkingDirectory; blnIncludeAuth = !IfCommandIs(command, "status", "add", "delete", "move", "revert"); sbArguments.Append(command); if (IfCommandIs(command, "log")) { sbArguments.Append(" --verbose"); } if (asXml) { sbArguments.Append(" --xml"); } if (IfCommandIs(command, "update", "checkout", "info", "export", "log")) { sbArguments.AppendFormat(" --revision {0}", options.Revision.ToString()); } if (!options.IgnoreStandardExcludes) { sbArguments.Append(" --no-ignore"); } sbArguments.Append(" --non-interactive"); if (blnIncludeAuth) { if (!options.CacheAuthCredentials) { sbArguments.Append(" --no-auth-cache"); } if (!string.IsNullOrEmpty(options.Username)) { sbArguments.AppendFormat(" --username \"{0}\"", options.Username); } if (!string.IsNullOrEmpty(options.Password)) { sbArguments.AppendFormat(" --password \"{0}\"", options.Password); } } if (!string.IsNullOrEmpty(options.Comment)) { sbArguments.AppendFormat(" --message \"{0}\"", options.Comment); } if (options.Depth != DepthType.NotSet) { switch (options.Depth) { case DepthType.Empty: strArg = "empty"; break; case DepthType.Files: strArg = "files"; break; case DepthType.Infinity: strArg = "infinity"; break; case DepthType.Immediates: default: strArg = "immediates"; break; } sbArguments.AppendFormat(" --depth={0}", strArg); } foreach (string arg in options.MiscArgs) { if (!string.IsNullOrEmpty(arg)) { sbArguments.AppendFormat(" {0}", arg); } } foreach (SvnPath path in options.Paths) { if (!string.IsNullOrEmpty(path.Value)) { if (path.Value.Contains(' ')) { strArg = " \"{0}\""; } else { strArg = " {0}"; } sbArguments.AppendFormat(strArg, path.AsArgument(command, options.Revision).Trim().Trim('"')); } } startInfo.Arguments = sbArguments.ToString(); try { _process.Run(startInfo); } catch (Win32Exception win32Ex) { throw new Exception("Exception caught executing process: most probably 'svn.exe' was not found", win32Ex); } catch (Exception ex) { throw new Exception("An exception occurred running an SVN command.", ex); } if (_errorOutput.Any(e => e.Contains("not a working copy"))) { throw new NotWorkingCopyException(); } if (_process.ExitCode == 9009 && _output.ToString().Contains("not a working copy")) { throw new NotWorkingCopyException(); } else if (_process.ExitCode != 0) { throw new Exception("Failed while running 'svn.exe'. Error code " + _process.ExitCode); } return(_output.ToString()); }