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

public Class ExternalToolUtils

extends Object
Class Inheritance
Imports
java.util.TreeMap, .LinkedHashSet, .Map, .Optional, .Set, java.io.File, .IOException, org.eclipse.jgit.attributes.Attributes, org.eclipse.jgit.errors.RevisionSyntaxException, org.eclipse.jgit.lib.Constants, .Repository, org.eclipse.jgit.treewalk.FileTreeIterator, .TreeWalk, .WorkingTreeIterator, org.eclipse.jgit.treewalk.filter.NotIgnoredFilter, org.eclipse.jgit.util.FS

Utilities for diff- and merge-tools.

Field Summary

Modifier and TypeField and Description
public static final String
KEY_DIFF_TOOL

Key for diff tool git configuration section

public static final String
KEY_MERGE_TOOL

Key for merge tool git configuration section

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Set<String>

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
createSortedToolSet
(String
the default tool name
defaultName
,
Set<String>
the user defined tool names
userDefinedNames
,
Set<String>
the pre defined tool names
preDefinedNames
)

Create sorted tool set

public static Optional<String>

Returns:

attribute value for the given tool key if set
getExternalToolFromAttributes
(final Repository
target repository to traverse into
repository
,
final String
path to the node in repository to parse git attributes for
path
,
final String
config key name for the tool
toolKey
)

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

public static boolean

Returns:

true if tool available and false otherwise
isToolAvailable
(FS
the file system abstraction
fs
,
File
the .git directory
gitDir
,
File
the working directory
directory
,
String
the tool path
path
)

Whether tool is available

public static String

Returns:

the prepared (with replaced variables) command string
prepareCommand
(String
the input "command" string
command
,
FileElement
the local file (ours)
localFile
,
FileElement
the remote file (theirs)
remoteFile
,
FileElement
the merged file (worktree)
mergedFile
,
FileElement
the base file (can be null)
baseFile
)

Prepare command for execution.

public static Map<String, String>

Returns:

the environment map with variables and values (file paths)
prepareEnvironment
(File
the .git directory
gitDir
,
FileElement
the local file (ours)
localFile
,
FileElement
the remote file (theirs)
remoteFile
,
FileElement
the merged file (worktree)
mergedFile
,
FileElement
the base file (can be null)
baseFile
)

Prepare environment needed for execution.

public static String

Returns:

quoted path if it contains spaces
quotePath
(String
the path to be quoted
path
)

Quote path

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

KEY_DIFF_TOOLback to summary
public static final String KEY_DIFF_TOOL

Key for diff tool git configuration section

KEY_MERGE_TOOLback to summary
public static final String KEY_MERGE_TOOL

Key for merge tool git configuration section

Constructor Detail

ExternalToolUtilsback to summary
public ExternalToolUtils()

Method Detail

createSortedToolSetback to summary
public static Set<String> createSortedToolSet(String defaultName, Set<String> userDefinedNames, Set<String> preDefinedNames)

Create sorted tool set

Parameters
defaultName:String

the default tool name

userDefinedNames:Set<String>

the user defined tool names

preDefinedNames:Set<String>

the pre defined tool names

Returns:Set<String>

the sorted tool names set: first element is default tool name if valid, then user defined tool names and then pre defined tool names

getExternalToolFromAttributesback to summary
public static Optional<String> getExternalToolFromAttributes(final Repository repository, final String path, final 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:Repository

target repository to traverse into

path:String

path to the node in repository to parse git attributes for

toolKey:String

config key name for the tool

Returns:Optional<String>

attribute value for the given tool key if set

Exceptions
ToolException:
if the tool failed
isToolAvailableback to summary
public static boolean isToolAvailable(FS fs, File gitDir, File directory, String path)

Whether tool is available

Parameters
fs:FS

the file system abstraction

gitDir:File

the .git directory

directory:File

the working directory

path:String

the tool path

Returns:boolean

true if tool available and false otherwise

prepareCommandback to summary
public static String prepareCommand(String command, FileElement localFile, FileElement remoteFile, FileElement mergedFile, FileElement baseFile) throws IOException

Prepare command for execution.

Parameters
command:String

the input "command" string

localFile:FileElement

the local file (ours)

remoteFile:FileElement

the remote file (theirs)

mergedFile:FileElement

the merged file (worktree)

baseFile:FileElement

the base file (can be null)

Returns:String

the prepared (with replaced variables) command string

Exceptions
IOException:
if an IO error occurred
prepareEnvironmentback to summary
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:File

the .git directory

localFile:FileElement

the local file (ours)

remoteFile:FileElement

the remote file (theirs)

mergedFile:FileElement

the merged file (worktree)

baseFile:FileElement

the base file (can be null)

Returns:Map<String, String>

the environment map with variables and values (file paths)

Exceptions
IOException:
if an IO error occurred
quotePathback to summary
public static String quotePath(String path)

Quote path

Parameters
path:String

the path to be quoted

Returns:String

quoted path if it contains spaces

Annotations
@SuppressWarnings:nls