Top Description Inners Fields Constructors Methods
org.eclipse.jgit.lib

public Class CommitConfig

extends Object
Class Inheritance
Imports
java.io.File, .FileNotFoundException, .IOException, java.nio.charset.Charset, .IllegalCharsetNameException, .StandardCharsets, .UnsupportedCharsetException, java.text.MessageFormat, java.util.Locale, org.eclipse.jgit.annotations.NonNull, .Nullable, org.eclipse.jgit.errors.ConfigInvalidException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.Config.ConfigEnum, .Config.SectionParser, org.eclipse.jgit.util.FS, .IO, .RawParseUtils, .StringUtils

The standard "commit" configuration parameters.
Since
5.13

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
CommitConfig.CleanupMode

How to clean up commit messages when committing.

Field Summary

Modifier and TypeField and Description
private boolean
private CommitConfig.CleanupMode
private static final char[]
private char
private String
private static final String
private static final Charset
private String
public static final Config.SectionParser<CommitConfig>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the processed text
cleanText
(String
text to process
text
,
CommitConfig.CleanupMode mode, char
comment character (normally #) to use if mode is CleanupMode#STRIP or CleanupMode#SCISSORS
commentChar
)

Processes a text according to the given CleanupMode.

public static char

Returns:

the comment character, or (char) 0 if none could be determined
determineCommentChar
(String
to get a comment character for
text
)

Determines a comment character by choosing one from a limited set of 7-bit ASCII characters that do not occur in the given text at the beginning of any line.

public CommitConfig.CleanupMode

Returns:

the CleanupMode; CleanupMode#DEFAULT if the git config is not set
getCleanupMode
()

Retrieves the CleanupMode as given by git config commit.cleanup.

public char

Returns:

the character to use for comments in commit messages
getCommentChar
()

Retrieves the comment character set by git config core.commentChar.

public char

Returns:

the character to use
getCommentChar
(String
existing text
text
)

Determines the comment character to use for a particular text.

public String

Returns:

the encoding or null if not present.
getCommitEncoding
()

Get the encoding of the commit as defined in the git i18n.commitEncoding property.

public String

Returns:

content of the commit template or null if not present.
getCommitTemplateContent
(Repository
to resolve relative path in local git repo config
repository
)

Get the content to the commit template as defined in commit.template.

public String

Returns:

the path to commit template or null if not present.
getCommitTemplatePath
()

Get the path to the commit template as defined in the git commit.template property.

private Charset
public boolean

Returns:

true if git config core.commentChar is "auto"
isAutoCommentChar
()

Tells whether the comment character should be determined by choosing a character not occurring in a commit message.

private static boolean
isComment(String text, char commentChar)

public CommitConfig.CleanupMode

Returns:

the mode, if it is not CleanupMode#DEFAULT, otherwise the resolved mode, which is never CleanupMode#DEFAULT
resolve
(CommitConfig.CleanupMode
CleanupMode to resolve
mode
,
boolean
if true return CleanupMode#STRIP if the git config is also "default", otherwise return CleanupMode#WHITESPACE
defaultStrip
)

Computes a non-default CleanupMode from the given mode and the git config.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoCommentCharback to summary
private boolean autoCommentChar
cleanupModeback to summary
private CommitConfig.CleanupMode cleanupMode
COMMENT_CHARSback to summary
private static final char[] COMMENT_CHARS
commentCharacterback to summary
private char commentCharacter
commitTemplatePathback to summary
private String commitTemplatePath
CUTback to summary
private static final String CUT
DEFAULT_COMMIT_MESSAGE_ENCODINGback to summary
private static final Charset DEFAULT_COMMIT_MESSAGE_ENCODING
i18nCommitEncodingback to summary
private String i18nCommitEncoding
KEYback to summary
public static final Config.SectionParser<CommitConfig> KEY

Key for Config#get(SectionParser).

Constructor Detail

CommitConfigback to summary
private CommitConfig(Config rc)

Method Detail

cleanTextback to summary
public static String cleanText(String text, CommitConfig.CleanupMode mode, char commentChar)

Processes a text according to the given CleanupMode.

Parameters
text:String

text to process

mode:CommitConfig.CleanupMode

CleanupMode to use

commentChar:char

comment character (normally #) to use if mode is CleanupMode#STRIP or CleanupMode#SCISSORS

Returns:String

the processed text

Exceptions
IllegalArgumentException:
if mode is CleanupMode#DEFAULT (use resolve(CleanupMode, boolean) first)
Since
6.1
determineCommentCharback to summary
public static char determineCommentChar(String text)

Determines a comment character by choosing one from a limited set of 7-bit ASCII characters that do not occur in the given text at the beginning of any line. If none can be determined, (char) 0 is returned.

Parameters
text:String

to get a comment character for

Returns:char

the comment character, or (char) 0 if none could be determined

Since
6.2
getCleanupModeback to summary
public CommitConfig.CleanupMode getCleanupMode()

Retrieves the CleanupMode as given by git config commit.cleanup.

Returns:CommitConfig.CleanupMode

the CleanupMode; CleanupMode#DEFAULT if the git config is not set

Annotations
@NonNull
Since
6.1
getCommentCharback to summary
public char getCommentChar()

Retrieves the comment character set by git config core.commentChar.

Returns:char

the character to use for comments in commit messages

Since
6.2
getCommentCharback to summary
public char getCommentChar(String text)

Determines the comment character to use for a particular text. If core.commentChar is "auto", tries to determine an unused character; if none is found, falls back to '#'. Otherwise returns the character given by core.commentChar.

Parameters
text:String

existing text

Returns:char

the character to use

Since
6.2
getCommitEncodingback to summary
public String getCommitEncoding()

Get the encoding of the commit as defined in the git i18n.commitEncoding property.

Returns:String

the encoding or null if not present.

Annotations
@Nullable
getCommitTemplateContentback to summary
public String getCommitTemplateContent(Repository repository) throws FileNotFoundException, IOException, ConfigInvalidException

Get the content to the commit template as defined in commit.template. If no i18n.commitEncoding is specified, UTF-8 fallback is used.

Parameters
repository:Repository

to resolve relative path in local git repo config

Returns:String

content of the commit template or null if not present.

Annotations
@Nullable
Exceptions
FileNotFoundException:
if the template file does not exists
IOException:
if the template file can not be read
ConfigInvalidException:
if a commitEncoding is specified and is invalid
Since
6.0
getCommitTemplatePathback to summary
public String getCommitTemplatePath()

Get the path to the commit template as defined in the git commit.template property.

Returns:String

the path to commit template or null if not present.

Annotations
@Nullable
getEncodingback to summary
private Charset getEncoding() throws ConfigInvalidException
isAutoCommentCharback to summary
public boolean isAutoCommentChar()

Tells whether the comment character should be determined by choosing a character not occurring in a commit message.

Returns:boolean

true if git config core.commentChar is "auto"

Since
6.2
isCommentback to summary
private static boolean isComment(String text, char commentChar)
resolveback to summary
public CommitConfig.CleanupMode resolve(CommitConfig.CleanupMode mode, boolean defaultStrip)

Computes a non-default CleanupMode from the given mode and the git config.

Parameters
mode:CommitConfig.CleanupMode

CleanupMode to resolve

defaultStrip:boolean

if true return CleanupMode#STRIP if the git config is also "default", otherwise return CleanupMode#WHITESPACE

Returns:CommitConfig.CleanupMode

the mode, if it is not CleanupMode#DEFAULT, otherwise the resolved mode, which is never CleanupMode#DEFAULT

Annotations
@NonNull
Since
6.1
org.eclipse.jgit.lib back to summary

public final Enum CommitConfig.CleanupMode

extends Enum<CommitConfig.CleanupMode>
implements ConfigEnum
Class Inheritance
All Implemented Interfaces
org.eclipse.jgit.lib.Config.ConfigEnum

How to clean up commit messages when committing.
Since
6.1

Field Summary

Modifier and TypeField and Description
public static final CommitConfig.CleanupMode
DEFAULT

Use STRIP for user-edited messages, otherwise WHITESPACE, unless overridden by a git config setting other than DEFAULT.

public static final CommitConfig.CleanupMode
SCISSORS

Omit everything from the first "scissor" line on, then apply WHITESPACE.

public static final CommitConfig.CleanupMode
STRIP

WHITESPACE, additionally remove comment lines.

public static final CommitConfig.CleanupMode
VERBATIM

Make no changes.

public static final CommitConfig.CleanupMode
WHITESPACE

Remove trailing whitespace and leading and trailing empty lines; collapse multiple empty lines to a single one.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
matchConfigValue(String
the string to match
in
)

Implements org.eclipse.jgit.lib.Config.ConfigEnum.matchConfigValue.

Checks if the given string matches with enum value.

public String
toConfigValue()

Implements org.eclipse.jgit.lib.Config.ConfigEnum.toConfigValue.

Converts enumeration value into a string to be save in config.

public static CommitConfig.CleanupMode
public static CommitConfig.CleanupMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DEFAULTback to summary
public static final CommitConfig.CleanupMode DEFAULT

Use STRIP for user-edited messages, otherwise WHITESPACE, unless overridden by a git config setting other than DEFAULT.

SCISSORSback to summary
public static final CommitConfig.CleanupMode SCISSORS

Omit everything from the first "scissor" line on, then apply WHITESPACE.

STRIPback to summary
public static final CommitConfig.CleanupMode STRIP

WHITESPACE, additionally remove comment lines.

VERBATIMback to summary
public static final CommitConfig.CleanupMode VERBATIM

Make no changes.

WHITESPACEback to summary
public static final CommitConfig.CleanupMode WHITESPACE

Remove trailing whitespace and leading and trailing empty lines; collapse multiple empty lines to a single one.

Constructor Detail

CleanupModeback to summary
private CleanupMode()

Method Detail

matchConfigValueback to summary
public boolean matchConfigValue(String in)

Implements org.eclipse.jgit.lib.Config.ConfigEnum.matchConfigValue.

Doc from org.eclipse.jgit.lib.Config.ConfigEnum.matchConfigValue.

Checks if the given string matches with enum value.

Parameters
in:String

the string to match

Returns:boolean

true if the given string matches enum value, false otherwise

Annotations
@Override
toConfigValueback to summary
public String toConfigValue()

Implements org.eclipse.jgit.lib.Config.ConfigEnum.toConfigValue.

Doc from org.eclipse.jgit.lib.Config.ConfigEnum.toConfigValue.

Converts enumeration value into a string to be save in config.

Returns:String

the enum value as config string

Annotations
@Override
valueOfback to summary
public static CommitConfig.CleanupMode valueOf(String name)
valuesback to summary
public static CommitConfig.CleanupMode[] values()