Ejemplo n.º 1
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
                return null;

            if (revisions[0].Guid == GitRevision.UncommittedWorkingDirGuid) //working dir changes
            {
                if (file.IsTracked)
                    return Settings.Module.GetCurrentChanges(file.Name, file.OldName, false, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);
                return FileReader.ReadFileContent(Settings.WorkingDir + file.Name, diffViewer.Encoding);
            }
            if (revisions[0].Guid == GitRevision.IndexGuid) //index
            {
                return Settings.Module.GetCurrentChanges(file.Name, file.OldName, true, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);
            }
            var secondRevision = revisions.Count == 2 ? revisions[1].Guid : revisions[0].Guid + "^";

            PatchApply.Patch patch = Settings.Module.GetSingleDiff(revisions[0].Guid, secondRevision, file.Name, file.OldName,
                                                    diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);

            if (patch == null)
                return null;

            if (file.IsSubmodule)
                return GitCommandHelpers.ProcessSubmodulePatch(patch.Text);

            return patch.Text;
        }
Ejemplo n.º 2
0
 public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
 {
     IList<GitRevision> revisions = grid.GetSelectedRevisions();
     string firstRevision = revisions.Count > 0 ? revisions[0].Guid : null;
     string secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;
     return GetSelectedPatch(diffViewer, firstRevision, secondRevision, file);
 }
Ejemplo n.º 3
0
        public static string GetSelectedPatch(this FileViewer diffViewer, string firstRevision, string secondRevision, GitItemStatus file)
        {
            //to simplify if-ology
            if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid)
            {
                string temp = firstRevision;
                firstRevision = secondRevision;
                secondRevision = temp;
            }

            if (IsItemUntracked(file, firstRevision, secondRevision))
            {
                var fullPath = Path.Combine(diffViewer.Module.WorkingDir, file.Name);
                if (Directory.Exists(fullPath) && GitModule.IsValidGitWorkingDir(fullPath))
                    return GitCommandHelpers.GetSubmoduleText(diffViewer.Module, file.Name.TrimEnd('/'), "");
                return FileReader.ReadFileContent(fullPath, diffViewer.Encoding);
            }

            if (file.IsSubmodule && file.SubmoduleStatus != null)
                return GitCommandHelpers.ProcessSubmoduleStatus(diffViewer.Module, file.SubmoduleStatus.Result);

            PatchApply.Patch patch = GetItemPatch(diffViewer.Module, file, firstRevision, secondRevision,
                diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);

            if (patch == null)
                return string.Empty;

            if (file.IsSubmodule)
                return GitCommandHelpers.ProcessSubmodulePatch(diffViewer.Module, patch);
            return patch.Text;
        }
Ejemplo n.º 4
0
        public static string GetSelectedPatch(this FileViewer diffViewer, IList<GitRevision> revisions, GitItemStatus file)
        {
            if (revisions.Count == 0)
                return null;

            string firstRevision = revisions[0].Guid;
            string secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

            return GetSelectedPatch(diffViewer, firstRevision, secondRevision, file);
        }
        private static string GetChangedFileText(GitModule module, GitItemStatus file)
        {
            var changes = module.GetCurrentChanges(file.Name, file.OldName, file.IsStaged, "-U1000000", module.FilesEncoding);

            if (changes != null)
                return changes.Text;

            var content = module.GetFileContents(file);

            if (content != null)
                return content;

            return File.ReadAllText(Path.Combine(module.WorkingDir, file.Name));
        }
Ejemplo n.º 6
0
 protected void ShowChanges(GitItemStatus item, bool staged)
 {
     if (item.Name.EndsWith(".png"))
     {
         SelectedDiff.ViewFile(item.Name);
     } else
     if (item.IsTracked)
     {
         SelectedDiff.ViewCurrentChanges(item.Name, "Patch", staged);
     }
     else
     {
         SelectedDiff.ViewFile(item.Name);
     }
 }
Ejemplo n.º 7
0
        protected void ShowChanges(GitItemStatus item, bool staged)
        {
            currentItem = item;
            currentItemStaged = staged;

            if (item == null)
                return;

            if (item.Name.EndsWith(".png"))
            {
                SelectedDiff.ViewFile(item.Name);
            } else
            if (item.IsTracked)
            {
                SelectedDiff.ViewCurrentChanges(item.Name, staged);
            }
            else
            {
                SelectedDiff.ViewFile(item.Name);
            }
        }
Ejemplo n.º 8
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
                return null;

            string firstRevision = revisions[0].Guid;
            var secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

            //to simplify if-ology
            if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid)
            {
                firstRevision = secondRevision;
                secondRevision = revisions[0].Guid;
            }

            if (IsItemUntracked(file, firstRevision, secondRevision))
            {
                var fullPath = Path.Combine(grid.Module.WorkingDir, file.Name);
                if (Directory.Exists(fullPath) && GitModule.ValidWorkingDir(fullPath))
                    return GitCommandHelpers.GetSubmoduleText(grid.Module, file.Name.TrimEnd('/'), "");
                return FileReader.ReadFileContent(fullPath, diffViewer.Encoding);
            }

            if (file.IsSubmodule && file.SubmoduleStatus != null)
                return GitCommandHelpers.ProcessSubmoduleStatus(grid.Module, file.SubmoduleStatus);

            PatchApply.Patch patch = GetItemPatch(grid.Module, file, firstRevision, secondRevision,
                diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);

            if (patch == null)
                return string.Empty;

            if (file.IsSubmodule)
                return GitCommandHelpers.ProcessSubmodulePatch(grid.Module, patch);
            return patch.Text;
        }
