Class MergeTools


  • public class MergeTools
    extends Object
    Manages merge tools.
    • Constructor Detail

      • MergeTools

        public MergeTools​(Repository repo)
        Creates the external merge-tools manager for given repository.
        Parameters:
        repo - the repository
      • MergeTools

        public MergeTools​(StoredConfig config)
        Creates the external diff-tools manager for given configuration.
        Parameters:
        config - the git configuration
    • Method Detail

      • merge

        public Optional<FS.ExecutionResult> merge​(FileElement localFile,
                                                  FileElement remoteFile,
                                                  FileElement mergedFile,
                                                  FileElement baseFile,
                                                  File tempDir,
                                                  Optional<String> toolName,
                                                  BooleanTriState prompt,
                                                  boolean gui,
                                                  PromptContinueHandler promptHandler,
                                                  InformNoToolHandler noToolHandler)
                                           throws ToolException
        Merge two versions of a file with optional base file.
        Parameters:
        localFile - The local/left version of the file.
        remoteFile - The remote/right version of the file.
        mergedFile - The file for the result.
        baseFile - The base version of the file. May be null.
        tempDir - The tmepDir used for the files. May be null.
        toolName - Optionally the name of the tool to use. If not given the default tool will be used.
        prompt - Optionally a flag whether to prompt the user before compare. If not given the default will be used.
        gui - A flag whether to prefer a gui tool.
        promptHandler - The handler to use when needing to prompt the user if he wants to continue.
        noToolHandler - The handler to use when needing to inform the user, that no tool is configured.
        Returns:
        the optional result of executing the tool if it was executed
        Throws:
        ToolException - when the tool fails
      • merge

        public FS.ExecutionResult merge​(FileElement localFile,
                                        FileElement remoteFile,
                                        FileElement mergedFile,
                                        FileElement baseFile,
                                        File tempDir,
                                        ExternalMergeTool tool)
                                 throws ToolException
        Merge two versions of a file with optional base file.
        Parameters:
        localFile - the local file element
        remoteFile - the remote file element
        mergedFile - the merged file element
        baseFile - the base file element (can be null)
        tempDir - the temporary directory (needed for backup and auto-remove, can be null)
        tool - the selected tool
        Returns:
        the execution result from tool
        Throws:
        ToolException
      • createTempDirectory

        public File createTempDirectory()
                                 throws IOException
        Create temporary directory.
        Returns:
        the created temporary directory if (mergetol.writeToTemp == true) or null if not configured or false.
        Throws:
        IOException
      • getUserDefinedToolNames

        public Set<String> getUserDefinedToolNames()
        Get user defined tool names.
        Returns:
        the user defined tool names
      • getPredefinedToolNames

        public Set<String> getPredefinedToolNames()
        Returns:
        the predefined tool names
      • getAllToolNames

        public Set<String> getAllToolNames()
        Get all tool names.
        Returns:
        the all tool names (default or available tool name is the first in the set)
      • getExternalToolFromAttributes

        public Optional<String> getExternalToolFromAttributes​(String path)
                                                       throws ToolException
        Provides Optional with the name of an external merge 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:
        path - path to the node in repository to parse git attributes for
        Returns:
        name of the difftool if set
        Throws:
        ToolException
      • getPredefinedAvailableTools

        public Set<String> getPredefinedAvailableTools()
        Checks the availability of the predefined tools in the system.
        Returns:
        set of predefined available tools
      • getPredefinedTools

        public Map<String,​ExternalMergeTool> getPredefinedTools​(boolean checkAvailability)
        Get predefined tools map.
        Parameters:
        checkAvailability - true: for checking if tools can be executed; ATTENTION: this check took some time, do not execute often (store the map for other actions); false: availability is NOT checked: isAvailable() returns default false is this case!
        Returns:
        the predefined tools with optionally checked availability (long running operation)
      • getFirstAvailableTool

        public String getFirstAvailableTool()
        Get first available tool name.
        Returns:
        the name of first available predefined tool or null
      • isInteractive

        public boolean isInteractive()
        Is interactive merge (prompt enabled) ?
        Returns:
        is interactive (config prompt enabled) ?
      • getDefaultToolName

        public String getDefaultToolName​(boolean gui)
        Get the default (gui-)tool name.
        Parameters:
        gui - use the diff.guitool setting ?
        Returns:
        the default tool name