internal static GitItem CreateGitItemFromString(GitModule aModule, string itemsString) { if ((itemsString == null) || (itemsString.Length <= MinimumStringLength)) return null; var guidStart = itemsString.IndexOf(' ', 7); var item = new GitItem(aModule) { Mode = itemsString.Substring(0, 6), ItemType = itemsString.Substring(7, guidStart - 7), Guid = itemsString.Substring(guidStart + 1, 40), Name = itemsString.Substring(guidStart + 42).Trim() }; item.FileName = item.Name; return item; }
public IList<GitItem> GetFileChanges(string file) { file = FixPath(file); var tree = RunGitCmd("whatchanged --all -- \"" + file + "\""); var itemsStrings = tree.Split('\n'); var items = new List<GitItem>(); GitItem item = null; foreach (var itemsString in itemsStrings) { if (itemsString.StartsWith("commit ")) { item = new GitItem(this) { CommitGuid = itemsString.Substring(7).Trim() }; items.Add(item); } else if (item == null) { continue; } else if (itemsString.StartsWith("Author: ")) { item.Author = itemsString.Substring(7).Trim(); } else if (itemsString.StartsWith("Date: ")) { item.Date = itemsString.Substring(7).Trim(); } else if (!itemsString.StartsWith(":") && !string.IsNullOrEmpty(itemsString)) { item.Name += itemsString.Trim() + Environment.NewLine; } else { if (itemsString.Length > 32) item.Guid = itemsString.Substring(26, 7); } } return items; }
public static string GetFullPathFromGitItem(GitModule gitModule, GitItem gitItem) { return GetFullPathFromFilename(gitModule, gitItem.FileName); }
public static List<IGitItem> GetTree(string id) { var tree = RunCachableCmd(Settings.GitCommand, "ls-tree -z \"" + id + "\""); var itemsStrings = tree.Split(new char[] { '\0', '\n' }); var items = new List<IGitItem>(); foreach (var itemsString in itemsStrings) { if (itemsString.Length <= 53) continue; var item = new GitItem { Mode = itemsString.Substring(0, 6) }; var guidStart = itemsString.IndexOf(' ', 7); item.ItemType = itemsString.Substring(7, guidStart - 7); item.Guid = itemsString.Substring(guidStart + 1, 40); item.Name = itemsString.Substring(guidStart + 42).Trim(); item.FileName = item.Name; items.Add(item); } return items; }
public static List<GitItem> GetConflictedFiles() { string[] unmerged = RunCmd(Settings.GitCommand, "ls-files --unmerged").Split('\n'); List<GitItem> unmergedFiles = new List<GitItem>(); string fileName = ""; foreach (string file in unmerged) { if (file.LastIndexOfAny(new char[] { ' ', '\t' }) > 0) { if (file.Substring(file.LastIndexOfAny(new char[] { ' ', '\t' }) + 1) != fileName) { fileName = file.Substring(file.LastIndexOfAny(new char[] { ' ', '\t' }) + 1); GitItem gitFile = new GitItem(); gitFile.FileName = fileName; unmergedFiles.Add(gitFile); } } } return unmergedFiles; }
public static List<IGitItem> GetTree(string id) { string tree = RunCachableCmd(Settings.GitCommand, "ls-tree \"" + id + "\""); string[] itemsStrings = tree.Split('\n'); List<IGitItem> items = new List<IGitItem>(); foreach (string itemsString in itemsStrings) { GitItem item = new GitItem(); if (itemsString.Length > 53) { item.Mode = itemsString.Substring(0, 6); int guidStart = itemsString.IndexOf(' ', 7); item.ItemType = itemsString.Substring(7, guidStart - 7); item.Guid = itemsString.Substring(guidStart + 1, 40); item.Name = itemsString.Substring(guidStart + 42).Trim(); item.FileName = item.Name; //if (item.ItemType == "tree") // item.SubItems = GetTree(item.Guid); items.Add(item); } } return items; }
private static string GetFileName(GitItem item) { var fileName = item.FileName; if (fileName.Contains("\\") && fileName.LastIndexOf("\\") < fileName.Length) fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1); if (fileName.Contains("/") && fileName.LastIndexOf("/") < fileName.Length) fileName = fileName.Substring(fileName.LastIndexOf('/') + 1); fileName = (Path.GetTempPath() + fileName).Replace(Settings.PathSeparatorWrong, Settings.PathSeparator); return fileName; }
public static List<GitItem> GetFileChanges(string file) { file = FixPath(file); string tree = RunCmd(Settings.GitDir + "git.cmd", "whatchanged --all -- \"" + file + "\""); string[] itemsStrings = tree.Split('\n'); List<GitItem> items = new List<GitItem>(); GitItem item = null; foreach (string itemsString in itemsStrings) { if (itemsString.StartsWith("commit ")) { item = new GitItem(); item.CommitGuid = itemsString.Substring(7).Trim(); items.Add(item); } else if (item == null) { continue; } else if (itemsString.StartsWith("Author: ")) { item.Author = itemsString.Substring(7).Trim(); } else if (itemsString.StartsWith("Date: ")) { item.Date = itemsString.Substring(7).Trim(); } else if (!itemsString.StartsWith(":") && !string.IsNullOrEmpty(itemsString)) { item.Name += itemsString.Trim() + "\n"; } else { if (item != null && itemsString.Length > 32) item.Guid = itemsString.Substring(26, 7); } } return items; }