Exemple #1
0
        private void PresentComparisonWindow(DiffBranchPair branchDiffPair, string leftFileMoniker, string rightFileMoniker)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            var    filename    = System.IO.Path.GetFileName(this.DocumentPath);
            string leftLabel   = $"{filename}@{branchDiffPair.BranchToDiffAgainst.Name}";
            string rightLabel  = $"{filename}@{branchDiffPair.WorkingBranch.Name}";
            string caption     = $"{System.IO.Path.GetFileName(leftFileMoniker)} Vs. {System.IO.Path.GetFileName(rightFileMoniker)}";
            string tooltip     = string.Empty;
            string inlineLabel = string.Empty;
            string roles       = string.Empty;
            __VSDIFFSERVICEOPTIONS diffServiceOptions = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;

            vsDifferenceService.OpenComparisonWindow2(leftFileMoniker, rightFileMoniker, caption, tooltip, leftLabel, rightLabel, inlineLabel, roles, (uint)diffServiceOptions);
            System.IO.File.Delete(leftFileMoniker);
        }
Exemple #2
0
        public HashSet <DiffResultItem> GetDiffedChangeSet(IGitRepository gitRepo, DiffBranchPair diffBranchPair)
        {
            var compareOptions = new CompareOptions
            {
                Algorithm         = DiffAlgorithm.Minimal,
                IncludeUnmodified = false,
            };

            // NB! Hard to make this "Diff" property and following code unit-testable...
            var branchDiffResult = gitRepo.Diff.Compare <TreeChanges>(
                diffBranchPair.BranchToDiffAgainst.Tip.Tree,
                diffBranchPair.WorkingBranch.Tip.Tree,
                compareOptions);

            // Can not include delete items, no way to show it in Solution Explorer
            // No special handling to Conflicts/Copied change kinds.
            var modifiedTreeChanges = branchDiffResult.Modified;
            var addedTreeChanges    = branchDiffResult.Added;
            var renamedTreeChanges  = branchDiffResult.Renamed;
            var allChanges          = modifiedTreeChanges
                                      .Concat(addedTreeChanges)
                                      .Concat(renamedTreeChanges);

            HashSet <DiffResultItem> changedPathsSet = new HashSet <DiffResultItem>();

            foreach (var treeEntryChange in allChanges)
            {
                // Issue with LibGit2Sharp: Paths returned are *-nix format, not windows directory format.
                var itemPathWithCorrectSeparator = treeEntryChange.Path.Replace("/", Constants.DirectorySeperator);
                var repoPathWithCorrectSeperator = gitRepo.WorkingDirectory.Replace("/", Constants.DirectorySeperator);

                var diffedObject = new DiffResultItem
                {
                    AbsoluteFilePath =
                        repoPathWithCorrectSeperator.ToLowerInvariant()
                        + itemPathWithCorrectSeparator.ToLowerInvariant(),

                    OldAbsoluteFilePath = treeEntryChange.Status == ChangeKind.Renamed ? treeEntryChange.OldPath.Replace("/", Constants.DirectorySeperator) : string.Empty,
                };

                changedPathsSet.Add(diffedObject);
            }

            return(changedPathsSet);
        }