Package org.eclipse.jgit.lib
Class CommitConfig
- java.lang.Object
-
- org.eclipse.jgit.lib.CommitConfig
-
public class CommitConfig extends 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 static Config.SectionParser<CommitConfig>
KEY
Key forConfig.get(SectionParser)
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
cleanText(String text, CommitConfig.CleanupMode mode, char commentChar)
Processes a text according to the givenCommitConfig.CleanupMode
.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.CommitConfig.CleanupMode
getCleanupMode()
Retrieves theCommitConfig.CleanupMode
as given by git configcommit.cleanup
.char
getCommentChar()
Retrieves the comment character set by git configcore.commentChar
.char
getCommentChar(String text)
Determines the comment character to use for a particular text.String
getCommitEncoding()
Get the encoding of the commit as defined in the giti18n.commitEncoding
property.String
getCommitTemplateContent(Repository repository)
Get the content to the commit template as defined incommit.template
.String
getCommitTemplatePath()
Get the path to the commit template as defined in the gitcommit.template
property.boolean
isAutoCommentChar()
Tells whether the comment character should be determined by choosing a character not occurring in a commit message.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)
.
-
-
Method Detail
-
getCommitTemplatePath
@Nullable public 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 String getCommitEncoding()
Get the encoding of the commit as defined in the giti18n.commitEncoding
property.- Returns:
- the encoding or
null
if not present.
-
getCommentChar
public char getCommentChar()
Retrieves the comment character set by git configcore.commentChar
.- Returns:
- the character to use for comments in commit messages
- Since:
- 6.2
-
getCommentChar
public char getCommentChar(String text)
Determines the comment character to use for a particular text. Ifcore.commentChar
is "auto", tries to determine an unused character; if none is found, falls back to '#'. Otherwise returns the character given bycore.commentChar
.- Parameters:
text
- existing text- Returns:
- the character to use
- Since:
- 6.2
-
isAutoCommentChar
public boolean isAutoCommentChar()
Tells whether the comment character should be determined by choosing a character not occurring in a commit message.- Returns:
true
if git configcore.commentChar
is "auto"- Since:
- 6.2
-
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 String getCommitTemplateContent(@NonNull Repository repository) throws FileNotFoundException, 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:
IOException
- if the template file can not be readFileNotFoundException
- if the template file does not existsConfigInvalidException
- if acommitEncoding
is specified and is invalid- Since:
- 6.0
-
cleanText
public static String cleanText(@NonNull 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:
IllegalArgumentException
- ifmode
isCommitConfig.CleanupMode.DEFAULT
(useresolve(CleanupMode, boolean)
first)- Since:
- 6.1
-
determineCommentChar
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
- to get a comment character for- Returns:
- the comment character, or
(char) 0
if none could be determined - Since:
- 6.2
-
-