Class ExternalToolUtils


  • public class ExternalToolUtils
    extends Object
    Utilities for diff- and merge-tools.
    • Constructor Detail

      • ExternalToolUtils

        public ExternalToolUtils()
    • Method Detail

      • prepareCommand

        public static String prepareCommand​(String command,
                                            FileElement localFile,
                                            FileElement remoteFile,
                                            FileElement mergedFile,
                                            FileElement baseFile)
                                     throws IOException
        Prepare command for execution.
        Parameters:
        command - the input "command" string
        localFile - the local file (ours)
        remoteFile - the remote file (theirs)
        mergedFile - the merged file (worktree)
        baseFile - the base file (can be null)
        Returns:
        the prepared (with replaced variables) command string
        Throws:
        IOException
      • prepareEnvironment

        public static Map<String,​String> prepareEnvironment​(File gitDir,
                                                                  FileElement localFile,
                                                                  FileElement remoteFile,
                                                                  FileElement mergedFile,
                                                                  FileElement baseFile)
                                                           throws IOException
        Prepare environment needed for execution.
        Parameters:
        gitDir - the .git directory
        localFile - the local file (ours)
        remoteFile - the remote file (theirs)
        mergedFile - the merged file (worktree)
        baseFile - the base file (can be null)
        Returns:
        the environment map with variables and values (file paths)
        Throws:
        IOException
      • quotePath

        public static String quotePath​(String path)
        Parameters:
        path - the path to be quoted
        Returns:
        quoted path if it contains spaces
      • isToolAvailable

        public static boolean isToolAvailable​(FS fs,
                                              File gitDir,
                                              File directory,
                                              String path)
        Parameters:
        fs - the file system abstraction
        gitDir - the .git directory
        directory - the working directory
        path - the tool path
        Returns:
        true if tool available and false otherwise
      • createSortedToolSet

        public static Set<String> createSortedToolSet​(String defaultName,
                                                      Set<String> userDefinedNames,
                                                      Set<String> preDefinedNames)
        Parameters:
        defaultName - the default tool name
        userDefinedNames - the user defined tool names
        preDefinedNames - the pre defined tool names
        Returns:
        the sorted tool names set: first element is default tool name if valid, then user defined tool names and then pre defined tool names
      • getExternalToolFromAttributes

        public static Optional<String> getExternalToolFromAttributes​(Repository repository,
                                                                     String path,
                                                                     String toolKey)
                                                              throws ToolException
        Provides Optional with the name of an external tool if specified in git configuration for a path. The formed git configuration results from global rules as well as merged rules from info and worktree attributes. Triggers TreeWalk until specified path found in the tree.
        Parameters:
        repository - target repository to traverse into
        path - path to the node in repository to parse git attributes for
        toolKey - config key name for the tool
        Returns:
        attribute value for the given tool key if set
        Throws:
        ToolException