Top Description Fields Constructors Methods
org.eclipse.jgit.api

public Class TagCommand

extends GitCommand<Ref>
Class Inheritance
Imports
java.io.IOException, java.text.MessageFormat, org.eclipse.jgit.api.errors.ConcurrentRefUpdateException, .GitAPIException, .InvalidTagNameException, .JGitInternalException, .NoHeadException, .RefAlreadyExistsException, .UnsupportedSigningFormatException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.Constants, .GpgConfig, .GpgConfig.GpgFormat, .ObjectId, .ObjectInserter, .PersonIdent, .Ref, .RefUpdate, .RefUpdate.Result, .Repository, .Signer, .Signers, .TagBuilder, org.eclipse.jgit.revwalk.RevObject, .RevWalk, org.eclipse.jgit.transport.CredentialsProvider

Create/update an annotated tag object or a simple unannotated tag

Examples (git is a org.eclipse.jgit.api.Git instance):

Create a new tag for the current commit:

git.tag().setName("v1.0").setMessage("First stable release").call();

Create a new unannotated tag for the current commit:

git.tag().setName("v1.0").setAnnotated(false).call();
See Also
Git documentation about Tag

Field Summary

Modifier and TypeField and Description
private Boolean
private CredentialsProvider
private boolean
private GpgConfig
private RevObject
private String
private String
private Boolean
private Signer
private String
private PersonIdent
Inherited from org.eclipse.jgit.api.GitCommand:
repo

Constructor Summary

AccessConstructor and Description
protected
TagCommand(Repository repo)

Constructor for TagCommand.

Method Summary

Modifier and TypeMethod and Description
public Ref
call()

Implements abstract org.eclipse.jgit.api.GitCommand.call.

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

public String

Returns:

the tag message used for the tag
getMessage
()

Get the tag message.

public String

Returns:

the tag name used for the tag
getName
()

Get the tag name.

public RevObject

Returns:

the object id of the tag
getObjectId
()

Get the tag's object id

public String

Returns:

the key ID set, or null if none is set
getSigningKey
()

Retrieves the signing key ID.

public PersonIdent

Returns:

the tagger of the tag
getTagger
()

Get the tagger who created the tag.

public boolean

Returns:

true if this command will create an annotated tag (default is true)
isAnnotated
()

Whether this will create an annotated tag.

public boolean

Returns:

is this a force update
isForceUpdate
()

Whether this is a forced update

public boolean

Returns:

whether the tag is signed
isSigned
()

Whether setSigned(true) has been called or whether a signing key ID has been set; i.e., whether -s or -u was specified explicitly.

private void
processOptions()

Sets default values for not explicitly specified options.

public TagCommand

Returns:

this
setAnnotated
(boolean
whether this shall be an annotated tag
annotated
)

Configure this tag to be created as an annotated tag

public TagCommand

Returns:

this
setCredentialsProvider
(CredentialsProvider
the provider to use when querying for credentials (eg., during signing)
credentialsProvider
)

Sets a CredentialsProvider

public TagCommand

Returns:

this
setForceUpdate
(boolean
whether this is a forced update
forceUpdate
)

If set to true the Tag command may replace an existing tag object.

public TagCommand

Returns:

this
setGpgConfig
(GpgConfig
to set; if null, the config will be loaded from the git config of the repository
config
)

Sets an external GpgConfig to use.

public TagCommand

Returns:

this
setMessage
(String
the tag message used for the tag
message
)

Set the tag message.

public TagCommand

Returns:

this
setName
(String
the tag name used for the tag
name
)

Set the tag name.

public TagCommand

Returns:

this
setObjectId
(RevObject id)

Sets the object id of the tag.

public TagCommand

Returns:

this
setSigned
(boolean
whether to sign
signed
)

If set to true the Tag command creates a signed tag object.

public TagCommand

Returns:

this
setSigner
(Signer
to use; if null, the default signer will be used
signer
)

Sets the Signer to use if the commit is to be signed.

public TagCommand

Returns:

this
setSigningKey
(String
signing key; null allowed
signingKey
)

Sets the signing key.

public TagCommand

Returns:

this
setTagger
(PersonIdent tagger)

Sets the tagger of the tag.

private Ref
updateTagRef(ObjectId tagId, RevWalk revWalk, String tagName, String newTagToString)

Inherited from org.eclipse.jgit.api.GitCommand:
checkCallablegetRepositorysetCallable

Field Detail

annotatedback to summary
private Boolean annotated
credentialsProviderback to summary
private CredentialsProvider credentialsProvider
forceUpdateback to summary
private boolean forceUpdate
gpgConfigback to summary
private GpgConfig gpgConfig
idback to summary
private RevObject id
messageback to summary
private String message
nameback to summary
private String name
signedback to summary
private Boolean signed
signerback to summary
private Signer signer
signingKeyback to summary
private String signingKey
taggerback to summary
private PersonIdent tagger

Constructor Detail

TagCommandback to summary
protected TagCommand(Repository repo)

Constructor for TagCommand.

Parameters
repo:Repository

a org.eclipse.jgit.lib.Repository object.

Method Detail

callback to summary
public Ref call() throws GitAPIException, ConcurrentRefUpdateException, InvalidTagNameException, NoHeadException

