//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); //} } }
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); }
public void StartExternalDiff(ITextDocument textDocument) { if (textDocument == null || string.IsNullOrEmpty(textDocument.FilePath)) { return; } var filename = textDocument.FilePath; if (!IsDiffPerformed(filename)) { return; } var depotPath = GetPerforcePath(filename); FileSpec fs = new FileSpec(new DepotPath(depotPath)); var tempFileName = Path.GetTempFileName(); var printOptions = new GetFileContentsCmdOptions(GetFileContentsCmdFlags.Suppress, tempFileName); _repository.GetFileContents(printOptions, fs); IVsDifferenceService differenceService = _serviceProvider.GetService(typeof(SVsDifferenceService)) as IVsDifferenceService; string leftFileMoniker = tempFileName; // The difference service will automatically load the text from the file open in the editor, even if // it has changed. Don't use the original path here. string rightFileMoniker = filename; string caption = "p4 diff"; string leftLabel = string.Format("{0}#head", depotPath); string rightLabel = filename; string inlineLabel = null; string tooltip = null; string roles = null; __VSDIFFSERVICEOPTIONS grfDiffOptions = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary; differenceService.OpenComparisonWindow2(leftFileMoniker, rightFileMoniker, caption, tooltip, leftLabel, rightLabel, inlineLabel, roles, (uint)grfDiffOptions); // Since the file is marked as temporary, we can delete it now // Perforce can create read-only file, so set FileAttributes.Normal in order to safe delete it System.IO.File.SetAttributes(tempFileName, FileAttributes.Normal); System.IO.File.Delete(tempFileName); }