// Standard constructor private GitLocalRepository(string location) { Location = location; var result = GitController.Default.TryExecute(GitCommandBuilder.Format(Location, "%H")); Hash = result ? "" : result.Out.ToLowerInvariant(); }
/// <summary> /// Is valid repository /// </summary> public static bool IsRepository(string path) { if (string.IsNullOrWhiteSpace(path)) { path = Environment.CurrentDirectory; } if (!Directory.Exists(path)) { return(false); } var result = GitController.Default.TryExecute(GitCommandBuilder.Format(path, "%H")); return(!string.IsNullOrEmpty(result.Out) && result.Out.All(c => c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F')); }
/// <summary> /// Create a new repository by cloning /// </summary> /// <param name="ssh">SSH</param> /// <param name="branch">Branch</param> /// <param name="path">Path</param> /// <returns></returns> public static GitLocalRepository Clone(Uri ssh, string branch, string path) { if (ssh is null) { throw new ArgumentNullException(nameof(ssh)); } if (string.IsNullOrEmpty(path)) { path = Environment.CurrentDirectory; } if (Directory.Exists(path)) { if (Directory.EnumerateDirectories(path).Any() || Directory.EnumerateFiles(path).Any()) { throw new ArgumentException($"Directory {path} already exist.", nameof(path)); } } Directory.CreateDirectory(path); var result = GitController.Default.TryExecute(GitCommandBuilder.Clone(ssh, branch, path, true)); if (result) { return(new GitLocalRepository(path) { m_Ssh = ssh, m_Branch = branch, }); } else { result.ThrowIfError(); } return(null); }
/// <summary> /// Execute /// </summary> public GitResult Execute(string command) => GitController.Default.Execute(GitCommandBuilder.WithDirectory(command, Location));
/// <summary> /// Execute Async /// </summary> public Task <GitResult> ExecuteAsync(string command, CancellationToken token) => GitController.Default.ExecuteAsync(GitCommandBuilder.WithDirectory(command, Location), token);