public class CommitCommand extends GitCommand<RevCommit>
Commit
command. It has setters for all
supported options and arguments of this command and a call()
method
to finally execute the command.repo
Modifier | Constructor and Description |
---|---|
protected |
CommitCommand(Repository repo) |
Modifier and Type | Method and Description |
---|---|
RevCommit |
call()
Executes the
commit 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 |
setAllowEmpty(boolean allowEmpty) |
CommitCommand |
setAmend(boolean amend)
Used to amend the tip of the current branch.
|
CommitCommand |
setAuthor(PersonIdent author)
Sets the author for this
commit . |
CommitCommand |
setAuthor(String name,
String email)
Sets the author for this
commit . |
CommitCommand |
setCommitter(PersonIdent committer)
Sets the committer for this
commit . |
CommitCommand |
setCommitter(String name,
String email)
Sets the committer for this
commit . |
CommitCommand |
setHookOutputStream(PrintStream hookStdOut)
Set the output stream for all hook scripts executed by this command
(pre-commit, commit-msg, post-commit).
|
CommitCommand |
setHookOutputStream(String hookName,
PrintStream hookStdOut)
Set the output stream for a selected hook script executed by this command
(pre-commit, commit-msg, post-commit).
|
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 the
noVerify option on this commit command. |
CommitCommand |
setOnly(String only)
Commit dedicated path only.
|
CommitCommand |
setReflogComment(String reflogComment)
Override the message written to the reflog
|
checkCallable, getRepository, setCallable
protected CommitCommand(Repository repo)
repo
- public RevCommit call() throws GitAPIException, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, AbortedByHookException
commit
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 to call()
)call
in interface Callable<RevCommit>
call
in class GitCommand<RevCommit>
RevCommit
object representing the successful commit.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 committingAbortedByHookException
- if there are either pre-commit or commit-msg hooks present in
the repository and one of them rejects the commit.GitAPIException
- or subclass thereof when an error occurspublic CommitCommand setMessage(String message)
message
- the commit message used for the commit
this
public CommitCommand setAllowEmpty(boolean allowEmpty)
allowEmpty
- whether it should be allowed to create a commit which has the
same tree as it's sole predecessor (a commit which doesn't
change anything). By default when creating standard commits
(without specifying paths) JGit allows to create such commits.
When this flag is set to false an attempt to create an "empty"
standard commit will lead to an EmptyCommitException.
By default when creating a commit containing only specified
paths an attempt to create an empty commit leads to a
JGitInternalException
. By setting this flag to
true
this exception will not be thrown.
this
public String getMessage()
commit
public CommitCommand setCommitter(PersonIdent committer)
commit
. If no committer is explicitly
specified because this method is never called or called with null
value then the committer will be deduced from config info in repository,
with current time.committer
- the committer used for the commit
this
public CommitCommand setCommitter(String name, String email)
commit
. 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.name
- the name of the committer used for the commit
email
- the email of the committer used for the commit
this
public PersonIdent getCommitter()
commit
. If no committer was
specified null
is returned and the default
PersonIdent
of this repo is used during execution of the
commandpublic CommitCommand setAuthor(PersonIdent author)
commit
. If no author is explicitly
specified because this method is never called or called with null
value then the author will be set to the committer or to the original
author when amending.author
- the author used for the commit
this
public CommitCommand setAuthor(String name, String email)
commit
. 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.name
- the name of the author used for the commit
email
- the email of the author used for the commit
this
public PersonIdent getAuthor()
commit
. If no author was
specified null
is returned and the default
PersonIdent
of this repo is used during execution of the
commandpublic CommitCommand setAll(boolean all)
all
- this
JGitInternalException
- in case of an illegal combination of arguments/ optionspublic CommitCommand setAmend(boolean amend)
amend
- this
public CommitCommand setOnly(String 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.
only
- path to commit (with /
as separator)this
public CommitCommand setInsertChangeId(boolean insertChangeId)
insertChangeId
- this
public CommitCommand setReflogComment(String reflogComment)
reflogComment
- the comment to be written into the reflog or null
to specify that no reflog should be writtenthis
public CommitCommand setNoVerify(boolean noVerify)
noVerify
option on this commit command.
Both the pre-commit and commit-msg hooks can block a commit by their
return value; setting this option to true
will bypass these
two hooks.
noVerify
- Whether this commit should be verified by the pre-commit and
commit-msg hooks.this
public CommitCommand setHookOutputStream(PrintStream hookStdOut)
System.out
.hookStdOut
- the output stream for hook scripts executed by this commandthis
public CommitCommand setHookOutputStream(String hookName, PrintStream hookStdOut)
System.out
.hookName
- name of the hook to set the output stream forhookStdOut
- the output stream to use for the selected hookthis
Copyright © 2017 Eclipse JGit Project. All rights reserved.