Inheritance: IGitItem
Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
 public static string GetFullPathFromGitItem(GitModule gitModule, GitItem gitItem)
 {
     return GetFullPathFromFilename(gitModule, gitItem.FileName);
 }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        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;
        }