Top Description Fields Constructors Methods
org.eclipse.jgit.internal.diffmergetool

public Class MergeTools

extends Object
Class Inheritance
Imports
java.io.File, .IOException, java.nio.file.Files, .Path, .Paths, .StandardCopyOption, java.util.ArrayList, .Collections, .LinkedHashSet, .Map, .Map.Entry, .Optional, .Set, .TreeMap, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.Repository, .StoredConfig, org.eclipse.jgit.lib.internal.BooleanTriState, org.eclipse.jgit.treewalk.TreeWalk, org.eclipse.jgit.util.FS, .FS.ExecutionResult, .StringUtils

Manages merge tools.

Field Summary

Modifier and TypeField and Description
private final MergeToolConfig
private final FS
private final File
private final Map<String, ExternalMergeTool>
private final Repository
private final Map<String, ExternalMergeTool>
private final File

Constructor Summary

AccessConstructor and Description
public
MergeTools(Repository
the repository
repo
)

Creates the external merge-tools manager for given repository.

public
MergeTools(StoredConfig
the git configuration
config
)

Creates the external diff-tools manager for given configuration.

private

Method Summary

Modifier and TypeMethod and Description
private FileElement
createBackupFile(FileElement from, File toParentDir)

public File

Returns:

the created temporary directory if (mergetol.writeToTemp == true) or null if not configured or false.
createTempDirectory
()

Create temporary directory.

public Set<String>

Returns:

the all tool names (default or available tool name is the first in the set)
getAllToolNames
()

Get all tool names.

public String

Returns:

the default tool name
getDefaultToolName
(boolean
use the diff.guitool setting ?
gui
)

Get the default (gui-)tool name.

public Optional<String>

Returns:

name of the difftool if set
getExternalToolFromAttributes
(final String
path to the node in repository to parse git attributes for
path
)

Provides Optional with the name of an external merge tool if specified in git configuration for a path.

public String

Returns:

the name of first available predefined tool or null
getFirstAvailableTool
()

Get first available tool name.

public Set<String>

Returns:

set of predefined available tools
getPredefinedAvailableTools
()

Checks the availability of the predefined tools in the system.

public Set<String>

Returns:

the predefined tool names
getPredefinedToolNames
()

Get predefined tool names

public Map<String, ExternalMergeTool>

Returns:

the predefined tools with optionally checked availability (long running operation)
getPredefinedTools
(boolean
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!
checkAvailability
)

Get predefined tools map.

private ExternalMergeTool
getTool(final String name)

public Set<String>

Returns:

the user defined tool names
getUserDefinedToolNames
()

Get user defined tool names.

public Map<String, ExternalMergeTool>

Returns:

the user defined tools
getUserDefinedTools
()

Get user defined tools

public boolean

Returns:

is interactive (config prompt enabled) ?
isInteractive
()

Is interactive merge (prompt enabled) ?

private void
keepBackupFile(String mergedFilePath, FileElement backup)

public Optional<FS.ExecutionResult>

Returns:

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

Merge two versions of a file with optional base file.

public FS.ExecutionResult

Returns:

the execution result from tool
merge
(FileElement
the local file element
localFile
,
FileElement
the remote file element
remoteFile
,
FileElement
the merged file element
mergedFile
,
FileElement
the base file element (can be null)
baseFile
,
File
the temporary directory (needed for backup and auto-remove, can be null)
tempDir
,
ExternalMergeTool
the selected tool
tool
)

Merge two versions of a file with optional base file.

private Map<String, ExternalMergeTool>
private Map<String, ExternalMergeTool>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configback to summary
private final MergeToolConfig config
fsback to summary
private final FS fs
gitDirback to summary
private final File gitDir
predefinedToolsback to summary
private final Map<String, ExternalMergeTool> predefinedTools
repoback to summary
private final Repository repo
userDefinedToolsback to summary
private final Map<String, ExternalMergeTool> userDefinedTools
workTreeback to summary
private final File workTree

Constructor Detail

MergeToolsback to summary
public MergeTools(Repository repo)

Creates the external merge-tools manager for given repository.

Parameters
repo:Repository

the repository

MergeToolsback to summary
public MergeTools(StoredConfig config)

