Package org.eclipse.jgit.lib
Class CommitConfig
- java.lang.Object
-
- org.eclipse.jgit.lib.CommitConfig
-
public class CommitConfig extends java.lang.Object
The standard "commit" configuration parameters.- Since:
- 5.13
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CommitConfig.CleanupMode
How to clean up commit messages when committing.
-
Field Summary
Fields Modifier and Type Field Description private CommitConfig.CleanupMode
cleanupMode
private java.lang.String
commitTemplatePath
private static java.lang.String
CUT
private static java.nio.charset.Charset
DEFAULT_COMMIT_MESSAGE_ENCODING
private java.lang.String
i18nCommitEncoding
static Config.SectionParser<CommitConfig>
KEY
Key forConfig.get(SectionParser)
.
-
Constructor Summary
Constructors Modifier Constructor Description private
CommitConfig(Config rc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
cleanText(java.lang.String text, CommitConfig.CleanupMode mode, char commentChar)
Processes a text according to the givenCommitConfig.CleanupMode
.CommitConfig.CleanupMode
getCleanupMode()
Retrieves theCommitConfig.CleanupMode
as given by git configcommit.cleanup
.java.lang.String
getCommitEncoding()
Get the encoding of the commit as defined in the giti18n.commitEncoding
property.java.lang.String
getCommitTemplateContent(Repository repository)
Get the content to the commit template as defined incommit.template
.java.lang.String
getCommitTemplatePath()
Get the path to the commit template as defined in the gitcommit.template
property.private java.nio.charset.Charset
getEncoding()
private static boolean
isComment(java.lang.String text, char commentChar)
CommitConfig.CleanupMode
resolve(CommitConfig.CleanupMode mode, boolean defaultStrip)
Computes a non-defaultCommitConfig.CleanupMode
from the given mode and the git config.
-
-
-
Field Detail
-
KEY
public static final Config.SectionParser<CommitConfig> KEY
Key forConfig.get(SectionParser)
.
-
CUT
private static final java.lang.String CUT
- See Also:
- Constant Field Values
-
DEFAULT_COMMIT_MESSAGE_ENCODING
private static final java.nio.charset.Charset DEFAULT_COMMIT_MESSAGE_ENCODING
-
i18nCommitEncoding
private java.lang.String i18nCommitEncoding
-
commitTemplatePath
private java.lang.String commitTemplatePath
-
cleanupMode
private CommitConfig.CleanupMode cleanupMode
-
-
Constructor Detail
-
CommitConfig
private CommitConfig(Config rc)
-
-
Method Detail
-
getCommitTemplatePath
@Nullable public java.lang.String getCommitTemplatePath()
Get the path to the commit template as defined in the gitcommit.template
property.- Returns:
- the path to commit template or
null
if not present.
-
getCommitEncoding
@Nullable public java.lang.String getCommitEncoding()
Get the encoding of the commit as defined in the giti18n.commitEncoding
property.- Returns:
- the encoding or
null
if not present.
-
getCleanupMode
@NonNull public CommitConfig.CleanupMode getCleanupMode()
Retrieves theCommitConfig.CleanupMode
as given by git configcommit.cleanup
.- Returns:
- the
CommitConfig.CleanupMode
;CommitConfig.CleanupMode.DEFAULT
if the git config is not set - Since:
- 6.1
-
resolve
@NonNull public CommitConfig.CleanupMode resolve(@NonNull CommitConfig.CleanupMode mode, boolean defaultStrip)
Computes a non-defaultCommitConfig.CleanupMode
from the given mode and the git config.- Parameters:
mode
-CommitConfig.CleanupMode
to resolvedefaultStrip
- iftrue
returnCommitConfig.CleanupMode.STRIP
if the git config is also "default", otherwise returnCommitConfig.CleanupMode.WHITESPACE
- Returns:
- the
mode
, if it is notCommitConfig.CleanupMode.DEFAULT
, otherwise the resolved mode, which is neverCommitConfig.CleanupMode.DEFAULT
- Since:
- 6.1
-
getCommitTemplateContent
@Nullable public java.lang.String getCommitTemplateContent(@NonNull Repository repository) throws java.io.FileNotFoundException, java.io.IOException, ConfigInvalidException
Get the content to the commit template as defined incommit.template
. If noi18n.commitEncoding
is specified, UTF-8 fallback is used.- Parameters:
repository
- to resolve relative path in local git repo config- Returns:
- content of the commit template or
null
if not present. - Throws:
java.io.IOException
- if the template file can not be readjava.io.FileNotFoundException
- if the template file does not existsConfigInvalidException
- if acommitEncoding
is specified and is invalid- Since:
- 6.0
-
getEncoding
private java.nio.charset.Charset getEncoding() throws ConfigInvalidException
- Throws:
ConfigInvalidException
-
cleanText
public static java.lang.String cleanText(@NonNull java.lang.String text, @NonNull CommitConfig.CleanupMode mode, char commentChar)
Processes a text according to the givenCommitConfig.CleanupMode
.- Parameters:
text
- text to processmode
-CommitConfig.CleanupMode
to usecommentChar
- comment character (normally#
) to use ifmode
isCommitConfig.CleanupMode.STRIP
orCommitConfig.CleanupMode.SCISSORS
- Returns:
- the processed text
- Throws:
java.lang.IllegalArgumentException
- ifmode
isCommitConfig.CleanupMode.DEFAULT
(useresolve(CleanupMode, boolean)
first)- Since:
- 6.1
-
isComment
private static boolean isComment(java.lang.String text, char commentChar)
-
-