コード例 #1
0
        //TODO Do a command pattern so we can plugin any diff tool
        internal async Task RunDiffCommand(DiffFileInfo fileInfo)
        {
            if (GitSccOptions.Current.DiffTool == DiffTools.VisualStudio)
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                var diffService = (IVsDifferenceService)GetService(typeof(SVsDifferenceService));
                if (diffService != null)
                {
                    string rightLabel = fileInfo.ModifiedFilePath;

                    string tempPrefix = Path.GetRandomFileName().Substring(0, 5);
                    string caption    = string.Format("{0}_{1} vs. {1}", tempPrefix, fileInfo.ActualFilename);
                    var    leftLabel  = string.Format("{0}@{1}", fileInfo.ActualFilename, fileInfo.LastRevision);

                    __VSDIFFSERVICEOPTIONS grfDiffOptions = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;
                    diffService.OpenComparisonWindow2(fileInfo.UnmodifiedFilePath, fileInfo.ModifiedFilePath, caption, null,
                                                      leftLabel, rightLabel, null, null, (uint)grfDiffOptions);

                    // Since the file is marked as temporary, we can delete it now
                    File.Delete(fileInfo.UnmodifiedFilePath);
                }
            }
            else
            {
                var diffCmd = sccService.GetTracker(fileInfo.ModifiedFilePath).DefaultDiffCommand;
                if (string.IsNullOrWhiteSpace(diffCmd))
                {
                    MessageBox.Show(
                        "Please setup default diff tool for git, or use change settings to use Visual Studio diff",
                        "Configuration Error");
                }
                var              cmd       = diffCmd.Replace("$LOCAL", fileInfo.UnmodifiedFilePath).Replace("$REMOTE", fileInfo.ModifiedFilePath);
                string           fileName  = Regex.Match(cmd, ParameterPattern).Value;
                string           arguments = cmd.Substring(fileName.Length);
                ProcessStartInfo startInfo = new ProcessStartInfo(fileName, arguments);
                Process.Start(startInfo);
                //var difftoolPath = GitSccOptions.Current.DifftoolPath;
                //if (string.IsNullOrWhiteSpace(difftoolPath)) difftoolPath = "diffmerge.exe";

                //try
                //{
                //    RunCommand(difftoolPath, "\"" + fileInfo.UnmodifiedFilePath + "\" \"" + fileInfo.ModifiedFilePath + "\"");
                //}
                //catch (FileNotFoundException ex)
                //{
                //    throw new FileNotFoundException(string.Format("Diff tool '{0}' is not available.", difftoolPath), difftoolPath, ex);
                //}
            }
        }
コード例 #2
0
        //TODO mode ot RepoManager
        public static DiffFileInfo GenerateDiffFileInfo(GitRepository repository, string filename)
        {
            var info = new DiffFileInfo();

            info.ActualFilename = Path.GetFileName(filename);
            info.ModifiedFilePath = filename;
            info.LastRevision = repository.GetRevision(filename);

            var filetype = Path.GetExtension(filename);

            //write unmodified file to disk
            var unmodifiedFile = repository.GetUnmodifiedFileByAbsolutePath(filename);
            var tempFileName = Path.GetTempFileName() + filetype;
            File.WriteAllText(tempFileName, unmodifiedFile);
            info.UnmodifiedFilePath = tempFileName;

            return info;
        }
コード例 #3
0
        //TODO mode ot RepoManager
        public static DiffFileInfo GenerateDiffFileInfo(GitRepository repository, string filename)
        {
            var info = new DiffFileInfo();

            info.ActualFilename   = Path.GetFileName(filename);
            info.ModifiedFilePath = filename;
            info.LastRevision     = repository.GetRevision(filename);

            var filetype = Path.GetExtension(filename);

            //write unmodified file to disk
            var unmodifiedFile = repository.GetUnmodifiedFileByAbsolutePath(filename);
            var tempFileName   = Path.GetTempFileName() + filetype;

            File.WriteAllText(tempFileName, unmodifiedFile);
            info.UnmodifiedFilePath = tempFileName;

            return(info);
        }