Ejemplo n.º 9
0
        private static int GitItemStatusFromStatusCharacter(bool fromDiff, string[] files, int n, string status, string fileName, char x, out GitItemStatus gitItemStatus)
        {
            gitItemStatus = null;

            if (x == ' ')
            {
                return(n);
            }

            gitItemStatus = new GitItemStatus();
            //Find renamed files...
            if (x == 'R')
            {
                if (fromDiff)
                {
                    gitItemStatus.OldName = fileName.Trim();
                    gitItemStatus.Name    = files[n + 1].Trim();
                }
                else
                {
                    gitItemStatus.Name    = fileName.Trim();
                    gitItemStatus.OldName = files[n + 1].Trim();
                }
                gitItemStatus.IsNew     = false;
                gitItemStatus.IsChanged = false;
                gitItemStatus.IsDeleted = false;
                gitItemStatus.IsRenamed = true;
                gitItemStatus.IsTracked = true;
                if (status.Length > 2)
                {
                    gitItemStatus.RenameCopyPercentage = status.Substring(1);
                }
                n++;
            }
            else
            //Find copied files...
            if (x == 'C')
            {
                if (fromDiff)
                {
                    gitItemStatus.OldName = fileName.Trim();
                    gitItemStatus.Name    = files[n + 1].Trim();
                }
                else
                {
                    gitItemStatus.Name    = fileName.Trim();
                    gitItemStatus.OldName = files[n + 1].Trim();
                }
                gitItemStatus.IsNew     = false;
                gitItemStatus.IsChanged = false;
                gitItemStatus.IsDeleted = false;
                gitItemStatus.IsCopied  = true;
                gitItemStatus.IsTracked = true;
                if (status.Length > 2)
                {
                    gitItemStatus.RenameCopyPercentage = status.Substring(1);
                }
                n++;
            }
            else
            {
                gitItemStatus.Name       = fileName.Trim();
                gitItemStatus.IsNew      = x == 'A' || x == '?' || x == '!';
                gitItemStatus.IsChanged  = x == 'M';
                gitItemStatus.IsDeleted  = x == 'D';
                gitItemStatus.IsRenamed  = false;
                gitItemStatus.IsTracked  = x != '?' && x != '!' && x != ' ' || !gitItemStatus.IsNew;
                gitItemStatus.IsConflict = x == 'U';
            }
            return(n);
        }
Ejemplo n.º 10
0
        public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 1 && (revisions[0].ParentGuids == null || revisions[0].ParentGuids.Length == 0))
            {
                diffViewer.ViewGitItem(file.Name, file.TreeGuid);
            }
            else
            diffViewer.ViewPatch(() =>
                                   {
                                       string selectedPatch = diffViewer.GetSelectedPatch(grid, file);

                                       return selectedPatch ?? defaultText;
                                   });
        }
Ejemplo n.º 11
0
        private void ShowChanges(GitItemStatus item, bool staged)
        {
            _currentItem = item;
            _currentItemStaged = staged;

            if (item == null)
                return;

            long length = GetItemLength(item.Name);
            if (length < 5 * 1024 * 1024) // 5Mb
                SetSelectedDiff(item, staged);
            else
            {
                SelectedDiff.Clear();
                SelectedDiff.Refresh();
                llShowPreview.Show();
            }

            _stageSelectedLinesToolStripMenuItem.Text = staged ? _unstageSelectedLines.Text : _stageSelectedLines.Text;
            _stageSelectedLinesToolStripMenuItem.Image = staged ? toolUnstageItem.Image : toolStageItem.Image;
            _stageSelectedLinesToolStripMenuItem.ShortcutKeyDisplayString =
                GetShortcutKeys((int) (staged ? Commands.UnStageSelectedFile : Commands.StageSelectedFile)).ToShortcutKeyDisplayString();
        }
Ejemplo n.º 12
0
        private void UpdateSelectedFileViewers()
        {
            var selectedRows = FileChanges.GetSelectedRevisions();

            if (selectedRows.Count == 0) return;

            IGitItem revision = selectedRows[0];

            var fileName = revision.Name;

            if (string.IsNullOrEmpty(fileName))
                fileName = FileName;

            Text = string.Format("File History - {0}", FileName);
            if (!fileName.Equals(FileName))
                Text = Text + string.Format(" ({0})", fileName);

            if (tabControl1.SelectedTab == BlameTab)
                Blame.LoadBlame(revision.Guid, fileName, FileChanges, BlameTab, Diff.Encoding);
            if (tabControl1.SelectedTab == ViewTab)
            {
                var scrollpos = View.ScrollPos;

                View.Encoding = Diff.Encoding;
                View.ViewGitItemRevision(fileName, revision.Guid);
                View.ScrollPos = scrollpos;
            }

            if (tabControl1.SelectedTab == DiffTab)
            {
                GitItemStatus file = new GitItemStatus();
                file.IsTracked = true;
                file.Name = fileName;
                Diff.ViewPatch(FileChanges, file, "You need to select at least one revision to view diff.");
            }
        }