Creates the external diff-tools manager for given configuration.

Parameters
config:StoredConfig

the git configuration

MergeToolsback to summary
private MergeTools(Repository repo, StoredConfig config)

Method Detail

createBackupFileback to summary
private FileElement createBackupFile(FileElement from, File toParentDir) throws IOException
createTempDirectoryback to summary
public File createTempDirectory() throws IOException

Create temporary directory.

Returns:File

the created temporary directory if (mergetol.writeToTemp == true) or null if not configured or false.

Exceptions
IOException:
if an IO error occurred
getAllToolNamesback to summary
public Set<String> getAllToolNames()

Get all tool names.

Returns:Set<String>

the all tool names (default or available tool name is the first in the set)

getDefaultToolNameback to summary
public String getDefaultToolName(boolean gui)

Get the default (gui-)tool name.

Parameters
gui:boolean

use the diff.guitool setting ?

Returns:String

the default tool name

getExternalToolFromAttributesback to summary
public Optional<String> getExternalToolFromAttributes(final 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:String

path to the node in repository to parse git attributes for

Returns:Optional<String>

name of the difftool if set

Exceptions
ToolException:
if the tool failed
getFirstAvailableToolback to summary
public String getFirstAvailableTool()

Get first available tool name.

Returns:String

the name of first available predefined tool or null

getPredefinedAvailableToolsback to summary
public Set<String> getPredefinedAvailableTools()

Checks the availability of the predefined tools in the system.

Returns:Set<String>

set of predefined available tools

getPredefinedToolNamesback to summary
public Set<String> getPredefinedToolNames()

Get predefined tool names

Returns:Set<String>

the predefined tool names

getPredefinedToolsback to summary
public Map<String, ExternalMergeTool> getPredefinedTools(boolean checkAvailability)

Get predefined tools map.

Parameters
checkAvailability:boolean

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:Map<String, ExternalMergeTool>

the predefined tools with optionally checked availability (long running operation)

getToolback to summary
private ExternalMergeTool getTool(final String name)
getUserDefinedToolNamesback to summary
public Set<String> getUserDefinedToolNames()

Get user defined tool names.

Returns:Set<String>

the user defined tool names

getUserDefinedToolsback to summary
public Map<String, ExternalMergeTool> getUserDefinedTools()

Get user defined tools

Returns:Map<String, ExternalMergeTool>

the user defined tools

isInteractiveback to summary
public boolean isInteractive()

Is interactive merge (prompt enabled) ?

Returns:boolean

is interactive (config prompt enabled) ?

keepBackupFileback to summary
private void keepBackupFile(String mergedFilePath, FileElement backup) throws IOException
mergeback to summary
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:FileElement

The local/left version of the file.

remoteFile:FileElement

The remote/right version of the file.

mergedFile:FileElement

The file for the result.

baseFile:FileElement

The base version of the file. May be null.

tempDir:File

The tmepDir used for the files. May be null.

toolName:Optional<String>

Optionally the name of the tool to use. If not given the default tool will be used.

prompt:BooleanTriState

Optionally a flag whether to prompt the user before compare. If not given the default will be used.

gui:boolean

A flag whether to prefer a gui tool.

promptHandler:PromptContinueHandler

The handler to use when needing to prompt the user if he wants to continue.

noToolHandler:InformNoToolHandler

The handler to use when needing to inform the user, that no tool is configured.

Returns:Optional<FS.ExecutionResult>

the optional result of executing the tool if it was executed

Exceptions
ToolException:
when the tool fails
mergeback to summary
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:FileElement

the local file element

remoteFile:FileElement

the remote file element

mergedFile:FileElement

the merged file element

baseFile:FileElement

the base file element (can be null)

tempDir:File

the temporary directory (needed for backup and auto-remove, can be null)

tool:ExternalMergeTool

the selected tool

Returns:FS.ExecutionResult

the execution result from tool

Exceptions
ToolException:
if the tool failed
setupPredefinedToolsback to summary
private Map<String, ExternalMergeTool> setupPredefinedTools()
setupUserDefinedToolsback to summary
private Map<String, ExternalMergeTool> setupUserDefinedTools(Map<String, ExternalMergeTool> predefTools)