Class CliGitAPIImpl
- All Implemented Interfaces:
IGitAPI
,Serializable
,GitClient
- Direct Known Subclasses:
GitAPI
Git
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jenkinsci.plugins.gitclient.GitClient
GitClient.ConfigLevel
-
Field Summary
Modifier and TypeFieldDescriptionprotected ProxyConfiguration
static final int
preventive Time-out for git command execution.static final boolean
Constant which can block use of setsid in git calls for ssh credentialed operations.protected final File
Fields inherited from interface org.jenkinsci.plugins.gitclient.GitClient
CREDENTIALS_MATCHER, quietRemoteBranches, verbose
-
Constructor Summary
ModifierConstructorDescriptionprotected
CliGitAPIImpl
(String gitExe, File workspace, TaskListener listener, EnvVars environment) Constructor for CliGitAPIImpl. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
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.changelog.void
changelog
(String revFrom, String revTo, OutputStream outputStream) Deprecated.void
Adds the changelog entries for commits in the range revFrom..revTo.checkout()
checkout.void
Deprecated.void
Deprecated.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()
Remove untracked files and directories, including files listed in the ignore rules.void
clean
(boolean cleanSubmodule) Remove untracked files and directories, including files listed in the ignore rules.void
clearCredentials.void
Clone a remote repositoryvoid
clone
(org.eclipse.jgit.transport.RemoteConfig source) Deprecated.void
clone
(org.eclipse.jgit.transport.RemoteConfig rc, boolean useShallowClone) Deprecated.clone_()
clone_.void
commit.void
commit
(String message, org.eclipse.jgit.lib.PersonIdent author, org.eclipse.jgit.lib.PersonIdent committer) Deprecated.void
config
(GitClient.ConfigLevel configLevel, String key, String value) Execute git config at the specified configuration level.void
deleteBranch
(String name) (force) delete a branch.void
Deletes a ref.void
deleteTag.Equivalent of "git-describe --tags".protected String
extractBranchNameFromBranchSpec
(String branchSpec) This method takes a branch specification and normalizes it get unambiguous results.void
fetch()
Deprecated.void
Deprecated.void
Deprecated.void
Deprecated.void
fetch
(org.eclipse.jgit.transport.RemoteConfig remoteRepository) Deprecated.void
Deprecated.fetch_()
fetch_.void
fixSubmoduleUrls
(String remote, TaskListener listener) fixSubmoduleUrls.getAllLogEntries
(String branch) Deprecated.Returns the set of branches defined in this repository, including local branches and remote branches.getBranchesContaining
(String revspec) Deprecated.getBranchesContaining
(String revspec, boolean allBranches) Find all the branches that include the given commit.Get the default remote.getDefaultRemote
(String _default_) Returns name of default remote.getHeadRev
(String url) getHeadRev.org.eclipse.jgit.lib.ObjectId
getHeadRev
(String url, String branchSpec) getHeadRev.getRefNames
(String refPrefix) List refs with the given prefix.Returns the remote branches defined in this repository.getRemoteReferences
(String url, String pattern, boolean headsOnly, boolean tagsOnly) List references in a remote repository.getRemoteSymbolicReferences
(String url, String pattern) List symbolic references in a remote repository.getRemoteTagNames
(String tagPattern) getRemoteTagNames.getRemoteUrl
(String name) From a given repository, get a remote's URLgetRemoteUrl
(String name, String GIT_DIR) Returns URL of remote name in repository GIT_DIR.org.eclipse.jgit.lib.Repository
Deprecated.Returns an executable file of ssh installed in WindowsgetSubmodulePath
(String name) Get submodule path.getSubmodules
(String treeIsh) Finds all the submodule references in this repository at the specified tree.getSubmoduleUrl
(String name) Returns URL of the named submodule.getTagMessage
(String tagName) getTagMessage.getTagNames
(String tagPattern) getTagNames.getTags()
Return name and object ID of all tags in current repository.getTagsOnCommit
(String revName) Deprecated.getWorkTree.boolean
hasGitModules.boolean
hasGitModules
(String treeIsh) Deprecated.boolean
Returns true if this workspace has a git repository.boolean
hasGitRepo
(boolean checkParentDirectories) Returns true if this workspace has a git repository.boolean
hasGitRepo
(String GIT_DIR) Returns true if the parameter GIT_DIR is a directory which contains a git repository.void
init()
Initialize an empty repository for further git operations.init_()
init_.boolean
isBareRepository.boolean
isBareRepository
(String GIT_DIR) Detect whether a repository at the given path is bare or not.boolean
isCliGitVerAtLeast
(int major, int minor, int rev, int bugfix) Compare the current cli git version with the required version.boolean
isCommitInRepo
(org.eclipse.jgit.lib.ObjectId commit) isCommitInRepo.boolean
Returns true if this repository is configured as a shallow clone.Launch command using the workspace as working directorylaunchCommand
(String... args) Launch command using the workspace as working directoryfinal List<IndexEntry>
Deprecated.lsTree.boolean
maintenance
(String task) Executes git maintenance commands based on the git version.merge()
merge.void
Deprecated.void
merge
(org.eclipse.jgit.lib.ObjectId rev) Deprecated.org.eclipse.jgit.lib.ObjectId
mergeBase
(org.eclipse.jgit.lib.ObjectId id1, org.eclipse.jgit.lib.ObjectId id2) Deprecated.void
prune
(org.eclipse.jgit.transport.RemoteConfig repository) Prune stale remote tracking branches with "git remote prune" on the specified remote.push()
push.void
Deprecated.void
Deprecated.void
Deprecated.rebase()
rebase.void
Create (or update) a ref.boolean
Check if a ref exists.protected org.jenkinsci.plugins.gitclient.RemoteGitImpl
remoteProxyFor
(GitClient proxy) remoteProxyFor.void
reset()
Deprecated.void
reset
(boolean hard) Reset the contents of the working directory of this repository.List<org.eclipse.jgit.lib.ObjectId>
revList.revList_()
revList_.List<org.eclipse.jgit.lib.ObjectId>
revListAll.List<org.eclipse.jgit.lib.ObjectId>
revListBranch
(String branchId) Deprecated.org.eclipse.jgit.lib.ObjectId
Retrieve commit object that is direct child forrevName
revision reference.void
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
setHostKeyFactory
(HostKeyVerifierFactory verifier) void
setProxy
(ProxyConfiguration proxy) setProxy.void
setRemoteUrl
(String name, String url) For a given repository, set a remote's URLvoid
setRemoteUrl
(String name, String url, String GIT_DIR) Set remote repository name and URL.void
setSubmoduleUrl
(String name, String url) Sets URL of the named submodule.void
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.void
setupSubmoduleUrls
(String remote, TaskListener listener) Deprecated.Deprecated.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.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.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.subGit.void
submoduleClean
(boolean recursive) submoduleClean.void
submoduleInit.void
submoduleReset
(boolean recursive, boolean hard) Reset submodulesvoid
Sync submodule URLsUpdate submodules.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
Create (or update) a tag.boolean
tagExists.org.eclipse.jgit.lib.ObjectId
validateRevision
(String revName) validateRevision.<T> T
withRepository
(RepositoryCallback<T> callable) Runs the computation that requires local access toRepository
.protected Object
When sent to remote, switch to the proxy.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jenkinsci.plugins.gitclient.GitClient
changelog, checkout, checkout, clone, commit, merge, setAuthor, setCommitter, setCredentials, setProxy, submoduleUpdate, submoduleUpdate, submoduleUpdate, submoduleUpdate, withRepository
Methods inherited from interface hudson.plugins.git.IGitAPI
changelog, checkoutBranch
-
Field Details
-
USE_SETSID
public static final boolean USE_SETSIDConstant which can block use of setsid in git calls for ssh credentialed operations.USE_SETSID=Boolean.valueOf(System.getProperty(CliGitAPIImpl.class.getName() + ".useSETSID", "false"))
. Allow ssh authenticated git calls on Unix variants to be preceded by setsid so that the git command is run without being associated with a terminal. Some docker runtime cases, and some automated test cases have shown that some versions of command line git or ssh will not allow automatic answers to private key passphrase prompts unless there is no controlling terminal associated with the process. -
TIMEOUT
public static final int TIMEOUTpreventive Time-out for git command execution.We run git as an external process so can't guarantee it won't hang for whatever reason. Even though the plugin does its best to avoid git interactively asking for credentials, there are many of other cases where git may hang.
-
workspace
-
proxy
-
-
Constructor Details
-
CliGitAPIImpl
Constructor for CliGitAPIImpl.- Parameters:
gitExe
- aString
object.workspace
- aFile
object.listener
- aTaskListener
object.environment
- aEnvVars
object.
-
-
Method Details
-
isCliGitVerAtLeast
public boolean isCliGitVerAtLeast(int major, int minor, int rev, int bugfix) Compare the current cli git version with the required version. Finds if the current cli git version is at-least the required version. Returns True if the current cli git version is at least the required version.- Parameters:
major
- required major version for command line gitminor
- required minor version for command line gitrev
- required revision for command line gitbugfix
- required patches for command line git- Returns:
- true if the command line git version is at least the required version
-
subGit
subGit.- Parameters:
subdir
- aString
object.- Returns:
- a IGitAPI implementation to manage git submodule repository
-
init
Initialize an empty repository for further git operations.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
hasGitRepo
Returns true if this workspace has a git repository. Also returns true if this workspace contains an empty .git directory and a parent directory has a git repository.- Returns:
- true if this workspace has a git repository
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
hasGitRepo
Returns true if this 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.
-
hasGitRepo
Returns true if the parameter GIT_DIR is a directory which contains a git repository.- Parameters:
GIT_DIR
- aString
object.- Returns:
- true if GIT_DIR has a git repository
- Throws:
GitException
- if underlying git operation fails.
-
getSubmodules
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.
-
fetch_
fetch_.- Returns:
- a
FetchCommand
object.
-
fetch
@Deprecated public void fetch(org.eclipse.jgit.transport.URIish url, List<org.eclipse.jgit.transport.RefSpec> refspecs) throws GitException, InterruptedException Deprecated.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 public void fetch(String remoteName, org.eclipse.jgit.transport.RefSpec... refspec) throws GitException, InterruptedException Deprecated.fetch.- Parameters:
remoteName
- aString
object.refspec
- aRefSpec
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
fetch
@Deprecated public void fetch(String remoteName, org.eclipse.jgit.transport.RefSpec refspec) throws GitException, InterruptedException Deprecated.fetch.- Parameters:
remoteName
- aString
object.refspec
- aRefSpec
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
reset
Reset the contents of the working directory of this repository. Refer to git reset documentation.- Parameters:
hard
- reset as though "--hard" were passed to "git reset"- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
clone_
clone_.- Returns:
- a
CloneCommand
object.
-
merge
merge.- Returns:
- a
MergeCommand
object.
-
rebase
rebase.- Returns:
- a
RebaseCommand
object.
-
init_
init_.- Returns:
- a
InitCommand
object.
-
clean
Remove untracked files and directories, including files listed in the ignore rules.- Parameters:
cleanSubmodule
- flag to add extra -f- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
clean
Remove untracked files and directories, including files listed in the ignore rules.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
revParse
public 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.
-
validateRevision
public org.eclipse.jgit.lib.ObjectId validateRevision(String revName) throws GitException, InterruptedException validateRevision.- Parameters:
revName
- aString
object.- Returns:
- a
ObjectId
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
describe
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.
-
prune
public 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.
-
changelog
changelog.- Returns:
- a
ChangelogCommand
object.
-
showRevision
public 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
GitClient.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
public 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
GitClient.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.
-
submoduleInit
submoduleInit.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
addSubmodule
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.
-
submoduleSync
Sync submodule URLs- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
submoduleUpdate
Update submodules.- Returns:
- a
SubmoduleUpdateCommand
object.
-
submoduleReset
public void submoduleReset(boolean recursive, boolean hard) throws GitException, InterruptedException Reset submodules- Parameters:
recursive
- if true, will recursively reset submodules (requires git>=1.6.5)hard
- if true, the --hard argument will be passed to submodule reset- Throws:
GitException
- if executing the git command failsInterruptedException
- if git command interrupted
-
submoduleClean
submoduleClean. Cleans submodules- Parameters:
recursive
- a boolean.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getSubmoduleUrl
Returns URL of the named submodule. Get submodule URL- Parameters:
name
- submodule name whose URL will be returned- Returns:
- URL of the named submodule
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
setSubmoduleUrl
Sets URL of the named submodule. Set submodule URL- Parameters:
name
- submodule name whose URL will be seturl
- URL for the named submodule- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getSubmodulePath
Get submodule path.- Parameters:
name
- submodule name whose path is returned- Returns:
- path to submodule
- Throws:
GitException
- on git errorInterruptedException
- if interrupted
-
getRemoteUrl
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
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
addRemoteUrl.- Parameters:
name
- aString
object.url
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getRemoteUrl
Returns URL of remote name in repository GIT_DIR.- Parameters:
name
- name for the remote repository, for example, "origin"GIT_DIR
- directory containing git repository- Returns:
- URL of remote "name" in repository GIT_DIR.
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
setRemoteUrl
public void setRemoteUrl(String name, String url, String GIT_DIR) throws GitException, InterruptedException Set remote repository name and URL.- Parameters:
name
- name for the remote repository, for example, "origin"url
- URL for the remote repository, for example https://github.com/jenkinsci/git-client-plugin.gitGIT_DIR
- directory containing git repository- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getDefaultRemote
Returns name of default remote.- Parameters:
_default_
- value to return if no remote is defined in this repository- Returns:
- name of default remote
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getDefaultRemote
Get the default remote.- Returns:
- default git remote for this repository (often "origin")
- Throws:
GitException
- if executing the git command failsInterruptedException
- if interrupted
-
isBareRepository
Detect whether a repository at the given path is bare or not.- Parameters:
GIT_DIR
- The path to the repository (must be to .git dir).- Returns:
- true if this repository is bare
- Throws:
GitException
- on failureInterruptedException
- if interrupted
-
isShallowRepository
public boolean isShallowRepository()Returns true if this repository is configured as a shallow clone.- Returns:
- true if this repository is configured as a shallow clone
-
fixSubmoduleUrls
public void fixSubmoduleUrls(String remote, TaskListener listener) throws GitException, InterruptedException fixSubmoduleUrls. Fixes urls for submodule as stored in .git/config and $SUBMODULE/.git/config for when the remote repo is NOT a bare repository. It is only really possible to detect whether a repository is bare if we have local access to the repository. If the repository is remote, we therefore must default to believing that it is either bare or NON-bare. The defaults are according to the ending of the super-project remote.origin.url: - Ends with "/.git": default is NON-bare - otherwise: default is bare .- Parameters:
remote
- aString
object.listener
- aTaskListener
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
setupSubmoduleUrls
public 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. 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.
-
tag
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.
-
appendNote
Appends to an existing git-note on the current HEAD commit. If a note doesn't exist, it works just likeGitClient.addNote(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
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.
-
launchCommand
Launch command using the workspace as working directory- Parameters:
args
- arguments to the command- Returns:
- command output
- Throws:
GitException
- if launched command failsInterruptedException
- if interrupted
-
launchCommand
Launch command using the workspace as working directory- Parameters:
args
- command argumnents- Returns:
- command output
- Throws:
GitException
- on failureInterruptedException
- if interrupted
-
getSSHExecutable
Returns an executable file of ssh installed in Windows- Returns:
- File The ssh executable file
File
-
push
push.- Returns:
- a
PushCommand
object.
-
getBranches
Returns the set of branches defined in this repository, including local branches and remote branches. Remote branches are prefixed by "remotes/".- Returns:
- a
Set
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getRemoteBranches
Returns the remote branches defined in this repository.- Returns:
Set
of remote branches in this repository- Throws:
GitException
- if underlying git operation failsInterruptedException
- if interrupted
-
checkout
checkout.- Returns:
- a
CheckoutCommand
object.
-
tagExists
tagExists.- Parameters:
tagName
- aString
object.- Returns:
- true if tag exists in repository
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
deleteBranch
(force) delete a branch.- Parameters:
name
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
deleteTag
deleteTag.- Parameters:
tagName
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
lsTree
public List<IndexEntry> lsTree(String treeIsh, boolean recursive) throws GitException, InterruptedException lsTree.- Parameters:
treeIsh
- aString
object.recursive
- a boolean.- Returns:
- a
List
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
revList_
revList_.- Returns:
- a
RevListCommand
object.
-
revListAll
revListAll.- Returns:
- a
List
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
revList
public 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.
-
isCommitInRepo
public 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.
-
add
add.- Parameters:
filePattern
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
branch
branch.- Parameters:
name
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
commit
commit.- Parameters:
message
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
addCredentials
public 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.
-
clearCredentials
public void clearCredentials()clearCredentials. -
addDefaultCredentials
public 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.- See Also:
-
setAuthor
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.
-
setCommitter
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.
-
getRepository
Deprecated.Returns theRepository
used by this git instance.- Returns:
- a
Repository
object. - Throws:
GitException
- if underlying git operation fails.
-
getWorkTree
getWorkTree.- Returns:
- a
FilePath
object.
-
getRemoteTagNames
getRemoteTagNames.- Parameters:
tagPattern
- aString
object.- Returns:
- a
Set
object. - Throws:
GitException
- if underlying git operation fails.
-
getTagNames
getTagNames.- Parameters:
tagPattern
- aString
object.- Returns:
- a
Set
object. - Throws:
GitException
- if underlying git operation fails.
-
getTagMessage
getTagMessage.- Parameters:
tagName
- aString
object.- Returns:
- a
String
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
ref
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
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 otherwise.
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
deleteRef
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
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
public 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
public org.eclipse.jgit.lib.ObjectId getHeadRev(String url, String branchSpec) throws GitException, InterruptedException getHeadRev.- Parameters:
url
- aString
object.branchSpec
- aString
object.- Returns:
- a
ObjectId
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getRemoteReferences
public Map<String,org.eclipse.jgit.lib.ObjectId> getRemoteReferences(String url, String pattern, boolean headsOnly, boolean tagsOnly) throws GitException, InterruptedException List references in a remote repository. Equivalent togit ls-remote [--heads] [--tags] <repository> [<refs>]
.- Parameters:
url
- 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
public Map<String,String> getRemoteSymbolicReferences(String url, String pattern) throws GitException, InterruptedException Description copied from interface:GitClient
List symbolic references in a remote repository. Equivalent togit ls-remote --symref <repository> [<refs>]
. Note: the response may be empty for multiple reasons- Parameters:
url
- 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 or if the command line git version does not support reporting symbolic references.
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
merge
Deprecated.Merge commits from revspec into the current branch.- Parameters:
refSpec
- the revision specification to be merged (for example, origin/main)- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
push
@Deprecated public void push(org.eclipse.jgit.transport.RemoteConfig repository, String refspec) throws GitException, InterruptedException Deprecated.Push revspec to repository.- Parameters:
repository
- git repository to receive commitsrefspec
- commits to be pushed- Throws:
GitException
- if underlying git operating failsInterruptedException
- if interrupted
-
getBranchesContaining
@Deprecated public List<Branch> getBranchesContaining(String revspec) throws GitException, InterruptedException Deprecated.Find all the branches that include the given commit.- Parameters:
revspec
- substring to be searched for branch name- Returns:
- list of branches containing revspec
- Throws:
GitException
- on failureInterruptedException
- if interrupted
-
getBranchesContaining
public 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
-
mergeBase
@Deprecated public org.eclipse.jgit.lib.ObjectId mergeBase(org.eclipse.jgit.lib.ObjectId id1, org.eclipse.jgit.lib.ObjectId id2) throws GitException, InterruptedException Deprecated.mergeBase.- Parameters:
id1
- aObjectId
object.id2
- aObjectId
object.- Returns:
- a
ObjectId
object. - Throws:
InterruptedException
- if interrupted.GitException
-
getAllLogEntries
Deprecated.This method makes no sense, in that it lists all log entries across all refs and yet it takes a meaningless 'branch' parameter. Please do not use this.- Parameters:
branch
- aString
object.- Returns:
- a
String
object. - Throws:
InterruptedException
- if interrupted.GitException
-
getTags
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
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.
-
config
public void config(GitClient.ConfigLevel configLevel, String key, String value) throws GitException, InterruptedException Execute git config at the specified configuration level. If value is null, the key will be removed from the configuration.- Parameters:
configLevel
- configuration level that will be modified. If null, thenGitClient.ConfigLevel.LOCAL
will be used.key
- configuration section expressed assection[.subsection].name
value
- configuration value. If null, the key will be removed from the configuration (unset)- Throws:
GitException
- on Git exceptionInterruptedException
- on thread interruption
-
isBareRepository
isBareRepository.- Specified by:
isBareRepository
in interfaceIGitAPI
- Returns:
- true if this repository is a bare repository
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getHostKeyFactory
-
setHostKeyFactory
-
hasGitModules
Deprecated.Returns true if this repository has submodules.- Specified by:
hasGitModules
in interfaceIGitAPI
- Parameters:
treeIsh
- an ignored argument, kept for compatibility- Returns:
- true if this repository has submodules (git modules file)
- Throws:
GitException
- if underlying git operation fails.- See Also:
-
setupSubmoduleUrls
@Deprecated public void setupSubmoduleUrls(String remote, TaskListener listener) throws GitException, InterruptedException Deprecated.- Specified by:
setupSubmoduleUrls
in interfaceIGitAPI
- Throws:
GitException
InterruptedException
-
fetch
@Deprecated public void fetch(String repository, String refspec) throws GitException, InterruptedException Deprecated.Retrieve commits based on refspec from repository.- Specified by:
fetch
in interfaceIGitAPI
- Parameters:
repository
- URL of the repository to be retrievedrefspec
- definition of mapping from remote refs to local refs- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
fetch
@Deprecated public void fetch(org.eclipse.jgit.transport.RemoteConfig remoteRepository) throws GitException, InterruptedException Deprecated.Retrieve commits from RemoteConfig.- Specified by:
fetch
in interfaceIGitAPI
- Parameters:
remoteRepository
- remote configuration from which refs will be retrieved- Throws:
InterruptedException
- if interrupted.GitException
-
fetch
Deprecated.fetch.- Specified by:
fetch
in interfaceIGitAPI
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
reset
Deprecated.reset.- Specified by:
reset
in interfaceIGitAPI
- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
push
@Deprecated public void push(org.eclipse.jgit.transport.URIish url, String refspec) throws GitException, InterruptedException Deprecated.push.- Specified by:
push
in interfaceGitClient
- Parameters:
url
- aURIish
object.refspec
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
push
@Deprecated public void push(String remoteName, String refspec) throws GitException, InterruptedException Deprecated.push.- Specified by:
push
in interfaceGitClient
- Parameters:
remoteName
- aString
object.refspec
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
clone
@Deprecated public void clone(org.eclipse.jgit.transport.RemoteConfig source) throws GitException, InterruptedException Deprecated.Clone repository from source to this repository.- Specified by:
clone
in interfaceIGitAPI
- Parameters:
source
- remote repository to be cloned- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
clone
@Deprecated public void clone(org.eclipse.jgit.transport.RemoteConfig rc, boolean useShallowClone) throws GitException, InterruptedException Deprecated.Clone repository fromRemoteConfig
rc to this repository.- Specified by:
clone
in interfaceIGitAPI
- Parameters:
rc
- the remote config for the remote repositoryuseShallowClone
- if true, use a shallow clone- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
revListBranch
@Deprecated public List<org.eclipse.jgit.lib.ObjectId> revListBranch(String branchId) throws GitException, InterruptedException Deprecated.revListBranch.- Specified by:
revListBranch
in interfaceIGitAPI
- Parameters:
branchId
- aString
object.- Returns:
- a
List
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
showRevision
Deprecated.showRevision.- Specified by:
showRevision
in interfaceIGitAPI
- Parameters:
r
- aRevision
object.- Returns:
- a
List
object. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
getTagsOnCommit
Deprecated.getTagsOnCommit.- Specified by:
getTagsOnCommit
in interfaceIGitAPI
- Parameters:
revName
- aString
object.- Returns:
- a
List
object. - Throws:
GitException
- if underlying git operation fails.IOException
- if any IO failure
-
lsTree
@Deprecated public final List<IndexEntry> lsTree(String treeIsh) throws GitException, InterruptedException Deprecated.This method has been implemented as non-recursive historically, but often that is not what the caller wants.- Specified by:
lsTree
in interfaceIGitAPI
- Parameters:
treeIsh
- string representation of a treeIsh item- Returns:
- list of IndexEntry items starting at treeIsh
- Throws:
GitException
- on failureInterruptedException
- if interrupted
-
writeReplace
When sent to remote, switch to the proxy.- Returns:
- a
Object
object. - Throws:
ObjectStreamException
- if current channel is null
-
hasGitModules
hasGitModules.- Specified by:
hasGitModules
in interfaceGitClient
- Returns:
- true if this repositor has one or more submodules
- Throws:
GitException
- if underlying git operation fails.
-
showRevision
public 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
GitClient.changelog()
.- Specified by:
showRevision
in interfaceGitClient
- Parameters:
r
- aObjectId
object.- Returns:
- The git whatchanged output, in
raw
format. - Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
extractBranchNameFromBranchSpec
This method takes a branch specification and normalizes it get unambiguous results. This is the case when using "refs/heads/"
TODO: Currently only for specs starting with "refs/heads/" the implementation is correct. All others branch specs should also be normalized to "refs/heads/" in order to get unambiguous results. To achieve this it is necessary to identify remote names in the branch spec and to discuss how to handle clashes (e.g. "remoteName/main" for branch "main" (refs/heads/main) in remote "remoteName" and branch "remoteName/main" (refs/heads/remoteName/main)).
Existing behavior is intentionally being retained so that current use cases are not disrupted by a behavioral change.
E.g.Branch Spec Normalization Examples branch spec normalized main
main*
feature1
feature1*
feature1/main
mainfeature1/main
*origin/main
main*
repo2/feature1
feature1*
refs/heads/feature1
refs/heads/feature1
origin/namespaceA/fix15 fix15namespaceA/fix15
*refs/heads/namespaceA/fix15
refs/heads/namespaceA/fix15
remotes/origin/namespaceA/fix15
refs/heads/namespaceA/fix15
*) TODO: Normalize to "refs/heads/"- Parameters:
branchSpec
- aString
object.- Returns:
- normalized branch name
-
withRepository
public <T> T withRepository(RepositoryCallback<T> callable) throws GitException, IOException, InterruptedException Runs the computation that requires local access toRepository
.- Specified by:
withRepository
in interfaceGitClient
- 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 interruptedGitException
-
commit
@Deprecated public void commit(String message, org.eclipse.jgit.lib.PersonIdent author, org.eclipse.jgit.lib.PersonIdent committer) throws GitException, InterruptedException Deprecated.commit.- Specified by:
commit
in interfaceGitClient
- Parameters:
message
- aString
object.author
- aPersonIdent
object.committer
- aPersonIdent
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
setAuthor
setAuthor.- Specified by:
setAuthor
in interfaceGitClient
- Parameters:
p
- aPersonIdent
object.- Throws:
GitException
- if underlying git operation fails.
-
setCommitter
setCommitter.- Specified by:
setCommitter
in interfaceGitClient
- Parameters:
p
- aPersonIdent
object.- Throws:
GitException
- if underlying git operation fails.
-
changelog
@Deprecated public void changelog(String revFrom, String revTo, OutputStream outputStream) throws GitException, InterruptedException Deprecated.changelog.- Specified by:
changelog
in interfaceGitClient
- Parameters:
revFrom
- aString
object.revTo
- aString
object.outputStream
- aOutputStream
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
changelog
public void changelog(String revFrom, String revTo, Writer w) throws GitException, InterruptedException Adds the changelog entries for commits in the range revFrom..revTo. This is just a short cut for callingGitClient.changelog()
with appropriate parameters.- Specified by:
changelog
in interfaceGitClient
- Parameters:
revFrom
- aString
object.revTo
- aString
object.w
- aWriter
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
clone
public void clone(String url, String origin, boolean useShallowClone, String reference) throws GitException, InterruptedException Clone a remote repository- Specified by:
clone
in interfaceGitClient
- 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.
-
checkout
Deprecated.Checks out the specified commit/tag/branch into the workspace. (equivalent ofgit checkout branch
.)- Specified by:
checkout
in interfaceGitClient
- Parameters:
commit
- A git object references expression (either a sha1, tag or branch)- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
checkout
@Deprecated public void checkout(String ref, String branch) throws GitException, InterruptedException Deprecated.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.- Specified by:
checkout
in interfaceGitClient
- 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.
-
checkoutBranch
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
GitClient.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
GitClient.checkout(String, String)
.- Specified by:
checkoutBranch
in interfaceGitClient
- Parameters:
branch
- aString
object.ref
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
merge
@Deprecated public void merge(org.eclipse.jgit.lib.ObjectId rev) throws GitException, InterruptedException Deprecated.merge.- Specified by:
merge
in interfaceGitClient
- Parameters:
rev
- aObjectId
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
remoteProxyFor
remoteProxyFor.- Parameters:
proxy
- aGitClient
object.- Returns:
- a
RemoteGitImpl
object.
-
setCredentials
public void setCredentials(com.cloudbees.plugins.credentials.common.StandardUsernameCredentials cred) setCredentials.- Specified by:
setCredentials
in interfaceGitClient
- Parameters:
cred
- aStandardUsernameCredentials
object.
-
setProxy
setProxy.- Specified by:
setProxy
in interfaceGitClient
- Parameters:
proxy
- aProxyConfiguration
object.
-
submoduleUpdate
@Deprecated public void submoduleUpdate(boolean recursive) throws GitException, InterruptedException Deprecated.Run submodule update optionally recursively on all submodules (equivalent ofgit submodule update --recursive
.)- Specified by:
submoduleUpdate
in interfaceGitClient
- Parameters:
recursive
- a boolean.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
submoduleUpdate
@Deprecated public 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'
.)- Specified by:
submoduleUpdate
in interfaceGitClient
- Parameters:
recursive
- a boolean.reference
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
submoduleUpdate
@Deprecated public 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
.)- Specified by:
submoduleUpdate
in interfaceGitClient
- Parameters:
recursive
- a boolean.remoteTracking
- a boolean.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-
submoduleUpdate
@Deprecated public 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'
.)- Specified by:
submoduleUpdate
in interfaceGitClient
- Parameters:
recursive
- a boolean.remoteTracking
- a boolean.reference
- aString
object.- Throws:
GitException
- if underlying git operation fails.InterruptedException
- if interrupted.
-