Ejemplo n.º 1
0
        public void GetInfo(DiffMergeToolType toolType, string expectedToolKey, string expectedPrefix)
        {
            var info = _configurationManager.GetTestAccessor().GetInfo(toolType);

            info.toolKey.Should().Be(expectedToolKey);
            info.prefix.Should().Be(expectedPrefix);
        }
Ejemplo n.º 2
0
        public void GetToolSetting_should_load_setting_for_requested_toolName(DiffMergeToolType toolType, string expectedPrefix)
        {
            var settings = _configurationManager.GetTestAccessor().GetToolSetting(DiffToolName, toolType, "customSuffix");

            settings.Should().BeEmpty();
            _fileSettings.GetValue($"{expectedPrefix}.{DiffToolName}.customSuffix");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the command for the diff/merge tool configured in the effective config.
        /// </summary>
        /// <param name="toolName">The name of the diff/merge tool.</param>
        /// <param name="toolType">Type of the tool.</param>
        /// <returns>The command for the diff/merge tool configured in the effective config. </returns>
        public string GetToolCommand(string toolName, DiffMergeToolType toolType)
        {
            if (string.IsNullOrWhiteSpace(toolName))
            {
                return(string.Empty);
            }

            var command = GetToolSetting(toolName, toolType, "cmd");

            if (!string.IsNullOrWhiteSpace(command))
            {
                return(command);
            }

            var config = LoadDiffMergeToolConfig(toolName, null);

            switch (toolType)
            {
            case DiffMergeToolType.Diff: return(config.FullDiffCommand);

            case DiffMergeToolType.Merge: return(config.FullMergeCommand);

            default: throw new NotSupportedException();
            }
        }
 /// <summary>
 /// Gets the collection of all configured diff/merge tools.
 /// </summary>
 public static IEnumerable <string> All(DiffMergeToolType toolType)
 {
     return(RegisteredTools.Where(t =>
                                  (t.Value.IsDiffTool && toolType == DiffMergeToolType.Diff) ||
                                  (t.Value.IsMergeTool && toolType == DiffMergeToolType.Merge))
            .Select(t => t.Key));
 }
        private string BrowseDiffMergeTool(string toolName, string path, DiffMergeToolType toolType)
        {
            DiffMergeToolConfiguration diffMergeToolConfig = default;
            var index = toolType == DiffMergeToolType.Diff ? _NO_TRANSLATE_cboDiffTool.SelectedIndex : _NO_TRANSLATE_cboMergeTool.SelectedIndex;

            if (index > -1)
            {
                diffMergeToolConfig = _diffMergeToolConfigurationManager.LoadDiffMergeToolConfig(toolName, null);
            }

            string initialDirectory = _controller.GetInitialDirectory(path, diffMergeToolConfig.Path);

            var filter = !string.IsNullOrWhiteSpace(diffMergeToolConfig.ExeFileName)
                ? $"{toolName}|{diffMergeToolConfig.ExeFileName}"
                : "*.exe;*.cmd;*.bat|*.exe;*.cmd;*.bat";

            using (var dialog = new OpenFileDialog
            {
                Filter = filter,
                InitialDirectory = initialDirectory,
                Title = _selectFile.Text
            })
            {
                return(dialog.ShowDialog() == DialogResult.OK ? dialog.FileName : path);
            }
        }
Ejemplo n.º 6
0
        public void ConfigureDiffMergeTool_should_configure_tool(string toolName, DiffMergeToolType toolType, string toolPath, string toolCommand,
                                                                 string expectedValueKey, string expectedPathKey, string expectedCommandKey)
        {
            _configurationManager.ConfigureDiffMergeTool(toolName, toolType, toolPath, toolCommand);

            _fileSettings.Received(1).SetValue(Arg.Any <string>(), Arg.Any <string>());
            _fileSettings.Received(1).SetValue(expectedValueKey, "bla");

            _fileSettings.Received(2).SetPathValue(Arg.Any <string>(), Arg.Any <string>());
            _fileSettings.Received(1).SetPathValue(expectedPathKey, toolPath);
            _fileSettings.Received(1).SetPathValue(expectedCommandKey, toolCommand);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Unset currently configured diff/merge tool.
        /// </summary>
        /// <param name="toolType">Type of the tool.</param>
        public void UnsetCurrentTool(DiffMergeToolType toolType)
        {
            var fileSettings = _getFileSettings();

            if (fileSettings == null)
            {
                return;
            }

            (string toolKey, string _) = GetInfo(toolType);
            fileSettings.SetValue(toolKey, "");
        }
Ejemplo n.º 8
0
        private string GetToolSetting(string toolName, DiffMergeToolType toolType, string settingSuffix)
        {
            (string toolKey, string prefix) = GetInfo(toolType);

            if (string.IsNullOrWhiteSpace(toolName))
            {
                toolName = _getFileSettings()?.GetValue(toolKey);
            }

            return(string.IsNullOrWhiteSpace(toolName) ?
                   string.Empty :
                   _getFileSettings()?.GetValue(string.Concat(prefix, ".", toolName, ".", settingSuffix)));
        }
Ejemplo n.º 9
0
        private (string ToolKey, string Prefix) GetInfo(DiffMergeToolType toolType)
        {
            switch (toolType)
            {
            case DiffMergeToolType.Diff:
                return(DiffToolKey, "difftool");

            case DiffMergeToolType.Merge:
                return(MergeToolKey, "mergetool");

            default: throw new NotSupportedException();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the path to the diff/merge tool configured in the effective config.
        /// </summary>
        /// <param name="toolName">The name of the diff/merge tool.</param>
        /// <param name="toolType">Type of the tool.</param>
        /// <returns>The path to the diff/merge tool configured in the effective config. </returns>
        public string GetToolPath(string toolName, DiffMergeToolType toolType)
        {
            if (string.IsNullOrWhiteSpace(toolName))
            {
                return(string.Empty);
            }

            var path = GetToolSetting(toolName, toolType, "path");

            if (!string.IsNullOrWhiteSpace(path))
            {
                return(path);
            }

            return(LoadDiffMergeToolConfig(toolName, null).Path);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Configures diff/merge tool.
        /// </summary>
        /// <param name="toolName">The name of the diff/merge tool.</param>
        /// <param name="toolType">Type of the tool.</param>
        /// <param name="toolPath">The location of the tool's executable.</param>
        /// <param name="toolCommand">The command.</param>
        public void ConfigureDiffMergeTool(string toolName, DiffMergeToolType toolType, string toolPath, string toolCommand)
        {
            if (string.IsNullOrWhiteSpace(toolName))
            {
                Debug.Fail("Diff/merge tool is required");
                return;
            }

            var fileSettings = _getFileSettings();

            if (fileSettings == null)
            {
                return;
            }

            (string toolKey, string prefix) = GetInfo(toolType);
            fileSettings.SetValue(toolKey, toolName);
            fileSettings.SetPathValue(string.Concat(prefix, ".", toolName, ".path"), toolPath);
            fileSettings.SetPathValue(string.Concat(prefix, ".", toolName, ".cmd"), toolCommand);
        }
        /// <summary>
        /// Gets the command for the diff/merge tool configured in the effective config.
        /// </summary>
        /// <param name="toolName">The name of the diff/merge tool.</param>
        /// <param name="toolType">Type of the tool.</param>
        /// <returns>The command for the diff/merge tool configured in the effective config. </returns>
        public string GetToolCommand(string?toolName, DiffMergeToolType toolType)
        {
            if (string.IsNullOrWhiteSpace(toolName))
            {
                return(string.Empty);
            }

            var command = GetToolSetting(toolName, toolType, "cmd");

            if (!string.IsNullOrWhiteSpace(command))
            {
                return(command);
            }

            var config = LoadDiffMergeToolConfig(toolName, null);

            return(toolType switch
            {
                DiffMergeToolType.Diff => config.FullDiffCommand,
                DiffMergeToolType.Merge => config.FullMergeCommand,
                _ => throw new NotSupportedException()
            });
Ejemplo n.º 13
0
        public void GetToolPath_should_return_command_for_toolName_if_set(string toolName, DiffMergeToolType toolType, string expectedValueKey)
        {
            var toolPath = @"c:\some\path\to the tool\MyTool.exe";

            _fileSettings.GetValue(expectedValueKey).Returns(toolPath);

            _configurationManager.GetToolPath(toolName, toolType).Should().Be(toolPath);
            _fileSettings.Received(1).GetValue(Arg.Any <string>());
            _fileSettings.Received(1).GetValue(expectedValueKey);
        }
Ejemplo n.º 14
0
        public void GetToolCommand_should_return_command_for_toolName_if_set(string toolName, DiffMergeToolType toolType, string expectedValueKey)
        {
            var command = "--wait --diff \"$LOCAL\" \"$REMOTE\"";

            _fileSettings.GetValue(expectedValueKey).Returns(command);

            _configurationManager.GetToolCommand(toolName, toolType).Should().Be(command);
            _fileSettings.Received(1).GetValue(Arg.Any <string>());
            _fileSettings.Received(1).GetValue(expectedValueKey);
        }
Ejemplo n.º 15
0
 public string GetToolSetting(string toolName, DiffMergeToolType toolType, string settingSuffix)
 => _manager.GetToolSetting(toolName, toolType, settingSuffix);
Ejemplo n.º 16
0
 public (string ToolKey, string Prefix) GetInfo(DiffMergeToolType toolType)
 => _manager.GetInfo(toolType);