Package org.eclipse.jgit.lib
Class CommitBuilder
- java.lang.Object
-
- org.eclipse.jgit.lib.CommitBuilder
-
public class CommitBuilder extends Object
Mutable builder to construct a commit recording the state of a project. Applications should use this object when they need to manually construct a commit and want precise control over its fields. For a higher level interface seeCommitCommand. To read a commit object, construct aRevWalkand obtain aRevCommitinstance by callingRevWalk.parseCommit(AnyObjectId).
-
-
Constructor Summary
Constructors Constructor Description CommitBuilder()Initialize an empty commit.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddParentId(AnyObjectId additionalParent)Add a parent onto the end of the parent list.byte[]build()Format this builder's state as a commit object.PersonIdentgetAuthor()PersonIdentgetCommitter()CharsetgetEncoding()StringgetMessage()ObjectId[]getParentIds()ObjectIdgetTreeId()voidsetAuthor(PersonIdent newAuthor)Set the author (name, email address, and date) of who wrote the commit.voidsetCommitter(PersonIdent newCommitter)Set the committer and commit time for this objectvoidsetEncoding(String encodingName)Set the encoding for the commit informationvoidsetEncoding(Charset enc)Set the encoding for the commit informationvoidsetMessage(String newMessage)Set the commit message.voidsetParentId(AnyObjectId newParent)Set the parent of this commit.voidsetParentIds(List<? extends AnyObjectId> newParents)Set the parents of this commit.voidsetParentIds(AnyObjectId parent1, AnyObjectId parent2)Set the parents of this commit.voidsetParentIds(ObjectId... newParents)Set the parents of this commit.voidsetTreeId(AnyObjectId id)Set the tree id for this commit objectbyte[]toByteArray()Format this builder's state as a commit object.StringtoString()
-
-
-
Method Detail
-
getTreeId
public ObjectId getTreeId()
- Returns:
- id of the root tree listing this commit's snapshot.
-
setTreeId
public void setTreeId(AnyObjectId id)
Set the tree id for this commit object- Parameters:
id- the tree identity.
-
getAuthor
public PersonIdent getAuthor()
- Returns:
- the author of this commit (who wrote it).
-
setAuthor
public void setAuthor(PersonIdent newAuthor)
Set the author (name, email address, and date) of who wrote the commit.- Parameters:
newAuthor- the new author. Should not be null.
-
getCommitter
public PersonIdent getCommitter()
- Returns:
- the committer and commit time for this object.
-
setCommitter
public void setCommitter(PersonIdent newCommitter)
Set the committer and commit time for this object- Parameters:
newCommitter- the committer information. Should not be null.
-
getParentIds
public ObjectId[] getParentIds()
- Returns:
- the ancestors of this commit. Never null.
-
setParentId
public void setParentId(AnyObjectId newParent)
Set the parent of this commit.- Parameters:
newParent- the single parent for the commit.
-
setParentIds
public void setParentIds(AnyObjectId parent1, AnyObjectId parent2)
Set the parents of this commit.- Parameters:
parent1- the first parent of this commit. Typically this is the current value of theHEADreference and is thus the current branch's position in history.parent2- the second parent of this merge commit. Usually this is the branch being merged into the current branch.
-
setParentIds
public void setParentIds(ObjectId... newParents)
Set the parents of this commit.- Parameters:
newParents- the entire list of parents for this commit.
-
setParentIds
public void setParentIds(List<? extends AnyObjectId> newParents)
Set the parents of this commit.- Parameters:
newParents- the entire list of parents for this commit.
-
addParentId
public void addParentId(AnyObjectId additionalParent)
Add a parent onto the end of the parent list.- Parameters:
additionalParent- new parent to add onto the end of the current parent list.
-
getMessage
public String getMessage()
- Returns:
- the complete commit message.
-
setMessage
public void setMessage(String newMessage)
Set the commit message.- Parameters:
newMessage- the commit message. Should not be null.
-
setEncoding
public void setEncoding(String encodingName)
Set the encoding for the commit information- Parameters:
encodingName- the encoding name. SeeCharset.forName(String).
-
setEncoding
public void setEncoding(Charset enc)
Set the encoding for the commit information- Parameters:
enc- the encoding to use.
-
getEncoding
public Charset getEncoding()
- Returns:
- the encoding that should be used for the commit message text.
-
build
public byte[] build() throws UnsupportedEncodingExceptionFormat this builder's state as a commit object.- Returns:
- this object in the canonical commit format, suitable for storage in a repository.
- Throws:
UnsupportedEncodingException- the encoding specified bygetEncoding()is not supported by this Java runtime.
-
toByteArray
public byte[] toByteArray() throws UnsupportedEncodingExceptionFormat this builder's state as a commit object.- Returns:
- this object in the canonical commit format, suitable for storage in a repository.
- Throws:
UnsupportedEncodingException- the encoding specified bygetEncoding()is not supported by this Java runtime.
-
-