Package org.eclipse.jgit.api
Class CommitCommand
- java.lang.Object
-
- org.eclipse.jgit.api.GitCommand<RevCommit>
-
- org.eclipse.jgit.api.CommitCommand
-
public class CommitCommand extends GitCommand<RevCommit>
A class used to execute aCommit
command. It has setters for all supported options and arguments of this command and acall()
method to finally execute the command.- See Also:
- Git documentation about Commit
-
-
Field Summary
-
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CommitCommand(Repository repo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RevCommit
call()
Executes thecommit
command with all the options and parameters collected by the setter methods of this class.PersonIdent
getAuthor()
PersonIdent
getCommitter()
String
getMessage()
CommitCommand
setAll(boolean all)
If set to true the Commit command automatically stages files that have been modified and deleted, but new files not known by the repository are not affected.CommitCommand
setAmend(boolean amend)
Used to amend the tip of the current branch.CommitCommand
setAuthor(String name, String email)
Sets the author for thiscommit
.CommitCommand
setAuthor(PersonIdent author)
Sets the author for thiscommit
.CommitCommand
setCommitter(String name, String email)
Sets the committer for thiscommit
.CommitCommand
setCommitter(PersonIdent committer)
Sets the committer for thiscommit
.CommitCommand
setHookOutputStream(PrintStream hookStdOut)
Set the output stream for hook scripts executed by this command.CommitCommand
setInsertChangeId(boolean insertChangeId)
If set to true a change id will be inserted into the commit message An existing change id is not replaced.CommitCommand
setMessage(String message)
CommitCommand
setNoVerify(boolean noVerify)
Sets thenoVerify
option on this commit command.CommitCommand
setOnly(String only)
Commit dedicated path only.CommitCommand
setReflogComment(String reflogComment)
Override the message written to the reflog-
Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
-
-
-
Constructor Detail
-
CommitCommand
protected CommitCommand(Repository repo)
- Parameters:
repo
-
-
-
Method Detail
-
call
public RevCommit call() throws GitAPIException, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, RejectCommitException
Executes thecommit
command with all the options and parameters collected by the setter methods of this class. Each instance of this class should only be used for one invocation of the command (means: one call tocall()
)- Specified by:
call
in interfaceCallable<RevCommit>
- Specified by:
call
in classGitCommand<RevCommit>
- Returns:
- a
RevCommit
object representing the successful commit. - Throws:
NoHeadException
- when called on a git repo without a HEAD referenceNoMessageException
- when called without specifying a commit messageUnmergedPathsException
- when the current index contained unmerged paths (conflicts)ConcurrentRefUpdateException
- when HEAD or branch ref is updated concurrently by someone elseWrongRepositoryStateException
- when repository is not in the right state for committingRejectCommitException
- if there are either pre-commit or commit-msg hooks present in the repository and at least one of them rejects the commit.GitAPIException
- or subclass thereof when an error occurs
-
setMessage
public CommitCommand setMessage(String message)
- Parameters:
message
- the commit message used for thecommit
- Returns:
this
-
getMessage
public String getMessage()
- Returns:
- the commit message used for the
commit
-
setCommitter
public CommitCommand setCommitter(PersonIdent committer)
Sets the committer for thiscommit
. If no committer is explicitly specified because this method is never called or called withnull
value then the committer will be deduced from config info in repository, with current time.- Parameters:
committer
- the committer used for thecommit
- Returns:
this
-
setCommitter
public CommitCommand setCommitter(String name, String email)
Sets the committer for thiscommit
. If no committer is explicitly specified because this method is never called then the committer will be deduced from config info in repository, with current time.- Parameters:
name
- the name of the committer used for thecommit
email
- the email of the committer used for thecommit
- Returns:
this
-
getCommitter
public PersonIdent getCommitter()
- Returns:
- the committer used for the
commit
. If no committer was specifiednull
is returned and the defaultPersonIdent
of this repo is used during execution of the command
-
setAuthor
public CommitCommand setAuthor(PersonIdent author)
Sets the author for thiscommit
. If no author is explicitly specified because this method is never called or called withnull
value then the author will be set to the committer or to the original author when amending.- Parameters:
author
- the author used for thecommit
- Returns:
this
-
setAuthor
public CommitCommand setAuthor(String name, String email)
Sets the author for thiscommit
. If no author is explicitly specified because this method is never called then the author will be set to the committer or to the original author when amending.- Parameters:
name
- the name of the author used for thecommit
email
- the email of the author used for thecommit
- Returns:
this
-
getAuthor
public PersonIdent getAuthor()
- Returns:
- the author used for the
commit
. If no author was specifiednull
is returned and the defaultPersonIdent
of this repo is used during execution of the command
-
setAll
public CommitCommand setAll(boolean all)
If set to true the Commit command automatically stages files that have been modified and deleted, but new files not known by the repository are not affected. This corresponds to the parameter -a on the command line.- Parameters:
all
-- Returns:
this
- Throws:
JGitInternalException
- in case of an illegal combination of arguments/ options
-
setAmend
public CommitCommand setAmend(boolean amend)
Used to amend the tip of the current branch. If set to true, the previous commit will be amended. This is equivalent to --amend on the command line.- Parameters:
amend
-- Returns:
this
-
setOnly
public CommitCommand setOnly(String only)
Commit dedicated path only.This method can be called several times to add multiple paths. Full file paths are supported as well as directory paths; in the latter case this commits all files/directories below the specified path.
- Parameters:
only
- path to commit (with/
as separator)- Returns:
this
-
setInsertChangeId
public CommitCommand setInsertChangeId(boolean insertChangeId)
If set to true a change id will be inserted into the commit message An existing change id is not replaced. An initial change id (I000...) will be replaced by the change id.- Parameters:
insertChangeId
-- Returns:
this
-
setReflogComment
public CommitCommand setReflogComment(String reflogComment)
Override the message written to the reflog- Parameters:
reflogComment
-- Returns:
this
-
setNoVerify
public CommitCommand setNoVerify(boolean noVerify)
Sets thenoVerify
option on this commit command.Both the
pre-commit
andcommit-msg
hooks can block a commit by their return value; setting this option totrue
will bypass these two hooks.- Parameters:
noVerify
- Whether this commit should be verified by the pre-commit and commit-msg hooks.- Returns:
this
- Since:
- 3.7
-
setHookOutputStream
public CommitCommand setHookOutputStream(PrintStream hookStdOut)
Set the output stream for hook scripts executed by this command. If not set it defaults toSystem.out
.- Parameters:
hookStdOut
- the output stream for hook scripts executed by this command- Returns:
this
- Since:
- 3.7
-
-