Ejemplo n.º 13
0
        private void Unstage()
        {
            if (Staged.GitItemStatuses.Count() > 10 && Staged.SelectedItems.Count() == Staged.GitItemStatuses.Count())
            {
                UnstageAllToolStripMenuItemClick(null, null);
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            EnableStageButtons(false);
            try
            {
                var lastSelection = new List<GitItemStatus>();
                if (_currentFilesList != null)
                    lastSelection = _currentSelection;

                    toolStripProgressBar1.Visible = true;
                    toolStripProgressBar1.Maximum = Staged.SelectedItems.Count() * 2;
                    toolStripProgressBar1.Value = 0;
                    Staged.StoreNextIndexToSelect();

                    var files = new List<GitItemStatus>();
                    var allFiles = new List<GitItemStatus>();

                    foreach (var item in Staged.SelectedItems)
                    {
                        toolStripProgressBar1.Value = Math.Min(toolStripProgressBar1.Maximum - 1, toolStripProgressBar1.Value + 1);
                        if (!item.IsNew)
                        {
                            toolStripProgressBar1.Value = Math.Min(toolStripProgressBar1.Maximum - 1, toolStripProgressBar1.Value + 1);
                            Module.UnstageFileToRemove(item.Name);

                            if (item.IsRenamed)
                                Module.UnstageFileToRemove(item.OldName);
                        }
                        else
                        {
                            files.Add(item);
                        }
                        allFiles.Add(item);
                    }

                    Module.UnstageFiles(files);

                    _skipUpdate = true;
                    InitializedStaged();
                    var stagedFiles = Staged.GitItemStatuses.ToList();
                    var unStagedFiles = Unstaged.GitItemStatuses.ToList();
                    foreach (var item in allFiles)
                    {
                        var item1 = item;
                        if (stagedFiles.Exists(i => i.Name == item1.Name))
                            continue;

                        var item2 = item;
                        if (unStagedFiles.Exists(i => i.Name == item2.Name))
                            continue;

                        if (item.IsNew && !item.IsChanged && !item.IsDeleted)
                            item.IsTracked = false;
                        else
                            item.IsTracked = true;

                        if (item.IsRenamed)
                        {
                            var clone = new GitItemStatus
                            {
                                Name = item.OldName,
                                IsDeleted = true,
                                IsTracked = true,
                                IsStaged = false
                            };
                            unStagedFiles.Add(clone);

                            item.IsRenamed = false;
                            item.IsNew = true;
                            item.IsTracked = false;
                            item.OldName = string.Empty;
                        }

                        item.IsStaged = false;
                        unStagedFiles.Add(item);
                    }
                    Staged.GitItemStatuses = stagedFiles;
                    Unstaged.GitItemStatuses = unStagedFiles;
                    _skipUpdate = false;
                    Staged.SelectStoredNextIndex();

                    toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;

                toolStripProgressBar1.Visible = false;

                if (Staged.IsEmpty)
                {
                    _currentFilesList = Unstaged;
                    RestoreSelectedFiles(Unstaged.GitItemStatuses, Staged.GitItemStatuses, lastSelection);
                    Unstaged.Focus();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            EnableStageButtons(true);
            Cursor.Current = Cursors.Default;

            if (AppSettings.RevisionGraphShowWorkingDirChanges)
                UICommands.RepoChangedNotifier.Notify();
        }
Ejemplo n.º 14
0
        protected void ShowChanges(GitItemStatus item, bool staged)
        {
            _currentItem = item;
            _currentItemStaged = staged;

            if (item == null)
                return;

            if (item.Name.EndsWith(".png"))
            {
                SelectedDiff.ViewFile(item.Name);
            }
            else if (item.IsTracked)
            {
                SelectedDiff.ViewCurrentChanges(item.Name, item.OldName, staged);
            }
            else
            {
                SelectedDiff.ViewFile(item.Name);
            }

            _StageSelectedLinesToolStripMenuItem.Text = staged ? _unstageSelectedLines.Text : _stageSelectedLines.Text;
        }
Ejemplo n.º 15
0
 public static void ViewChanges(this FileViewer diffViewer, string revision, string parentRevision, GitItemStatus file, string defaultText)
 {
     if (parentRevision == null)
     {
         if (file.TreeGuid.IsNullOrEmpty())
             diffViewer.ViewGitItemRevision(file.Name, revision);
         else if (!file.IsSubmodule)
             diffViewer.ViewGitItem(file.Name, file.TreeGuid);
         else
             diffViewer.ViewText(file.Name,
                 LocalizationHelpers.GetSubmoduleText(diffViewer.Module, file.Name, file.TreeGuid));
     }
     else
     {
         diffViewer.ViewPatch(() =>
             {
                 string selectedPatch = diffViewer.GetSelectedPatch(revision, parentRevision, file);
                 return selectedPatch ?? defaultText;
             });
     }
 }
Ejemplo n.º 16
0
 public static bool IsItemUntracked(GitItemStatus file,
     string firstRevision, string secondRevision)
 {
     if (firstRevision == GitRevision.UnstagedGuid) //working directory changes
     {
         if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
             return !file.IsTracked;
     }
     return false;
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Parse the output from git-status --porcelain=2
        /// </summary>
        /// <param name="statusString">output from the git command</param>
        /// <returns>list with the parsed GitItemStatus</returns>
        private static IReadOnlyList <GitItemStatus> GetAllChangedFilesFromString_v2(string statusString)
        {
            var diffFiles = new List <GitItemStatus>();

            if (string.IsNullOrEmpty(statusString))
            {
                return(diffFiles);
            }

            string trimmedStatus = RemoveWarnings(statusString);

            // Split all files on '\0'
            var files = trimmedStatus.Split(new[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);

            for (int n = 0; n < files.Length; n++)
            {
                string line      = files[n];
                char   entryType = line[0];

                if (entryType == '?' || entryType == '!')
                {
                    Debug.Assert(line.Length > 2 && line[1] == ' ', "Cannot parse for untracked:" + line);
                    string fileName = line.Substring(2);
                    UpdateItemStatus(entryType, false, "N...", fileName, null, null);
                }
                else if (entryType == '1' || entryType == '2' || entryType == 'u')
                {
                    // Parse from git-status documentation, assuming SHA-1 is used
                    // Ignore octal and treeGuid
                    // 1 XY subm <mH> <mI> <mW> <hH> <hI> <path>
                    // renamed:
                    // 2 XY subm <mH> <mI> <mW> <hH> <hI> <X><score> <path><sep><origPath>
                    // worktree (merge conflicts)
                    // u XY subm <m1> <m2> <m3> <mW> <h1> <h2> <h3> <path>

                    char   x = line[2];
                    char   y = line[3];
                    string fileName;
                    string oldFileName   = null;
                    string renamePercent = null;
                    string subm          = line.Substring(5, 4);

                    if (entryType == '1')
                    {
                        Debug.Assert(line.Length > 113 && line[1] == ' ', "Cannot parse line:" + line);
                        fileName = line.Substring(113);
                    }
                    else if (entryType == '2')
                    {
                        Debug.Assert(line.Length > 2 && n + 1 < files.Length, "Cannot parse renamed:" + line);

                        // Find renamed files...
                        string[] renames = line.Substring(114).Split(new[] { ' ' }, 2);
                        renamePercent = renames[0];
                        fileName      = renames[1];
                        oldFileName   = files[++n];
                    }
                    else if (entryType == 'u')
                    {
                        Debug.Assert(line.Length > 161, "Cannot parse unmerged:" + line);
                        fileName = line.Substring(161);
                    }
                    else
                    {
                        // illegal
                        continue;
                    }

                    UpdateItemStatus(x, true, subm, fileName, oldFileName, renamePercent);
                    UpdateItemStatus(y, false, subm, fileName, oldFileName, renamePercent);
                }
            }

            return(diffFiles);

            void UpdateItemStatus(char x, bool isIndex, string subm, string fileName, string oldFileName, string renamePercent)
            {
                if (x == '.')
                {
                    return;
                }

                var           staged        = isIndex ? StagedStatus.Index : StagedStatus.WorkTree;
                GitItemStatus gitItemStatus = GitItemStatusFromStatusCharacter(staged, fileName, x);

                if (oldFileName != null)
                {
                    gitItemStatus.OldName = oldFileName;
                }

                if (renamePercent != null)
                {
                    gitItemStatus.RenameCopyPercentage = renamePercent;
                }

                if (subm[0] == 'S')
                {
                    gitItemStatus.IsSubmodule = true;

                    if (!isIndex)
                    {
                        // Slight modification on how the following flags are used
                        // Changed commit
                        gitItemStatus.IsChanged = subm[1] == 'C';
                        gitItemStatus.IsDirty   = subm[2] == 'M' || subm[3] == 'U';
                    }
                }

                diffFiles.Add(gitItemStatus);
            }
        }
Ejemplo n.º 18
0
        /*
         *     source: https://git-scm.com/docs/git-status
         */
        public static List <GitItemStatus> GetAllChangedFilesFromString(GitModule module, string statusString, bool fromDiff = false)
        {
            var diffFiles = new List <GitItemStatus>();

            if (string.IsNullOrEmpty(statusString))
            {
                return(diffFiles);
            }

            /*The status string can show warnings. This is a text block at the start or at the beginning
             * of the file status. Strip it. Example:
             *  warning: LF will be replaced by CRLF in CustomDictionary.xml.
             *  The file will have its original line endings in your working directory.
             *  warning: LF will be replaced by CRLF in FxCop.targets.
             *  The file will have its original line endings in your working directory.*/
            var    nl             = new[] { '\n', '\r' };
            string trimmedStatus  = statusString.Trim(nl);
            int    lastNewLinePos = trimmedStatus.LastIndexOfAny(nl);

            if (lastNewLinePos > 0)
            {
                int ind = trimmedStatus.LastIndexOf('\0');
                if (ind < lastNewLinePos) //Warning at end
                {
                    lastNewLinePos = trimmedStatus.IndexOfAny(nl, ind >= 0 ? ind : 0);
                    trimmedStatus  = trimmedStatus.Substring(0, lastNewLinePos).Trim(nl);
                }
                else                                              //Warning at beginning
                {
                    trimmedStatus = trimmedStatus.Substring(lastNewLinePos).Trim(nl);
                }
            }

            // Doesn't work with removed submodules
            IList <string> Submodules = module.GetSubmodulesLocalPaths();

            //Split all files on '\0' (WE NEED ALL COMMANDS TO BE RUN WITH -z! THIS IS ALSO IMPORTANT FOR ENCODING ISSUES!)
            var files = trimmedStatus.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);

            for (int n = 0; n < files.Length; n++)
            {
                if (string.IsNullOrEmpty(files[n]))
                {
                    continue;
                }

                int splitIndex = files[n].IndexOfAny(new char[] { '\0', '\t', ' ' }, 1);

                string status   = string.Empty;
                string fileName = string.Empty;

                if (splitIndex < 0)
                {
                    status   = files[n];
                    fileName = files[n + 1];
                    n++;
                }
                else
                {
                    status   = files[n].Substring(0, splitIndex);
                    fileName = files[n].Substring(splitIndex);
                }

                char x = status[0];
                char y = status.Length > 1 ? status[1] : ' ';

                if (x != '?' && x != '!' && x != ' ')
                {
                    GitItemStatus gitItemStatusX = null;
                    if (x == 'R' || x == 'C') // Find renamed files...
                    {
                        string nextfile = n + 1 < files.Length ? files[n + 1] : "";
                        gitItemStatusX = GitItemStatusFromCopyRename(fromDiff, nextfile, fileName, x, status);
                        n++;
                    }
                    else
                    {
                        gitItemStatusX = GitItemStatusFromStatusCharacter(fileName, x);
                    }

                    gitItemStatusX.IsStaged = true;
                    if (Submodules.Contains(gitItemStatusX.Name))
                    {
                        gitItemStatusX.IsSubmodule = true;
                    }
                    diffFiles.Add(gitItemStatusX);
                }

                if (fromDiff || y == ' ')
                {
                    continue;
                }
                GitItemStatus gitItemStatusY;
                if (y == 'R' || y == 'C') // Find renamed files...
                {
                    string nextfile = n + 1 < files.Length ? files[n + 1] : "";
                    gitItemStatusY = GitItemStatusFromCopyRename(false, nextfile, fileName, y, status);
                    n++;
                }
                else
                {
                    gitItemStatusY = GitItemStatusFromStatusCharacter(fileName, y);
                }
                gitItemStatusY.IsStaged = false;
                if (Submodules.Contains(gitItemStatusY.Name))
                {
                    gitItemStatusY.IsSubmodule = true;
                }
                diffFiles.Add(gitItemStatusY);
            }

            return(diffFiles);
        }
Ejemplo n.º 19
0
 public static void ViewChanges(this FileViewer diffViewer, IList<GitRevision> revisions, GitItemStatus file, string defaultText)
 {
     var firstRevision = revisions.Count > 0 ? revisions[0] : null;
     string firstRevisionGuid = firstRevision == null ? null : firstRevision.Guid;
     string parentRevisionGuid = revisions.Count == 2 ? revisions[1].Guid : null;
     if (parentRevisionGuid == null && firstRevision != null && firstRevision.ParentGuids != null && firstRevision.ParentGuids.Length > 0)
         parentRevisionGuid = firstRevision.ParentGuids[0];
     ViewChanges(diffViewer, firstRevisionGuid, parentRevisionGuid, file, defaultText);
 }
Ejemplo n.º 20
0
        public static List<GitItemStatus> GitStatus(bool untracked)
        {
            string status;
            if (untracked)
                status = RunCmd(Settings.GitCommand, "status --untracked=all");
            else
                status = RunCmd(Settings.GitCommand, "status");

            string[] statusStrings = status.Split('\n');

            List<GitItemStatus> gitItemStatusList = new List<GitItemStatus>();

            foreach (string statusString in statusStrings)
            {
                if (statusString.StartsWith("#\tnew file:"))
                {
                    GitItemStatus itemStatus = new GitItemStatus();
                    itemStatus.IsNew = true;
                    itemStatus.IsTracked = true;
                    itemStatus.Name = statusString.Substring(statusString.LastIndexOf(':') + 1).Trim();
                    gitItemStatusList.Add(itemStatus);
                }
                else
                    if (statusString.StartsWith("#\tdeleted:"))
                    {
                        GitItemStatus itemStatus = new GitItemStatus();
                        itemStatus.IsDeleted = true;
                        itemStatus.IsTracked = true;
                        itemStatus.Name = statusString.Substring(statusString.LastIndexOf(':') + 1).Trim();
                        gitItemStatusList.Add(itemStatus);
                    }
                    else
                        if (statusString.StartsWith("#\tmodified:"))
                        {
                            GitItemStatus itemStatus = new GitItemStatus();
                            itemStatus.IsChanged = true;
                            itemStatus.IsTracked = true;
                            itemStatus.Name = statusString.Substring(statusString.LastIndexOf(':') + 1).Trim();
                            gitItemStatusList.Add(itemStatus);
                        }
                        else
                            if (statusString.StartsWith("#\t"))
                            {
                                GitItemStatus itemStatus = new GitItemStatus();
                                itemStatus.IsNew = true;
                                itemStatus.Name = statusString.Substring(2).Trim();
                                gitItemStatusList.Add(itemStatus);
                            }
            }

            return gitItemStatusList;
        }
Ejemplo n.º 21
0
        private static PatchApply.Patch GetItemPatch(GitModule module, GitItemStatus file,
            string firstRevision, string secondRevision, string diffArgs, Encoding encoding)
        {
            bool cacheResult = true;
            if (GitRevision.IsArtificial(firstRevision))
            {
                bool staged = firstRevision == GitRevision.IndexGuid;
                if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                {
                    return module.GetCurrentChanges(file.Name, file.OldName, staged,
                            diffArgs, encoding);
                }

                cacheResult = false;
                firstRevision = secondRevision;
                secondRevision = string.Empty;
                if (staged)
                    diffArgs = string.Join(" ", diffArgs, "--cached");
            }
            else if (secondRevision == null)
                secondRevision = firstRevision + "^";

            return module.GetSingleDiff(firstRevision, secondRevision, file.Name, file.OldName,
                    diffArgs, encoding, cacheResult);
        }
Ejemplo n.º 22
0
        public static List<GitItemStatus> GetAllChangedFilesFromString(string status)
        {
            string[] statusStrings = status.Split('\n');

            List<GitItemStatus> gitItemStatusList = new List<GitItemStatus>();

            GitItemStatus itemStatus = null;
            foreach (string statusString in statusStrings)
            {
                if (string.IsNullOrEmpty(statusString.Trim()) || statusString.Length < 2)
                    continue;

                if (!(itemStatus != null && itemStatus.Name == statusString.Substring(1).Trim()))
                {
                    itemStatus = new GitItemStatus();
                    itemStatus.Name = statusString.Substring(1).Trim();
                    gitItemStatusList.Add(itemStatus);
                }

                itemStatus.IsNew = itemStatus.IsNew || statusString[0] == '?';
                itemStatus.IsChanged = itemStatus.IsChanged || statusString[0] == 'C';
                itemStatus.IsDeleted = itemStatus.IsDeleted || statusString[0] == 'R';
                itemStatus.IsTracked = itemStatus.IsTracked || statusString[0] != '?';
            }

            return gitItemStatusList;
        }
Ejemplo n.º 23
0
 public static string GetFullPathFromGitItemStatus(GitModule gitModule, GitItemStatus gitItemStatus)
 {
     return GetFullPathFromFilename(gitModule, gitItemStatus.Name);
 }
Ejemplo n.º 24
0
        public static List<GitItemStatus> GetDiffFiles(string from, string to)
        {
            string result = RunCachableCmd(Settings.GitCommand, "diff --name-status \"" + to + "\" \"" + from + "\"");

            string[] files = result.Split('\n');

            List<GitItemStatus> retVal = new List<GitItemStatus>();
            foreach (string s in files)
            {
                if (!string.IsNullOrEmpty(s))
                {
                    GitItemStatus gitItemStatus = new GitItemStatus();
                    gitItemStatus.Name = s.Substring(1).Trim();

                    gitItemStatus.IsNew = s[0] == 'A';
                    gitItemStatus.IsChanged = s[0] == 'M';
                    gitItemStatus.IsDeleted = s[0] == 'D';
                    gitItemStatus.IsTracked = true;
                    retVal.Add(gitItemStatus);
                }
            }

            return retVal;
        }
Ejemplo n.º 25
0
        private void UnstageFilesClick(object sender, EventArgs e)
        {
            EnableStageButtons(false);
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (Staged.GitItemStatuses.Count > 10 && Staged.SelectedItems.Count == Staged.GitItemStatuses.Count)
                {
                    Loading.Visible = true;
                    GitCommandHelpers.ResetMixed("HEAD");
                    Initialize();
                }
                else
                {
                    toolStripProgressBar1.Visible = true;
                    toolStripProgressBar1.Maximum = Staged.SelectedItems.Count * 2;
                    toolStripProgressBar1.Value = 0;

                    var files = new List<GitItemStatus>();
                    var allFiles = new List<GitItemStatus>();

                    foreach (var item in Staged.SelectedItems)
                    {
                        toolStripProgressBar1.Value = Math.Min(toolStripProgressBar1.Maximum - 1, toolStripProgressBar1.Value + 1);
                        if (!item.IsNew)
                        {
                            toolStripProgressBar1.Value = Math.Min(toolStripProgressBar1.Maximum - 1, toolStripProgressBar1.Value + 1);
                            GitCommandHelpers.UnstageFileToRemove(item.Name);

                            if (item.IsRenamed)
                                GitCommandHelpers.UnstageFileToRemove(item.OldName);
                        }
                        else
                        {
                            files.Add(item);
                        }
                        allFiles.Add(item);
                    }

                    GitCommandHelpers.UnstageFiles(files);

                    InitializedStaged();
                    var stagedFiles = (List<GitItemStatus>)Staged.GitItemStatuses;
                    var unStagedFiles = (List<GitItemStatus>)Unstaged.GitItemStatuses;
                    Unstaged.GitItemStatuses = null;
                    foreach (var item in allFiles)
                    {
                        var item1 = item;
                        if (stagedFiles.Exists(i => i.Name == item1.Name))
                            continue;

                        var item2 = item;
                        if (unStagedFiles.Exists(i => i.Name == item2.Name))
                            continue;

                        if (item.IsNew && !item.IsChanged && !item.IsDeleted)
                            item.IsTracked = false;
                        else
                            item.IsTracked = true;

                        if (item.IsRenamed)
                        {
                            GitItemStatus clone = new GitItemStatus();
                            clone.Name = item.OldName;
                            clone.IsDeleted = true;
                            clone.IsTracked = true;
                            clone.IsStaged = false;
                            unStagedFiles.Add(clone);

                            item.IsRenamed = false;
                            item.IsNew = true;
                            item.IsTracked = false;
                            item.OldName = string.Empty;
                        }

                        item.IsStaged = false;
                        unStagedFiles.Add(item);
                    }
                    Staged.GitItemStatuses = stagedFiles;
                    Unstaged.GitItemStatuses = unStagedFiles;

                    toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
                }
                toolStripProgressBar1.Visible = false;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            EnableStageButtons(true);
            Cursor.Current = Cursors.Default;

            if (Settings.RevisionGraphShowWorkingDirChanges)
                NeedRefresh = true;
        }
Ejemplo n.º 26
0
        public static List<GitItemStatus> GetModifiedFiles()
        {
            string status = RunCmd(Settings.GitCommand, "ls-files --modified --exclude-standard");

            string[] statusStrings = status.Split('\n');

            List<GitItemStatus> gitItemStatusList = new List<GitItemStatus>();

            foreach (string statusString in statusStrings)
            {
                if (string.IsNullOrEmpty(statusString.Trim()))
                    continue;
                GitItemStatus itemStatus = new GitItemStatus();
                itemStatus.IsNew = false;
                itemStatus.IsChanged = true;
                itemStatus.IsDeleted = false;
                itemStatus.IsTracked = true;
                itemStatus.Name = statusString.Trim();
                gitItemStatusList.Add(itemStatus);
            }

            return gitItemStatusList;
        }
Ejemplo n.º 27
0
        private void UpdateSelectedFileViewers()
        {
            var selectedRows = FileChanges.GetSelectedRevisions();

            if (selectedRows.Count == 0) return;

            GitRevision revision = selectedRows[0];
            var children = FileChanges.GetRevisionChildren(revision.Guid);

            var fileName = revision.Name;

            if (string.IsNullOrEmpty(fileName))
                fileName = FileName;

            SetTitle(fileName);

            if (tabControl1.SelectedTab == BlameTab)
                Blame.LoadBlame(revision, children, fileName, FileChanges, BlameTab, Diff.Encoding);
            else if (tabControl1.SelectedTab == ViewTab)
            {
                var scrollpos = View.ScrollPos;

                View.Encoding = Diff.Encoding;
                View.ViewGitItemRevision(fileName, revision.Guid);
                View.ScrollPos = scrollpos;
            }
            else if (tabControl1.SelectedTab == DiffTab)
            {
                GitItemStatus file = new GitItemStatus();
                file.IsTracked = true;
                file.Name = fileName;
                file.IsSubmodule = GitModule.IsValidGitWorkingDir(Path.Combine(Module.WorkingDir, fileName));
                Diff.ViewChanges(FileChanges.GetSelectedRevisions(), file, "You need to select at least one revision to view diff.");
            }
        }
Ejemplo n.º 28
0
        private static int GitItemStatusFromStatusCharacter(bool fromDiff, string[] files, int n, string status, string fileName, char x, out GitItemStatus gitItemStatus)
        {
            gitItemStatus = null;

            if (x == ' ')
                return n;

            gitItemStatus = new GitItemStatus();
            //Find renamed files...
            if (x == 'R')
            {
                if (fromDiff)
                {
                    gitItemStatus.OldName = fileName.Trim();
                    gitItemStatus.Name = files[n + 1].Trim();
                }
                else
                {
                    gitItemStatus.Name = fileName.Trim();
                    gitItemStatus.OldName = files[n + 1].Trim();
                }
                gitItemStatus.IsNew = false;
                gitItemStatus.IsChanged = false;
                gitItemStatus.IsDeleted = false;
                gitItemStatus.IsRenamed = true;
                gitItemStatus.IsTracked = true;
                if (status.Length > 2)
                    gitItemStatus.RenameCopyPercentage = status.Substring(1);
                n++;
            }
            else
                //Find copied files...
                if (x == 'C')
                {
                    if (fromDiff)
                    {
                        gitItemStatus.OldName = fileName.Trim();
                        gitItemStatus.Name = files[n + 1].Trim();
                    }
                    else
                    {
                        gitItemStatus.Name = fileName.Trim();
                        gitItemStatus.OldName = files[n + 1].Trim();
                    }
                    gitItemStatus.IsNew = false;
                    gitItemStatus.IsChanged = false;
                    gitItemStatus.IsDeleted = false;
                    gitItemStatus.IsCopied = true;
                    gitItemStatus.IsTracked = true;
                    if (status.Length > 2)
                        gitItemStatus.RenameCopyPercentage = status.Substring(1);
                    n++;
                }
                else
                {
                    gitItemStatus.Name = fileName.Trim();
                    gitItemStatus.IsNew = x == 'A' || x == '?' || x == '!';
                    gitItemStatus.IsChanged = x == 'M';
                    gitItemStatus.IsDeleted = x == 'D';
                    gitItemStatus.IsRenamed = false;
                    gitItemStatus.IsTracked = x != '?' && x != '!' && x != ' ' || !gitItemStatus.IsNew;
                    gitItemStatus.IsConflict = x == 'U';
                }
            return n;
        }
Ejemplo n.º 29
0
 private void SetSelectedDiff(GitItemStatus item, bool staged)
 {
     if (item.Name.EndsWith(".png"))
     {
         SelectedDiff.ViewFile(item.Name);
     }
     else if (item.IsTracked)
     {
         SelectedDiff.ViewCurrentChanges(item, staged);
     }
     else
     {
         SelectedDiff.ViewFile(item.Name);
     }
 }
Ejemplo n.º 30
0
        public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 1 && (revisions[0].ParentGuids == null || revisions[0].ParentGuids.Length == 0))
            {
                if (file.TreeGuid.IsNullOrEmpty())
                    diffViewer.ViewGitItemRevision(file.Name, revisions[0].Guid);
                else if (!file.IsSubmodule)
                    diffViewer.ViewGitItem(file.Name, file.TreeGuid);
                else
                    diffViewer.ViewText(file.Name,
                        GitCommandHelpers.GetSubmoduleText(grid.Module, file.Name, file.TreeGuid));
            }
            else
            {
                diffViewer.ViewPatch(() =>
                                       {
                                           string selectedPatch = diffViewer.GetSelectedPatch(grid, file);
                                           return selectedPatch ?? defaultText;
                                       });
            }
        }
Ejemplo n.º 31
0
        private void UnstageFilesClick(object sender, EventArgs e)
        {
            EnableStageButtons(false);
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (Staged.GitItemStatuses.Count() > 10 && Staged.SelectedItems.Count() == Staged.GitItemStatuses.Count())
                {
                    Loading.Visible = true;
                    LoadingStaged.Visible = true;
                    Commit.Enabled = false;
                    CommitAndPush.Enabled = false;
                    Amend.Enabled = false;
                    Reset.Enabled = false;

                    Module.ResetMixed("HEAD");
                    Initialize();
                }
                else
                {
                    toolStripProgressBar1.Visible = true;
                    toolStripProgressBar1.Maximum = Staged.SelectedItems.Count() * 2;
                    toolStripProgressBar1.Value = 0;
                    Staged.StoreNextIndexToSelect();

                    var files = new List<GitItemStatus>();
                    var allFiles = new List<GitItemStatus>();

                    foreach (var item in Staged.SelectedItems)
                    {
                        toolStripProgressBar1.Value = Math.Min(toolStripProgressBar1.Maximum - 1, toolStripProgressBar1.Value + 1);
                        if (!item.IsNew)
                        {
                            toolStripProgressBar1.Value = Math.Min(toolStripProgressBar1.Maximum - 1, toolStripProgressBar1.Value + 1);
                            Module.UnstageFileToRemove(item.Name);

                            if (item.IsRenamed)
                                Module.UnstageFileToRemove(item.OldName);
                        }
                        else
                        {
                            files.Add(item);
                        }
                        allFiles.Add(item);
                    }

                    Module.UnstageFiles(files);

                    LockedFilesSelectionChanging(() =>
                        {
                            InitializedStaged();
                            var stagedFiles = Staged.GitItemStatuses.ToList();
                            var unStagedFiles = Unstaged.GitItemStatuses.ToList();
                            Unstaged.GitItemStatuses = null;
                            foreach (var item in allFiles)
                            {
                                var item1 = item;
                                if (stagedFiles.Exists(i => i.Name == item1.Name))
                                    continue;

                                var item2 = item;
                                if (unStagedFiles.Exists(i => i.Name == item2.Name))
                                    continue;

                                if (item.IsNew && !item.IsChanged && !item.IsDeleted)
                                    item.IsTracked = false;
                                else
                                    item.IsTracked = true;

                                if (item.IsRenamed)
                                {
                                    var clone = new GitItemStatus
                                    {
                                        Name = item.OldName,
                                        IsDeleted = true,
                                        IsTracked = true,
                                        IsStaged = false
                                    };
                                    unStagedFiles.Add(clone);

                                    item.IsRenamed = false;
                                    item.IsNew = true;
                                    item.IsTracked = false;
                                    item.OldName = string.Empty;
                                }

                                item.IsStaged = false;
                                unStagedFiles.Add(item);
                            }
                            Staged.GitItemStatuses = stagedFiles;
                            Unstaged.GitItemStatuses = unStagedFiles;
                        });
                    Staged.SelectStoredNextIndex();

                    toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
                }
                toolStripProgressBar1.Visible = false;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            EnableStageButtons(true);
            Cursor.Current = Cursors.Default;

            if (Settings.RevisionGraphShowWorkingDirChanges)
                UICommands.RepoChangedNotifier.Notify();
        }
Ejemplo n.º 32
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
                return null;

            string firstRevision = revisions[0].Guid;
            var secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

            //to simplify if-ology
            if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid)
            {
                firstRevision = secondRevision;
                secondRevision = revisions[0].Guid;
            }

            string extraDiffArgs = null;

            if (firstRevision == GitRevision.UnstagedGuid) //working dir changes
            {
                if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                {
                    if (file.IsTracked)
                    {
                        return ProcessDiffText(grid.Module, grid.Module.GetCurrentChanges(file.Name, file.OldName, false,
                            diffViewer.GetExtraDiffArguments(), diffViewer.Encoding), file.IsSubmodule);
                    }

                    var fullPath = Path.Combine(grid.Module.WorkingDir, file.Name);
                    if (Directory.Exists(fullPath) && GitModule.ValidWorkingDir(fullPath))
                        return GitCommandHelpers.GetSubmoduleText(grid.Module, file.Name.TrimEnd('/'), "");
                    return FileReader.ReadFileContent(fullPath, diffViewer.Encoding);
                }
                else
                {
                    firstRevision = secondRevision;
                    secondRevision = string.Empty;
                }
            }
            if (firstRevision == GitRevision.IndexGuid) //index
            {
                if (secondRevision == null)
                {
                    return ProcessDiffText(grid.Module, grid.Module.GetCurrentChanges(file.Name, file.OldName, true,
                        diffViewer.GetExtraDiffArguments(), diffViewer.Encoding), file.IsSubmodule);
                }

                //rev1 vs index
                firstRevision = secondRevision;
                secondRevision = string.Empty;
                extraDiffArgs = string.Join(" ", extraDiffArgs, "--cached");
            }

            Debug.Assert(!GitRevision.IsArtificial(firstRevision), string.Join(" ", firstRevision,secondRevision));

            if (secondRevision == null)
                secondRevision = firstRevision + "^";

            PatchApply.Patch patch = grid.Module.GetSingleDiff(firstRevision, secondRevision, file.Name, file.OldName,
                                                    string.Join(" ", diffViewer.GetExtraDiffArguments(), extraDiffArgs), diffViewer.Encoding);

            if (patch == null)
                return string.Empty;

            return ProcessDiffText(grid.Module, patch.Text, file.IsSubmodule);
        }
