public (MemoryStream, IRepositoryPair.FileType) ReadFile(string path, string branch = "master") { var(data, code) = SharedRepository.ExecuteWithExitCode($"show \"{branch}\":\"{path}\""); if (code != 0) { throw new FileNotFoundException($"File not found `{branch}:{path}'"); } if (!string.IsNullOrWhiteSpace(path)) { path = $"-- \"{path}\""; } var log = SharedRepository.Execute($"log -1 --pretty=\"\" \"{branch}\" --numstat {path}"); using (var r = new StreamReader(new MemoryStream(log))) { if (r.ReadLine()[0] == '-') { return(new MemoryStream(data), IRepositoryPair.FileType.Binary); } else { return(new MemoryStream(data), IRepositoryPair.FileType.Text); } } }
public CommitInfo ReadCommitInfo(string path, string branch = "master") { if (!string.IsNullOrWhiteSpace(path)) { path = $"-- \"{path}\""; } var(data, code) = SharedRepository.ExecuteWithExitCode($"log -1 --pretty=\"%s\" \"{branch}\" {path}"); if (code != 0) { return(null); } var message = System.Text.Encoding.UTF8.GetString(data).Trim(); var hashes = System.Text.Encoding.UTF8.GetString(SharedRepository.Execute($"log -1 --pretty=\"%H %h\" \"{branch}\" -- {path}")).Trim().Split(" "); var authorName = System.Text.Encoding.UTF8.GetString(SharedRepository.Execute($"log -1 --pretty=\"%an\" \"{branch}\" -- {path}")).Trim(); var authorEmail = System.Text.Encoding.UTF8.GetString(SharedRepository.Execute($"log -1 --pretty=\"%ae\" \"{branch}\" -- {path}")).Trim(); var datestring = System.Text.Encoding.UTF8.GetString(SharedRepository.Execute($"log -1 --pretty=\"%ad\" \"{branch}\" -- {path}")).Trim(); DateTime date; DateTime.TryParseExact(datestring, "ddd MMM d HH:mm:ss yyyy K", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out date); var shortHash = hashes.Count() >= 2 ? hashes[1] : ""; return(new CommitInfo() { Message = message, Hash = hashes[0], ShortHash = shortHash, AuthorName = authorName, AuthorEmail = authorEmail, Date = date }); }
public void Create() { var shared = new DirectoryInfo(SharedRepository.DirectoryPath); shared.Create(); SharedRepository.Execute($"init --bare --shared {SharedRepository.DirectoryPath}"); ClonedRepository.Execute($"clone {SharedRepository.DirectoryPath} {ClonedRepository.DirectoryPath}", working_dir: "/"); }
public IEnumerable <string> ReadFileList(string path, string branch = "master") { if (!string.IsNullOrWhiteSpace(path)) { path = $"-- \"{path}\""; } return(System.Text.Encoding.UTF8.GetString(SharedRepository.Execute($"ls-tree --full-tree -r -z --name-only \"{branch}\" {path}")).Split('\0').Select(x => x.Trim('"')).Where(x => !string.IsNullOrWhiteSpace(x))); }
public IEnumerable <string> GetBranches() { try { return(System.Text.Encoding.UTF8.GetString(SharedRepository.Execute("branch --format=\"%(refname:short)\"")).Trim().Split().Where(x => !string.IsNullOrWhiteSpace(x))); } catch (Exception e) { Console.Error.WriteLine(e.GetBaseException().ToString()); return(new string[0]); } }