private static Version getVersion() { try { IEnumerable <string> stdOut = ExternalProcess.Start("git", "--version", true, String.Empty).StdOut; if (!stdOut.Any()) { throw new UnknownVersionException(null); } Match m = gitVersion_re.Match(stdOut.First()); if (!m.Success || m.Groups.Count < 3 || !m.Groups["major"].Success || !m.Groups["minor"].Success || !m.Groups["build"].Success || !int.TryParse(m.Groups["major"].Value, out int major) || !int.TryParse(m.Groups["minor"].Value, out int minor) || !int.TryParse(m.Groups["build"].Value, out int build)) { throw new UnknownVersionException(null); } return(new Version(major, minor, build)); } catch (ExternalProcessException ex) { throw new UnknownVersionException(ex); } }
private static void setConfigKeyValueUnsafe(ConfigScope scope, string key, string value, string path) { string mode = value == null ? "unset" : ""; string scopeString = scope.ToString().ToLower(); string config = String.Format("config --{0} --{1} {2} {3}", scopeString, mode, key, value ?? ""); ExternalProcess.Start("git", config, true, path); }
public static IEnumerable <string> GetRemotePointsAt(string path, string sha) { try { string arguments = String.Format("branch --format=%(refname:short) --remote --points-at \"{0}\"", sha); return(ExternalProcess.Start("git", arguments, true, path).StdOut); } catch (ExternalProcessException) { return(Array.Empty <string>()); } }
private static string getRemoteUrl(string path) { try { IEnumerable <string> stdOut = ExternalProcess.Start("git", "config --get remote.origin.url", true, path).StdOut; return(stdOut.Any() ? stdOut.First() : null); } catch (ExternalProcessException) { return(null); } }
public static IEnumerable <string> GetConfigKeyValue(ConfigScope scope, string key, string path = "") { try { string scopeString = scope.ToString().ToLower(); string config = String.Format("config --{0} {1}", scopeString, key); ExternalProcess.Result result = ExternalProcess.Start("git", config, true, path); return(result.StdOut); } catch (ExternalProcessException) { return(Array.Empty <string>()); } }
public static void TraceGitConfiguration() { try { foreach (string arguments in new string[] { "--version", "config --global --list", "config --system --list" }) { IEnumerable <string> stdOut = ExternalProcess.Start("git", arguments, true, String.Empty).StdOut; if (stdOut.Any()) { Trace.TraceInformation(String.Format("git {0} ==>\n{1}", arguments, String.Join("\n", stdOut))); } } } catch (ExternalProcessException ex) { ExceptionHandlers.Handle("Cannot trace git configuration", ex); } }
private static string getRemoteUrl(string path) { try { IEnumerable <string> stdOut = ExternalProcess.Start("git", "config --get remote.origin.url", true, path).StdOut; return(stdOut.Any() ? stdOut.First() : null); } catch (Exception ex) { if (ex is ExternalProcessFailureException || ex is ExternalProcessSystemException) { return(null); } else { throw; } } }