Ejemplo n.º 33
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
                return null;

            string firstRevision = revisions[0].Guid;
            var secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

            //to simplify if-ology
            if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UncommittedWorkingDirGuid)
            {
                firstRevision = secondRevision;
                secondRevision = revisions[0].Guid;
            }

            string extraDiffArgs = null;

            if (firstRevision == GitRevision.UncommittedWorkingDirGuid) //working dir changes
            {
                if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                {
                    if (file.IsTracked)
                        return Settings.Module.GetCurrentChanges(file.Name, file.OldName, false, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);
                    return FileReader.ReadFileContent(Settings.WorkingDir + file.Name, diffViewer.Encoding);
                }
                else
                {
                    firstRevision = secondRevision;
                    secondRevision = string.Empty;
                }
            }
            if (firstRevision == GitRevision.IndexGuid) //index
            {
                if (secondRevision == null)
                    return Settings.Module.GetCurrentChanges(file.Name, file.OldName, true, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);
                else //rev1 vs index
                {
                    firstRevision = secondRevision;
                    secondRevision = string.Empty;
                    extraDiffArgs = extraDiffArgs.Join(" ", "--cached");
                }
            }

            Debug.Assert(!GitRevision.IsArtificial(firstRevision), firstRevision.Join(" ", secondRevision));

            if (secondRevision == null)
                secondRevision = firstRevision + "^";

            PatchApply.Patch patch = Settings.Module.GetSingleDiff(firstRevision, secondRevision, file.Name, file.OldName,
                                                    diffViewer.GetExtraDiffArguments().Join(" ", extraDiffArgs), diffViewer.Encoding);

            if (patch == null)
                return string.Empty;

            if (file.IsSubmodule)
                return GitCommandHelpers.ProcessSubmodulePatch(patch.Text);

            return patch.Text;
        }
