Interface GitClient
-
- All Known Subinterfaces:
IGitAPI
- All Known Implementing Classes:
CliGitAPIImpl
,GitAPI
,JGitAPIImpl
public interface GitClient
Interface to Git functionality.Since 1.1, this interface is remotable, meaning it can be referenced from a remote closure call.
-
-
Field Summary
Fields Modifier and Type Field Description static com.cloudbees.plugins.credentials.CredentialsMatcher
CREDENTIALS_MATCHER
The supported credential types.static boolean
quietRemoteBranches
ConstantquietRemoteBranches=Boolean.getBoolean(GitClient.class.getName() + ".quietRemoteBranches")
static boolean
verbose
Constantverbose=Boolean.getBoolean(IGitAPI.class.getName() + ".verbose")
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
add(String filePattern)
add.void
addCredentials(String url, com.cloudbees.plugins.credentials.common.StandardCredentials credentials)
Adds credentials to be used against a specific url.void
addDefaultCredentials(com.cloudbees.plugins.credentials.common.StandardCredentials credentials)
Adds credentials to be used when there are not url specific credentials defined.void
addNote(String note, String namespace)
Adds a new git-note on the current HEAD commit.void
addRemoteUrl(String name, String url)
addRemoteUrl.void
addSubmodule(String remoteURL, String subdir)
Create a submodule in subdir child directory for remote repositoryvoid
appendNote(String note, String namespace)
Appends to an existing git-note on the current HEAD commit.void
branch(String name)
branch.ChangelogCommand
changelog()
Returns aChangelogCommand
to build up the git-log invocation.void
changelog(String revFrom, String revTo, OutputStream os)
Deprecated.void
changelog(String revFrom, String revTo, Writer os)
Adds the changelog entries for commits in the range revFrom..revTo.CheckoutCommand
checkout()
checkout.void
checkout(String ref)
Deprecated.usecheckout()
andCheckoutCommand
void
checkout(String ref, String branch)
Deprecated.usecheckout()
andCheckoutCommand
void
checkoutBranch(String branch, String ref)
Regardless of the current state of the workspace (whether there is some dirty files, etc) and the state of the repository (whether the branch of the specified name exists or not), when this method exits the following conditions hold: The branch of the specified name branch exists and points to the specified refHEAD
points to branch.void
clean()
Fully revert working copy to a clean state, i.e.void
clean(boolean cleanSubmodule)
Fully revert working copy to a clean state, i.e.void
clearCredentials()
Remove all credentials from the client.void
clone(String url, String origin, boolean useShallowClone, String reference)
Clone a remote repositoryCloneCommand
clone_()
Returns aCloneCommand
to build up the git-log invocation.void
commit(String message)
commit.void
commit(String message, org.eclipse.jgit.lib.PersonIdent author, org.eclipse.jgit.lib.PersonIdent committer)
Deprecated.void
deleteBranch(String name)
(force) delete a branch.void
deleteRef(String refName)
Deletes a ref.void
deleteTag(String tagName)
deleteTag.String
describe(String commitIsh)
Equivalent of "git-describe --tags".void
fetch(String remoteName, org.eclipse.jgit.transport.RefSpec refspec)
Deprecated.usefetch_()
and configure aFetchCommand
void
fetch(String remoteName, org.eclipse.jgit.transport.RefSpec... refspec)
Deprecated.usefetch_()
and configure aFetchCommand
void
fetch(org.eclipse.jgit.transport.URIish url, List<org.eclipse.jgit.transport.RefSpec> refspecs)
Deprecated.usefetch_()
and configure aFetchCommand
FetchCommand
fetch_()
fetch_.Set<Branch>
getBranches()
getBranches.List<Branch>
getBranchesContaining(String revspec, boolean allBranches)
Find all the branches that include the given commit.Map<String,org.eclipse.jgit.lib.ObjectId>
getHeadRev(String url)
getHeadRev.org.eclipse.jgit.lib.ObjectId
getHeadRev(String remoteRepoUrl, String branch)
getHeadRev.Set<String>
getRefNames(String refPrefix)
List refs with the given prefix.Set<Branch>
getRemoteBranches()
getRemoteBranches.Map<String,org.eclipse.jgit.lib.ObjectId>
getRemoteReferences(String remoteRepoUrl, String pattern, boolean headsOnly, boolean tagsOnly)
List references in a remote repository.Map<String,String>
getRemoteSymbolicReferences(String remoteRepoUrl, String pattern)
List symbolic references in a remote repository.Set<String>
getRemoteTagNames(String tagPattern)
getRemoteTagNames.String
getRemoteUrl(String name)
From a given repository, get a remote's URLorg.eclipse.jgit.lib.Repository
getRepository()
Deprecated.as of 1.1 This method was deprecated to makeGitClient
remotable.List<IndexEntry>
getSubmodules(String treeIsh)
Finds all the submodule references in this repository at the specified tree.String
getTagMessage(String tagName)
getTagMessage.Set<String>
getTagNames(String tagPattern)
getTagNames.Set<GitObject>
getTags()
Return name and object ID of all tags in current repository.FilePath
getWorkTree()
The working tree of this repository.boolean
hasGitModules()
Returns true if the repository has Git submodules.boolean
hasGitRepo()
Return true if the current workspace has a git repository.boolean
hasGitRepo(boolean checkParentDirectories)
Return true if the current workspace has a git repository.void
init()
init.InitCommand
init_()
init_.boolean
isCommitInRepo(org.eclipse.jgit.lib.ObjectId commit)
isCommitInRepo.boolean
maintenance(String task)
Executes git maintenance commands based on the git version.MergeCommand
merge()
merge.void
merge(org.eclipse.jgit.lib.ObjectId rev)
Deprecated.usemerge()
and configure aMergeCommand
void
prune(org.eclipse.jgit.transport.RemoteConfig repository)
Prune stale remote tracking branches with "git remote prune" on the specified remote.PushCommand
push()
push.void
push(String remoteName, String refspec)
Deprecated.usepush()
and configure aPushCommand
void
push(org.eclipse.jgit.transport.URIish url, String refspec)
Deprecated.usepush()
and configure aPushCommand
RebaseCommand
rebase()
rebase.void
ref(String refName)
Create (or update) a ref.boolean
refExists(String refName)
Check if a ref exists.List<org.eclipse.jgit.lib.ObjectId>
revList(String ref)
revList.RevListCommand
revList_()
revList_.List<org.eclipse.jgit.lib.ObjectId>
revListAll()
revListAll.org.eclipse.jgit.lib.ObjectId
revParse(String revName)
Retrieve commit object that is direct child forrevName
revision reference.void
setAuthor(String name, String email)
Sets the identity of the author for future commits and merge operations.void
setAuthor(org.eclipse.jgit.lib.PersonIdent p)
setAuthor.void
setCommitter(String name, String email)
Sets the identity of the committer for future commits and merge operations.void
setCommitter(org.eclipse.jgit.lib.PersonIdent p)
setCommitter.void
setCredentials(com.cloudbees.plugins.credentials.common.StandardUsernameCredentials cred)
setCredentials.void
setProxy(ProxyConfiguration proxy)
setProxy.void
setRemoteUrl(String name, String url)
For a given repository, set a remote's URLvoid
setupSubmoduleUrls(Revision rev, TaskListener listener)
Set up submodule URLs so that they correspond to the remote pertaining to the revision that has been checked out.List<String>
showRevision(org.eclipse.jgit.lib.ObjectId r)
Given a Revision, show it as if it were an entry from git whatchanged, so that it can be parsed by GitChangeLogParser.List<String>
showRevision(org.eclipse.jgit.lib.ObjectId from, org.eclipse.jgit.lib.ObjectId to)
Given a Revision, show it as if it were an entry from git whatchanged, so that it can be parsed by GitChangeLogParser.List<String>
showRevision(org.eclipse.jgit.lib.ObjectId from, org.eclipse.jgit.lib.ObjectId to, Boolean useRawOutput)
Given a Revision, show it as if it were an entry from git whatchanged, so that it can be parsed by GitChangeLogParser.GitClient
subGit(String subdir)
subGit.void
submoduleClean(boolean recursive)
submoduleClean.void
submoduleInit()
submoduleInit.SubmoduleUpdateCommand
submoduleUpdate()
submoduleUpdate.void
submoduleUpdate(boolean recursive)
Deprecated.void
submoduleUpdate(boolean recursive, boolean remoteTracking)
Deprecated.void
submoduleUpdate(boolean recursive, boolean remoteTracking, String reference)
Deprecated.void
submoduleUpdate(boolean recursive, String reference)
Deprecated.void
tag(String tagName, String comment)
Create (or update) a tag.boolean
tagExists(String tagName)
tagExists.<T> T
withRepository(RepositoryCallback<T> callable)
Runs the computation that requires local access toRepository
.
-
-
-
Field Detail
-
verbose
static final boolean verbose
Constantverbose=Boolean.getBoolean(IGitAPI.class.getName() + ".verbose")
-
quietRemoteBranches
static final boolean quietRemoteBranches
ConstantquietRemoteBranches=Boolean.getBoolean(GitClient.class.getName() + ".quietRemoteBranches")
-
CREDENTIALS_MATCHER
static final com.cloudbees.plugins.credentials.CredentialsMatcher CREDENTIALS_MATCHER
The supported credential types.- Since:
- 1.2.0
-
-
Method Detail
-
clearCredentials
void clearCredentials()
Remove all credentials from the client.- Since:
- 1.2.0
-
addCredentials
void addCredentials(String url, com.cloudbees.plugins.credentials.common.StandardCredentials credentials)
Adds credentials to be used against a specific url.- Parameters:
url
- the url for the credentials to be used against.credentials
- the credentials to use.- Since:
- 1.2.0
-
addDefaultCredentials
void addDefaultCredentials(com.cloudbees.plugins.credentials.common.StandardCredentials credentials)
Adds credentials to be used when there are not url specific credentials defined.- Parameters:
credentials
- the credentials to use.- Since:
- 1.2.0
- See Also:
addCredentials(String, com.cloudbees.plugins.credentials.common.StandardCredentials)
-
setAuthor
void setAuthor(String name, String email) throws GitException
Sets the identity of the author for future commits and merge operations.- Parameters:
name
- aString
object.email
- aString
object.- Throws:
GitException
- if underlying git operation fails.
-
setAuthor
void setAuthor(org.eclipse.jgit.lib.PersonIdent p) throws GitException
setAuthor.- Parameters:
p
- aPersonIdent
object.- Throws:
GitException
- if underlying git operation fails.
-
setCommitter
void setCommitter(String name, String email) throws GitException
Sets the identity of the committer for future commits and merge operations.- Parameters:
name
- aString
object.email
- aString
object.- Throws:
GitException
- if underlying git operation fails.
-
setCommitter
void setCommitter(org.eclipse.jgit.lib.PersonIdent p) throws GitException
setCommitter.- Parameters:
p
- aPersonIdent
object.- Throws:
GitException
- if underlying git operation fails.
-
getRepository
@Deprecated org.eclipse.jgit.lib.Repository getRepository() throws GitException
Deprecated.as of 1.1 This method was deprecated to makeGitClient
remotable. When called on a proxy object, this method throwsNotSerializableException
. UsewithRepository(RepositoryCallback)
to pass in the closure instead. This prevents the repository leak (JENKINS-12188), too.Expose the JGit repository this GitClient is using. Don't forget to callRepository.close()
, to avoid JENKINS-12188.- Returns:
- a
Repository
object. - Throws:
GitException
- if underlying git operation fails.
-
withRepository
<T> T withRepository(RepositoryCallback<T> callable) throws IOException, InterruptedException
Runs the computation that requires local access toRepository
.- Type Parameters:
T
- type for the repository callback- Parameters:
callable
- the repository callback used as closure to instance- Returns:
- a T object.
- Throws:
IOException
- in case of IO errorInterruptedException
- if interrupted
-
init
void init() throws GitException, InterruptedException
init.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
add
void add(String filePattern) throws GitException, InterruptedException
add.- Parameters:
filePattern
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
commit
void commit(String message) throws GitException, InterruptedException
commit.- Parameters:
message
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
commit
@Deprecated void commit(String message, org.eclipse.jgit.lib.PersonIdent author, org.eclipse.jgit.lib.PersonIdent committer) throws GitException, InterruptedException
Deprecated.commit.- Parameters:
message
- aString
object.author
- aPersonIdent
object.committer
- aPersonIdent
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
hasGitRepo
boolean hasGitRepo() throws GitException, InterruptedException
Return true if the current workspace has a git repository.- Returns:
- true if this workspace has a git repository
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
hasGitRepo
boolean hasGitRepo(boolean checkParentDirectories) throws GitException, InterruptedException
Return true if the current workspace has a git repository. If checkParentDirectories is true, searches parent directories. If checkParentDirectories is false, checks workspace directory only.- Parameters:
checkParentDirectories
- if true, search upward for a git repository- Returns:
- true if this workspace has a git repository
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
isCommitInRepo
boolean isCommitInRepo(org.eclipse.jgit.lib.ObjectId commit) throws GitException, InterruptedException
isCommitInRepo.- Parameters:
commit
- aObjectId
object.- Returns:
- true if commit is in repository
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getRemoteUrl
String getRemoteUrl(String name) throws GitException, InterruptedException
From a given repository, get a remote's URL- Parameters:
name
- The name of the remote (e.g. origin)- Returns:
- a
String
object. - Throws:
GitException
- if executing the git command failsInterruptedException
- if interrupted.
-
setRemoteUrl
void setRemoteUrl(String name, String url) throws GitException, InterruptedException
For a given repository, set a remote's URL- Parameters:
name
- The name of the remote (e.g. origin)url
- The new value of the remote's URL- Throws:
GitException
- if executing the git command failsInterruptedException
- if interrupted.
-
addRemoteUrl
void addRemoteUrl(String name, String url) throws GitException, InterruptedException
addRemoteUrl.- Parameters:
name
- aString
object.url
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
checkout
@Deprecated void checkout(String ref) throws GitException, InterruptedException
Deprecated.usecheckout()
andCheckoutCommand
Checks out the specified commit/tag/branch into the workspace. (equivalent ofgit checkout branch
.)- Parameters:
ref
- A git object references expression (either a sha1, tag or branch)- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
checkout
@Deprecated void checkout(String ref, String branch) throws GitException, InterruptedException
Deprecated.usecheckout()
andCheckoutCommand
Creates a new branch that points to the specified ref. (equivalent to git checkout -b branch commit) This will fail if the branch already exists.- Parameters:
ref
- A git object references expression. For backward compatibility,null
will checkout current HEADbranch
- name of the branch to create from reference- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
checkout
CheckoutCommand checkout()
checkout.- Returns:
- a
CheckoutCommand
object.
-
checkoutBranch
void checkoutBranch(@CheckForNull String branch, String ref) throws GitException, InterruptedException
Regardless of the current state of the workspace (whether there is some dirty files, etc) and the state of the repository (whether the branch of the specified name exists or not), when this method exits the following conditions hold:- The branch of the specified name branch exists and points to the specified ref
HEAD
points to branch. In other words, the workspace is on the specified branch.- Both index and workspace are the same tree with ref. (no dirty files and no staged changes, although this method will not touch untracked files in the workspace.)
This method is preferred over the
checkout(String, String)
family of methods, as this method is affected far less by the current state of the repository. Thecheckout
methods, in their attempt to emulate the "git checkout" command line behaviour, have too many side effects. In Jenkins, where you care a lot less about throwing away local changes and care a lot more about resetting the workspace into a known state, methods like this is more useful.For compatibility reasons, the order of the parameter is different from
checkout(String, String)
.- Parameters:
branch
- aString
object.ref
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.- Since:
- 1.0.6
-
clone
void clone(String url, String origin, boolean useShallowClone, String reference) throws GitException, InterruptedException
Clone a remote repository- Parameters:
url
- URL for remote repository to cloneorigin
- upstream track name, defaults toorigin
by conventionuseShallowClone
- option to create a shallow clone, that has some restriction but will make clone operationreference
- (optional) reference to a local clone for faster clone operations (reduce network and local storage costs)- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
clone_
CloneCommand clone_()
Returns aCloneCommand
to build up the git-log invocation.- Returns:
- a
CloneCommand
object.
-
fetch
@Deprecated void fetch(org.eclipse.jgit.transport.URIish url, List<org.eclipse.jgit.transport.RefSpec> refspecs) throws GitException, InterruptedException
Deprecated.usefetch_()
and configure aFetchCommand
Fetch commits from url which match any of the passed in refspecs. Assumesremote.remoteName.url
has been set.- Parameters:
url
- aURIish
object.refspecs
- aList
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
fetch
@Deprecated void fetch(String remoteName, org.eclipse.jgit.transport.RefSpec... refspec) throws GitException, InterruptedException
Deprecated.usefetch_()
and configure aFetchCommand
fetch.- Parameters:
remoteName
- aString
object.refspec
- aRefSpec
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
fetch
@Deprecated void fetch(String remoteName, org.eclipse.jgit.transport.RefSpec refspec) throws GitException, InterruptedException
Deprecated.usefetch_()
and configure aFetchCommand
fetch.- Parameters:
remoteName
- aString
object.refspec
- aRefSpec
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
fetch_
FetchCommand fetch_()
fetch_.- Returns:
- a
FetchCommand
object.
-
push
@Deprecated void push(String remoteName, String refspec) throws GitException, InterruptedException
Deprecated.usepush()
and configure aPushCommand
push.- Parameters:
remoteName
- aString
object.refspec
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
push
@Deprecated void push(org.eclipse.jgit.transport.URIish url, String refspec) throws GitException, InterruptedException
Deprecated.usepush()
and configure aPushCommand
push.- Parameters:
url
- aURIish
object.refspec
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
push
PushCommand push()
push.- Returns:
- a
PushCommand
object.
-
merge
@Deprecated void merge(org.eclipse.jgit.lib.ObjectId rev) throws GitException, InterruptedException
Deprecated.usemerge()
and configure aMergeCommand
merge.- Parameters:
rev
- aObjectId
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
merge
MergeCommand merge()
merge.- Returns:
- a
MergeCommand
object.
-
rebase
RebaseCommand rebase()
rebase.- Returns:
- a
RebaseCommand
object.
-
init_
InitCommand init_()
init_.- Returns:
- a
InitCommand
object.
-
prune
void prune(org.eclipse.jgit.transport.RemoteConfig repository) throws GitException, InterruptedException
Prune stale remote tracking branches with "git remote prune" on the specified remote.- Parameters:
repository
- aRemoteConfig
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
clean
void clean() throws GitException, InterruptedException
Fully revert working copy to a clean state, i.e. run both git-reset(1) --hard then git-clean(1) for working copy to match a fresh clone.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
clean
void clean(boolean cleanSubmodule) throws GitException, InterruptedException
Fully revert working copy to a clean state, i.e. run both git-reset(1) --hard then git-clean(1) for working copy to match a fresh clone.- Parameters:
cleanSubmodule
- flag to add extra -f- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
branch
void branch(String name) throws GitException, InterruptedException
branch.- Parameters:
name
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
deleteBranch
void deleteBranch(String name) throws GitException, InterruptedException
(force) delete a branch.- Parameters:
name
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getBranches
Set<Branch> getBranches() throws GitException, InterruptedException
getBranches.- Returns:
- a
Set
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getRemoteBranches
Set<Branch> getRemoteBranches() throws GitException, InterruptedException
getRemoteBranches.- Returns:
- a
Set
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
tag
void tag(String tagName, String comment) throws GitException, InterruptedException
Create (or update) a tag. If tag already exist it gets updated (equivalent togit tag --force
)- Parameters:
tagName
- aString
object.comment
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
tagExists
boolean tagExists(String tagName) throws GitException, InterruptedException
tagExists.- Parameters:
tagName
- aString
object.- Returns:
- true if tag exists in repository
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getTagMessage
String getTagMessage(String tagName) throws GitException, InterruptedException
getTagMessage.- Parameters:
tagName
- aString
object.- Returns:
- a
String
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
deleteTag
void deleteTag(String tagName) throws GitException, InterruptedException
deleteTag.- Parameters:
tagName
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getTagNames
Set<String> getTagNames(String tagPattern) throws GitException, InterruptedException
getTagNames.- Parameters:
tagPattern
- aString
object.- Returns:
- a
Set
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getRemoteTagNames
Set<String> getRemoteTagNames(String tagPattern) throws GitException, InterruptedException
getRemoteTagNames.- Parameters:
tagPattern
- aString
object.- Returns:
- a
Set
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
ref
void ref(String refName) throws GitException, InterruptedException
Create (or update) a ref. The ref will reference HEAD (equivalent togit update-ref ... HEAD
).- Parameters:
refName
- the full name of the ref (e.g. "refs/myref"). Spaces will be replaced with underscores.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
refExists
boolean refExists(String refName) throws GitException, InterruptedException
Check if a ref exists. Equivalent to comparing the return code ofgit show-ref
to zero.- Parameters:
refName
- the full name of the ref (e.g. "refs/myref"). Spaces will be replaced with underscores.- Returns:
- True if the ref exists, false otherwse.
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
deleteRef
void deleteRef(String refName) throws GitException, InterruptedException
Deletes a ref. Has no effect if the ref does not exist, equivalent togit update-ref -d
.- Parameters:
refName
- the full name of the ref (e.g. "refs/myref"). Spaces will be replaced with underscores.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getRefNames
Set<String> getRefNames(String refPrefix) throws GitException, InterruptedException
List refs with the given prefix. Equivalent togit for-each-ref --format="%(refname)"
.- Parameters:
refPrefix
- the literal prefix any ref returned will have. The empty string implies all.- Returns:
- a set of refs, each beginning with the given prefix. Empty if none.
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getHeadRev
Map<String,org.eclipse.jgit.lib.ObjectId> getHeadRev(String url) throws GitException, InterruptedException
getHeadRev.- Parameters:
url
- aString
object.- Returns:
- a
Map
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getHeadRev
org.eclipse.jgit.lib.ObjectId getHeadRev(String remoteRepoUrl, String branch) throws GitException, InterruptedException
getHeadRev.- Parameters:
remoteRepoUrl
- aString
object.branch
- aString
object.- Returns:
- a
ObjectId
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getRemoteReferences
Map<String,org.eclipse.jgit.lib.ObjectId> getRemoteReferences(String remoteRepoUrl, String pattern, boolean headsOnly, boolean tagsOnly) throws GitException, InterruptedException
List references in a remote repository. Equivalent togit ls-remote [--heads] [--tags] <repository> [<refs>]
.- Parameters:
remoteRepoUrl
- Remote repository URL.pattern
- Only references matching the given pattern are displayed.headsOnly
- Limit to only refs/heads.tagsOnly
- Limit to only refs/tags. headsOnly and tagsOnly are not mutually exclusive; when both are true, references stored in refs/heads and refs/tags are displayed.- Returns:
- a map of reference names and their commit hashes. Empty if none.
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getRemoteSymbolicReferences
Map<String,String> getRemoteSymbolicReferences(String remoteRepoUrl, String pattern) throws GitException, InterruptedException
List symbolic references in a remote repository. Equivalent togit ls-remote --symref <repository> [<refs>]
. Note: the response may be empty for multiple reasons- Parameters:
remoteRepoUrl
- Remote repository URL.pattern
- Only references matching the given pattern are displayed.- Returns:
- a map of reference names and their underlying references. Empty if none or if the remote does not report symbolic references (i.e. Git 1.8.4 or earlier) or if the client does not support reporting symbolic references (e.g. command line Git prior to 2.8.0).
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
revParse
org.eclipse.jgit.lib.ObjectId revParse(String revName) throws GitException, InterruptedException
Retrieve commit object that is direct child forrevName
revision reference.- Parameters:
revName
- a commit sha1 or tag/branch refname- Returns:
- a
ObjectId
object. - Throws:
GitException
- when no such commit / revName is found in repository.InterruptedException
- if interrupted.
-
revList_
RevListCommand revList_()
revList_.- Returns:
- a
RevListCommand
object.
-
revListAll
List<org.eclipse.jgit.lib.ObjectId> revListAll() throws GitException, InterruptedException
revListAll.- Returns:
- a
List
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
revList
List<org.eclipse.jgit.lib.ObjectId> revList(String ref) throws GitException, InterruptedException
revList.- Parameters:
ref
- aString
object.- Returns:
- a
List
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
subGit
GitClient subGit(String subdir)
subGit.- Parameters:
subdir
- aString
object.- Returns:
- a IGitAPI implementation to manage git submodule repository
-
hasGitModules
boolean hasGitModules() throws GitException, InterruptedException
Returns true if the repository has Git submodules.- Returns:
- true if this repository has submodules
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getSubmodules
List<IndexEntry> getSubmodules(String treeIsh) throws GitException, InterruptedException
Finds all the submodule references in this repository at the specified tree.- Parameters:
treeIsh
- aString
object.- Returns:
- never null.
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
addSubmodule
void addSubmodule(String remoteURL, String subdir) throws GitException, InterruptedException
Create a submodule in subdir child directory for remote repository- Parameters:
remoteURL
- aString
object.subdir
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
submoduleUpdate
@Deprecated void submoduleUpdate(boolean recursive) throws GitException, InterruptedException
Deprecated.Run submodule update optionally recursively on all submodules (equivalent ofgit submodule update --recursive
.)- Parameters:
recursive
- a boolean.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
submoduleUpdate
@Deprecated void submoduleUpdate(boolean recursive, String reference) throws GitException, InterruptedException
Deprecated.Run submodule update optionally recursively on all submodules, with a specific reference passed to git clone if needing to --init. (equivalent ofgit submodule update --recursive --reference 'reference'
.)- Parameters:
recursive
- a boolean.reference
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
submoduleUpdate
@Deprecated void submoduleUpdate(boolean recursive, boolean remoteTracking) throws GitException, InterruptedException
Deprecated.Run submodule update optionally recursively on all submodules, optionally with remoteTracking submodules (equivalent ofgit submodule update --recursive --remote
.)- Parameters:
recursive
- a boolean.remoteTracking
- a boolean.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
submoduleUpdate
@Deprecated void submoduleUpdate(boolean recursive, boolean remoteTracking, String reference) throws GitException, InterruptedException
Deprecated.Run submodule update optionally recursively on all submodules, optionally with remoteTracking, with a specific reference passed to git clone if needing to --init. (equivalent ofgit submodule update --recursive --remote --reference 'reference'
.)- Parameters:
recursive
- a boolean.remoteTracking
- a boolean.reference
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
submoduleUpdate
SubmoduleUpdateCommand submoduleUpdate()
submoduleUpdate.- Returns:
- a
SubmoduleUpdateCommand
object.
-
submoduleClean
void submoduleClean(boolean recursive) throws GitException, InterruptedException
submoduleClean.- Parameters:
recursive
- a boolean.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
submoduleInit
void submoduleInit() throws GitException, InterruptedException
submoduleInit.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
setupSubmoduleUrls
void setupSubmoduleUrls(Revision rev, TaskListener listener) throws GitException, InterruptedException
Set up submodule URLs so that they correspond to the remote pertaining to the revision that has been checked out.- Parameters:
rev
- aRevision
object.listener
- aTaskListener
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
changelog
@Deprecated void changelog(String revFrom, String revTo, OutputStream os) throws GitException, InterruptedException
Deprecated.changelog.- Parameters:
revFrom
- aString
object.revTo
- aString
object.os
- aOutputStream
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
changelog
void changelog(String revFrom, String revTo, Writer os) throws GitException, InterruptedException
Adds the changelog entries for commits in the range revFrom..revTo. This is just a short cut for callingchangelog()
with appropriate parameters.- Parameters:
revFrom
- aString
object.revTo
- aString
object.os
- aWriter
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
changelog
ChangelogCommand changelog()
Returns aChangelogCommand
to build up the git-log invocation.- Returns:
- a
ChangelogCommand
object.
-
appendNote
void appendNote(String note, String namespace) throws GitException, InterruptedException
Appends to an existing git-note on the current HEAD commit. If a note doesn't exist, it works just likeaddNote(String, String)
- Parameters:
note
- Content of the note.namespace
- If unqualified, interpreted as "refs/notes/NAMESPACE" just like cgit.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
addNote
void addNote(String note, String namespace) throws GitException, InterruptedException
Adds a new git-note on the current HEAD commit.- Parameters:
note
- Content of the note.namespace
- If unqualified, interpreted as "refs/notes/NAMESPACE" just like cgit.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
showRevision
List<String> showRevision(org.eclipse.jgit.lib.ObjectId r) throws GitException, InterruptedException
Given a Revision, show it as if it were an entry from git whatchanged, so that it can be parsed by GitChangeLogParser.Changes are computed on the [from..to] range. If
from
is null, this prints just one commit thatto
represents.For merge commit, this method reports one diff per each parent. This makes this method behave differently from
changelog()
.- Parameters:
r
- aObjectId
object.- Returns:
- The git whatchanged output, in
raw
format. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
showRevision
List<String> showRevision(org.eclipse.jgit.lib.ObjectId from, org.eclipse.jgit.lib.ObjectId to) throws GitException, InterruptedException
Given a Revision, show it as if it were an entry from git whatchanged, so that it can be parsed by GitChangeLogParser.Changes are computed on the [from..to] range. If
from
is null, this prints just one commit thatto
represents.For merge commit, this method reports one diff per each parent. This makes this method behave differently from
changelog()
.- Parameters:
from
- aObjectId
object.to
- aObjectId
object.- Returns:
- The git whatchanged output, in
raw
format. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
showRevision
List<String> showRevision(org.eclipse.jgit.lib.ObjectId from, org.eclipse.jgit.lib.ObjectId to, Boolean useRawOutput) throws GitException, InterruptedException
Given a Revision, show it as if it were an entry from git whatchanged, so that it can be parsed by GitChangeLogParser.If useRawOutput is true, the '--raw' option will include commit file information to be passed to the GitChangeLogParser.
Changes are computed on the [from..to] range. If
from
is null, this prints just one commit thatto
represents.For merge commit, this method reports one diff per each parent. This makes this method behave differently from
changelog()
.- Parameters:
from
- aObjectId
object.to
- aObjectId
object.useRawOutput
- a {java.lang.Boolean} object.- Returns:
- The git whatchanged output, in
raw
format. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
describe
String describe(String commitIsh) throws GitException, InterruptedException
Equivalent of "git-describe --tags". Find a nearby tag (including unannotated ones) and come up with a short identifier to describe the tag.- Parameters:
commitIsh
- aString
object.- Returns:
- a
String
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
setCredentials
void setCredentials(com.cloudbees.plugins.credentials.common.StandardUsernameCredentials cred)
setCredentials.- Parameters:
cred
- aStandardUsernameCredentials
object.
-
setProxy
void setProxy(ProxyConfiguration proxy)
setProxy.- Parameters:
proxy
- aProxyConfiguration
object.
-
getBranchesContaining
List<Branch> getBranchesContaining(String revspec, boolean allBranches) throws GitException, InterruptedException
Find all the branches that include the given commit.- Parameters:
revspec
- commit id to query forallBranches
- whether remote branches should be also queried (true
) or not (false
)- Returns:
- list of branches the specified commit belongs to
- Throws:
GitException
- on Git exceptionsInterruptedException
- on thread interruption
-
getTags
Set<GitObject> getTags() throws GitException, InterruptedException
Return name and object ID of all tags in current repository.- Returns:
- set of tags in current repository
- Throws:
GitException
- on Git exceptionsInterruptedException
- on thread interruption
-
maintenance
boolean maintenance(String task) throws InterruptedException
Executes git maintenance commands based on the git version.- Parameters:
task
- aString
object. i.e (prefetch/gc/commit-graph/incremental-repack/loose-objects)- Returns:
- Boolean if maintenance has been executed or not.
- Throws:
InterruptedException
- if underlying git operation fails.
-
-