internal void OpenFile(FileItem file)
        {
            var path     = file.Path;
            var fullPath = path;

            if (!fullPath.Contains(GitRoot))
            {
                fullPath = Path.Combine(GitRoot, fullPath);
            }

            if (file.IsModified)
            {
                var tempFile = Path.GetTempFileName();
                var oldFile  = new ShellCommand().ExecuteGit($"show {SelectedBranch.Name}:\"{path}\"", GitRoot);
                File.WriteAllLines(tempFile, oldFile, GetEncoding(fullPath));

                VisualStudioService.dte2.ExecuteCommand("Tools.DiffFiles", $"\"{tempFile}\" \"{fullPath}\"");
            }
            else
            {
                if (File.Exists(fullPath))
                {
                    VisualStudioService.dte2.ItemOperations.OpenFile(fullPath);
                }
                else
                {
                    MessageBox.Show($"This file does not exist on disk.\n{fullPath}");
                }
            }
        }
Esempio n. 2
0
        public List <Item> GetItems(string gitRoot, string branch)
        {
            if (branch.Contains("*"))
            {
                branch = branch.Replace("*", "").Trim();
            }
            var diff = new ShellCommand().ExecuteGit($"diff --name-status {branch}", gitRoot);

            var changes = new ShellCommand().ExecuteGit("status --porcelain -u", gitRoot);

            diff.AddRange(ConvertChanges(changes));

            return(MakeTreeFromPaths(diff));
        }
        private void ReloadBranches()
        {
            var selectedBranch = SelectedBranch?.Name;

            Branches.Clear();
            var branches = new ShellCommand().ExecuteGit("branch", GitRoot).Select(p => p.Trim());

            foreach (var branch in branches)
            {
                Branches.Add(new Branch {
                    Name = branch
                });
            }
            if (selectedBranch != null)
            {
                SelectedBranch = Branches.SingleOrDefault(p => p.Name == selectedBranch);
            }
            else
            {
                SelectedBranch = Branches.FirstOrDefault(p => p.Name == "master") ?? Branches.FirstOrDefault();
            }
        }