Ejemplo n.º 34
0
        /*
         *     source: C:\Program Files\msysgit\doc\git\html\git-status.html
         */
        public static List <GitItemStatus> GetAllChangedFilesFromString(string statusString, bool fromDiff /*old name and new name are switched.. %^&#^% */)
        {
            var diffFiles = new List <GitItemStatus>();

            if (string.IsNullOrEmpty(statusString))
            {
                return(diffFiles);
            }

            /*The status string can show warnings. This is a text block at the start or at the beginning
             * of the file status. Strip it. Example:
             *  warning: LF will be replaced by CRLF in CustomDictionary.xml.
             *  The file will have its original line endings in your working directory.
             *  warning: LF will be replaced by CRLF in FxCop.targets.
             *  The file will have its original line endings in your working directory.*/
            var    nl             = new char[] { '\n', '\r' };
            string trimmedStatus  = statusString.Trim(nl);
            int    lastNewLinePos = trimmedStatus.LastIndexOfAny(nl);

            if (lastNewLinePos > 0)
            {
                int ind = trimmedStatus.LastIndexOf('\0');
                if (ind < lastNewLinePos) //Warning at end
                {
                    lastNewLinePos = trimmedStatus.IndexOfAny(nl, ind >= 0 ? ind: 0);
                    trimmedStatus  = trimmedStatus.Substring(0, lastNewLinePos).Trim(nl);
                }
                else                                              //Warning at beginning
                {
                    trimmedStatus = trimmedStatus.Substring(lastNewLinePos).Trim(nl);
                }
            }

            // Doesn't work with removed submodules
            IList <string> Submodules = Settings.Module.GetSubmodulesNames();

            //Split all files on '\0' (WE NEED ALL COMMANDS TO BE RUN WITH -z! THIS IS ALSO IMPORTANT FOR ENCODING ISSUES!)
            var files = trimmedStatus.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);

            for (int n = 0; n < files.Length; n++)
            {
                if (string.IsNullOrEmpty(files[n]))
                {
                    continue;
                }

                int splitIndex = files[n].IndexOfAny(new char[] { '\0', '\t', ' ' }, 1);

                string status   = string.Empty;
                string fileName = string.Empty;

                if (splitIndex < 0)
                {
                    status   = files[n];
                    fileName = files[n + 1];
                    n++;
                }
                else
                {
                    status   = files[n].Substring(0, splitIndex);
                    fileName = files[n].Substring(splitIndex);
                }

                char x = status[0];
                char y = status.Length > 1 ? status[1] : ' ';

                GitItemStatus gitItemStatus = null;

                if (x != '?' && x != '!')
                {
                    n = GitItemStatusFromStatusCharacter(fromDiff, files, n, status, fileName, x, out gitItemStatus);
                    if (gitItemStatus != null)
                    {
                        gitItemStatus.IsStaged = true;
                        diffFiles.Add(gitItemStatus);
                    }
                }

                if (!fromDiff)
                {
                    n = GitItemStatusFromStatusCharacter(fromDiff, files, n, status, fileName, y, out gitItemStatus);
                    if (gitItemStatus != null)
                    {
                        gitItemStatus.IsStaged = false;
                        diffFiles.Add(gitItemStatus);
                    }
                }

                if (gitItemStatus != null && Submodules.Contains(gitItemStatus.Name))
                {
                    gitItemStatus.IsSubmodule = true;
                }
            }

            return(diffFiles);
        }