Implements abstract org.eclipse.jgit.api.GitCommand.call.

Implements java.util.concurrent.Callable.call.

Doc from org.eclipse.jgit.api.GitCommand.call.

Computes a result, or throws an exception if unable to do so.

Execute the command

Executes the tag 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())

Returns:Ref

Doc from java.util.concurrent.Callable.call.

computed result

Annotations
@Override
Since
2.0
getMessageback to summary
public String getMessage()

Get the tag message.

Returns:String

the tag message used for the tag

getNameback to summary
public String getName()

Get the tag name.

Returns:String

the tag name used for the tag

getObjectIdback to summary
public RevObject getObjectId()

Get the tag's object id

Returns:RevObject

the object id of the tag

getSigningKeyback to summary
public String getSigningKey()

Retrieves the signing key ID.

Returns:String

the key ID set, or null if none is set

Since
5.11
getTaggerback to summary
public PersonIdent getTagger()

Get the tagger who created the tag.

Returns:PersonIdent

the tagger of the tag

isAnnotatedback to summary
public boolean isAnnotated()

Whether this will create an annotated tag.

Returns:boolean

true if this command will create an annotated tag (default is true)

Since
3.0
isForceUpdateback to summary
public boolean isForceUpdate()

Whether this is a forced update

Returns:boolean

is this a force update

isSignedback to summary
public boolean isSigned()

Whether setSigned(true) has been called or whether a signing key ID has been set; i.e., whether -s or -u was specified explicitly.

Returns:boolean

whether the tag is signed

processOptionsback to summary
private void processOptions() throws InvalidTagNameException, UnsupportedSigningFormatException

Sets default values for not explicitly specified options. Then validates that all required data has been provided.

Exceptions
InvalidTagNameException:
if the tag name is null or invalid
UnsupportedSigningFormatException:
if the tag should be signed but gpg.format is not GpgFormat#OPENPGP
setAnnotatedback to summary
public TagCommand setAnnotated(boolean annotated)

Configure this tag to be created as an annotated tag

Parameters
annotated:boolean

whether this shall be an annotated tag

Returns:TagCommand

this

Since
3.0
setCredentialsProviderback to summary
public TagCommand setCredentialsProvider(CredentialsProvider credentialsProvider)

Sets a CredentialsProvider

Parameters
credentialsProvider:CredentialsProvider

the provider to use when querying for credentials (eg., during signing)

Returns:TagCommand

this

Since
5.11
setForceUpdateback to summary
public TagCommand setForceUpdate(boolean forceUpdate)

If set to true the Tag command may replace an existing tag object. This corresponds to the parameter -f on the command line.

Parameters
forceUpdate:boolean

whether this is a forced update

Returns:TagCommand

this

setGpgConfigback to summary
public TagCommand setGpgConfig(GpgConfig config)

Sets an external GpgConfig to use. Whether it will be used is at the discretion of the setSigner(Signer).

Parameters
config:GpgConfig

to set; if null, the config will be loaded from the git config of the repository

Returns:TagCommand

this

Since
5.11
setMessageback to summary
public TagCommand setMessage(String message)

Set the tag message.

Parameters
message:String

the tag message used for the tag

Returns:TagCommand

this

setNameback to summary
public TagCommand setName(String name)

Set the tag name.

Parameters
name:String

the tag name used for the tag

Returns:TagCommand

this

setObjectIdback to summary
public TagCommand setObjectId(RevObject id)

Sets the object id of the tag. If the object id is null, the commit pointed to from HEAD will be used.

Parameters
id:RevObject

a org.eclipse.jgit.revwalk.RevObject object.

Returns:TagCommand

this

setSignedback to summary
public TagCommand setSigned(boolean signed)

If set to true the Tag command creates a signed tag object. This corresponds to the parameter -s (--sign or --no-sign) on the command line.

If true, the tag will be a signed annotated tag.

Parameters
signed:boolean

whether to sign

Returns:TagCommand

this

setSignerback to summary
public TagCommand setSigner(Signer signer)

Sets the Signer to use if the commit is to be signed.

Parameters
signer:Signer

to use; if null, the default signer will be used

Returns:TagCommand

this

Since
7.0
setSigningKeyback to summary
public TagCommand setSigningKey(String signingKey)

Sets the signing key.

Per spec of user.signingKey: this will be sent to the GPG program as is, i.e. can be anything supported by the GPG program.

Note, if none was set or null is specified a default will be obtained from the configuration.

If set to a non-null value, the tag will be a signed annotated tag.

Parameters
signingKey:String

signing key; null allowed

Returns:TagCommand

this

Since
5.11
setTaggerback to summary
public TagCommand setTagger(PersonIdent tagger)

Sets the tagger of the tag. If the tagger is null, a PersonIdent will be created from the info in the repository.

Parameters
tagger:PersonIdent

a org.eclipse.jgit.lib.PersonIdent object.

Returns:TagCommand

this

updateTagRefback to summary
private Ref updateTagRef(ObjectId tagId, RevWalk revWalk, String tagName, String newTagToString) throws IOException, ConcurrentRefUpdateException, RefAlreadyExistsException