private void _Reset() { using (var cmd = new CommandPrompt(true)) { cmd.WriteLine("cd {0}", this.Info.Directory); cmd.WriteLine("git pull -p"); cmd.WriteLine("git clean -f -d"); cmd.WriteLine("exit"); cmd.RethrowError(); cmd.WaitForExit(); } }
/// <summary> /// Commits one or more files directly to the repository. Installed SSH key is required. /// </summary> /// <param name="password">Password for the user's account.</param> /// <param name="message">Message of the commit.</param> /// <param name="author">Author of the commit. Username if empty.</param> /// <param name="folder">Path to a folder in the tree. Root folder if empty.</param> /// <param name="fileNames">Names of the files to commit. All files if empty.</param> public void Commit(string message, string description = null, string fileName = null, string authorName = null, string authorEmail = null) { if (!IsCloned()) { throw new Exception("Could not commit, because the repository was not cloned yet."); } if (string.IsNullOrEmpty(message)) { throw new Exception("Commit message cannot be empty."); } string descriptionParts = ""; string temp = ""; for (int i = 0; description != null && i < description.Length; ++i) { if (description[i] == '\r' || description[i] == '\n' || i == description.Length - 1) { if (temp.Trim().Length > 0) { descriptionParts += string.Format(" -m \"{0}\"", temp.Replace("\"", "\\\"")); temp = ""; } } else { temp += description[i]; } } using (var cmd = new CommandPrompt(true)) { cmd.WriteLine("cd {0}", this.Info.Directory); cmd.WriteLine("git reset HEAD -- ."); cmd.WriteLine("git add {0}", !string.IsNullOrEmpty(fileName) ? fileName : "."); cmd.WriteLine("git commit{0}{1}{2}", !string.IsNullOrEmpty(authorName) ? string.Format(" --author=\"{0} <{1}>\"", authorName, (!string.IsNullOrEmpty(authorEmail) ? authorEmail : "")) : "", string.Format(" -m \"{0}\"", message), !string.IsNullOrEmpty(descriptionParts) ? descriptionParts : ""); cmd.WriteLine("git push https://github.com/{0}/{1}/ {2}", this.Info.User, this.Info.Name, this.Info.Branch); cmd.WriteLine("exit"); cmd.WaitForExit(); cmd.RethrowError(); } }
/// <summary> /// Clones the repository into the given directory. /// </summary> /// <param name="override">Override the repository folder if it already exists.</param> /// <param name="reset">Reset the repository if it is already cloned.</param> /// <returns> /// 0: Repository was cloned successfully. /// 1: The repository folder already existed and was overriden. /// 2: The repository was already cloned and was reseted. /// </returns> public int Clone(bool @override = false, bool reset = false) { if (reset && IsCloned()) { _Reset(); return(2); } if (@override && System.IO.Directory.Exists(this.Info.Directory)) { DirectoryExt.ForceDelete(this.Info.Directory, true); return(1); } using (var cmd = new CommandPrompt(true)) { cmd.WriteLine("cd {0}", this.Info.BaseDirectory); cmd.WriteLine("git clone https://github.com/{0}/{1} --branch {2}", this.Info.User, this.Info.Name, this.Info.Branch); cmd.WriteLine("exit"); cmd.RethrowError(); cmd.WaitForExit(); } return(0); }