Class ExternalToolUtils

java.lang.Object
org.eclipse.jgit.internal.diffmergetool.ExternalToolUtils

public class ExternalToolUtils extends Object
Utilities for diff- and merge-tools.
  • Field Details

    • KEY_MERGE_TOOL

      public static final String KEY_MERGE_TOOL
      Key for merge tool git configuration section
      See Also:
    • KEY_DIFF_TOOL

      public static final String KEY_DIFF_TOOL
      Key for diff tool git configuration section
      See Also:
  • Constructor Details

    • ExternalToolUtils

      public ExternalToolUtils()
  • Method Details

    • 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 - if an IO error occurred
    • 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 - if an IO error occurred
    • quotePath

      public static String quotePath(String path)
      Quote 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)
      Whether tool is available
      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)
      Create sorted tool set
      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 - if the tool failed