org.jenkinsci.plugins.gitclient
Class CliGitAPIImpl

java.lang.Object
  extended by org.jenkinsci.plugins.gitclient.CliGitAPIImpl
All Implemented Interfaces:
GitClient
Direct Known Subclasses:
GitAPI

public class CliGitAPIImpl
extends Object
implements GitClient

Implementation class using command line CLI ran as external command. For internal use only, dont use directly. See Git


Field Summary
 
Fields inherited from interface org.jenkinsci.plugins.gitclient.GitClient
verbose
 
Constructor Summary
protected CliGitAPIImpl(String gitExe, File workspace, hudson.model.TaskListener listener, hudson.EnvVars environment)
           
 
Method Summary
 void add(String filePattern)
           
 void addNote(String note, String namespace)
           
 void addSubmodule(String remoteURL, String subdir)
          Create a submodule in subdir child directory for remote repository
 void appendNote(String note, String namespace)
           
 void branch(String name)
           
 void changelog(String revFrom, String revTo, OutputStream outputStream)
          Adds the changelog entries for commits in the range revFrom..revTo.
 void checkout(String commit)
          Checks out the specified commit/tag/branch into the workspace.
 void checkout(String ref, String branch)
          Checks out the specified commit/ref into the workspace, creating specified branch (equivalent to git checkout -b branch commit
 void clean()
          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.
 void clone(String url, String origin, boolean useShallowClone, String reference)
          Clone a remote repository
 void commit(String message)
           
 void commit(String message, org.eclipse.jgit.lib.PersonIdent author, org.eclipse.jgit.lib.PersonIdent committer)
           
 void deleteBranch(String name)
          (force) delete a branch.
 void deleteTag(String tagName)
           
 String describe(String commitIsh)
           
 void fetch()
           
 void fetch(String remoteName, org.eclipse.jgit.transport.RefSpec refspec)
          Fetch a remote repository.
 void fixSubmoduleUrls(String remote, hudson.model.TaskListener listener)
          Fixes urls for submodule as stored in .git/config and $SUBMODULE/.git/config for when the remote repo is NOT a bare repository.
 Set<Branch> getBranches()
           
 String getDefaultRemote()
          Get the default remote.
 String getDefaultRemote(String _default_)
           
 org.eclipse.jgit.lib.ObjectId getHeadRev(String remoteRepoUrl, String branch)
           
 Set<Branch> getRemoteBranches()
           
 String getRemoteUrl(String name)
          From a given repository, get a remote's URL
 String getRemoteUrl(String name, String GIT_DIR)
           
 org.eclipse.jgit.lib.Repository getRepository()
          Expose the JGit repository this GitClient is using.
 List<IndexEntry> getSubmodules(String treeIsh)
           
 String getSubmoduleUrl(String name)
          Get submodule URL
 String getTagMessage(String tagName)
           
 Set<String> getTagNames(String tagPattern)
           
 boolean hasGitModules()
          Returns true if the repository has Git submodules.
 boolean hasGitRepo()
           
 boolean hasGitRepo(String GIT_DIR)
           
 void init()
           
 boolean isBareRepository()
          Detect whether a repository is bare or not.
 boolean isBareRepository(String GIT_DIR)
          Detect whether a repository at the given path is bare or not.
 boolean isCommitInRepo(org.eclipse.jgit.lib.ObjectId commit)
           
 String launchCommand(hudson.util.ArgumentListBuilder args)
          Launch command using the workspace as working directory
 String launchCommand(String... args)
          Launch command using the workspace as working directory
 List<IndexEntry> lsTree(String treeIsh)
           
 void merge(org.eclipse.jgit.lib.ObjectId rev)
          Merge any changes into the head.
 void prune(org.eclipse.jgit.transport.RemoteConfig repository)
           
 void push(String remoteName, String refspec)
           
 void reset(boolean hard)
           
 List<org.eclipse.jgit.lib.ObjectId> revList(String ref)
           
 List<org.eclipse.jgit.lib.ObjectId> revListAll()
           
 org.eclipse.jgit.lib.ObjectId revParse(String revName)
          Retrieve commit object that is direct child for revName revision reference.
 void setRemoteUrl(String name, String url)
          For a given repository, set a remote's URL
 void setRemoteUrl(String name, String url, String GIT_DIR)
           
 void setSubmoduleUrl(String name, String url)
          Set submodule URL
 void setupSubmoduleUrls(Revision rev, hudson.model.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)
           
 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.
 GitClient subGit(String subdir)
           
 void submoduleClean(boolean recursive)
          Cleans submodules
 void submoduleInit()
           
 void submoduleReset(boolean recursive, boolean hard)
          Reset submodules
 void submoduleSync()
          Sync submodule URLs
 void submoduleUpdate(boolean recursive)
          Update submodules.
 void tag(String tagName, String comment)
          Create (or update) a tag.
 boolean tagExists(String tagName)
           
 org.eclipse.jgit.lib.ObjectId validateRevision(String revName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CliGitAPIImpl

protected CliGitAPIImpl(String gitExe,
                        File workspace,
                        hudson.model.TaskListener listener,
                        hudson.EnvVars environment)
Method Detail

subGit

public GitClient subGit(String subdir)
Specified by:
subGit in interface GitClient
Returns:
a IGitAPI implementation to manage git submodule repository

init

public void init()
          throws GitException
Specified by:
init in interface GitClient
Throws:
GitException

hasGitRepo

public boolean hasGitRepo()
                   throws GitException
Specified by:
hasGitRepo in interface GitClient
Throws:
GitException

hasGitRepo

public boolean hasGitRepo(String GIT_DIR)
                   throws GitException
Throws:
GitException

hasGitModules

public boolean hasGitModules()
                      throws GitException
Description copied from interface: GitClient
Returns true if the repository has Git submodules.

Specified by:
hasGitModules in interface GitClient
Throws:
GitException

getSubmodules

public List<IndexEntry> getSubmodules(String treeIsh)
                               throws GitException
Specified by:
getSubmodules in interface GitClient
Throws:
GitException

fetch

public void fetch(String remoteName,
                  org.eclipse.jgit.transport.RefSpec refspec)
           throws GitException
Description copied from interface: GitClient
Fetch a remote repository. Assumes remote.remoteName.url has been set.

Specified by:
fetch in interface GitClient
Throws:
GitException

fetch

public void fetch()
           throws GitException
Throws:
GitException

reset

public void reset(boolean hard)
           throws GitException
Throws:
GitException

clone

public void clone(String url,
                  String origin,
                  boolean useShallowClone,
                  String reference)
           throws GitException
Description copied from interface: GitClient
Clone a remote repository

Specified by:
clone in interface GitClient
Parameters:
url - URL for remote repository to clone
origin - upstream track name, defaults to origin by convention
useShallowClone - option to create a shallow clone, that has some restriction but will make clone operation
reference - (optional) reference to a local clone for faster clone operations (reduce network and local storage costs)
Throws:
GitException

clean

public void clean()
           throws GitException
Description copied from interface: GitClient
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.

Specified by:
clean in interface GitClient
Throws:
GitException

revParse

public org.eclipse.jgit.lib.ObjectId revParse(String revName)
                                       throws GitException
Description copied from interface: GitClient
Retrieve commit object that is direct child for revName revision reference.

Specified by:
revParse in interface GitClient
Parameters:
revName - a commit sha1 or tag/branch refname
Throws:
GitException - when no such commit / revName is found in repository.

validateRevision

public org.eclipse.jgit.lib.ObjectId validateRevision(String revName)
                                               throws GitException
Throws:
GitException

describe

public String describe(String commitIsh)
                throws GitException
Throws:
GitException

prune

public void prune(org.eclipse.jgit.transport.RemoteConfig repository)
           throws GitException
Specified by:
prune in interface GitClient
Throws:
GitException

changelog

public void changelog(String revFrom,
                      String revTo,
                      OutputStream outputStream)
               throws GitException
Description copied from interface: GitClient
Adds the changelog entries for commits in the range revFrom..revTo.

Specified by:
changelog in interface GitClient
Throws:
GitException

showRevision

public List<String> showRevision(org.eclipse.jgit.lib.ObjectId r)
                          throws GitException
Specified by:
showRevision in interface GitClient
Throws:
GitException

showRevision

public List<String> showRevision(org.eclipse.jgit.lib.ObjectId from,
                                 org.eclipse.jgit.lib.ObjectId to)
                          throws GitException
Description copied from interface: GitClient
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.

Specified by:
showRevision in interface GitClient
Returns:
The git show output, in raw format.
Throws:
GitException

merge

public void merge(org.eclipse.jgit.lib.ObjectId rev)
           throws GitException
Merge any changes into the head.

Specified by:
merge in interface GitClient
Parameters:
rev - the revision
Throws:
GitException - if the emrge fails

submoduleInit

public void submoduleInit()
                   throws GitException
Throws:
GitException

addSubmodule

public void addSubmodule(String remoteURL,
                         String subdir)
                  throws GitException
Description copied from interface: GitClient
Create a submodule in subdir child directory for remote repository

Specified by:
addSubmodule in interface GitClient
Throws:
GitException

submoduleSync

public void submoduleSync()
                   throws GitException
Sync submodule URLs

Throws:
GitException

submoduleUpdate

public void submoduleUpdate(boolean recursive)
                     throws GitException
Update submodules.

Specified by:
submoduleUpdate in interface GitClient
Parameters:
recursive - if true, will recursively update submodules (requires git>=1.6.5)
Throws:
GitException - if executing the Git command fails

submoduleReset

public void submoduleReset(boolean recursive,
                           boolean hard)
                    throws GitException
Reset submodules

Parameters:
recursive - if true, will recursively reset submodules (requres git>=1.6.5)
Throws:
GitException - if executing the git command fails

submoduleClean

public void submoduleClean(boolean recursive)
                    throws GitException
Cleans submodules

Specified by:
submoduleClean in interface GitClient
Parameters:
recursive - if true, will recursively clean submodules (requres git>=1.6.5)
Throws:
GitException - if executing the git command fails

getSubmoduleUrl

public String getSubmoduleUrl(String name)
                       throws GitException
Get submodule URL

Parameters:
name - The name of the submodule
Throws:
GitException - if executing the git command fails

setSubmoduleUrl

public void setSubmoduleUrl(String name,
                            String url)
                     throws GitException
Set submodule URL

Parameters:
name - The name of the submodule
url - The new value of the submodule's URL
Throws:
GitException - if executing the git command fails

getRemoteUrl

public String getRemoteUrl(String name)
                    throws GitException
Description copied from interface: GitClient
From a given repository, get a remote's URL

Specified by:
getRemoteUrl in interface GitClient
Parameters:
name - The name of the remote (e.g. origin)
Throws:
GitException - if executing the git command fails

setRemoteUrl

public void setRemoteUrl(String name,
                         String url)
                  throws GitException
Description copied from interface: GitClient
For a given repository, set a remote's URL

Specified by:
setRemoteUrl in interface GitClient
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 fails

getRemoteUrl

public String getRemoteUrl(String name,
                           String GIT_DIR)
                    throws GitException
Throws:
GitException

setRemoteUrl

public void setRemoteUrl(String name,
                         String url,
                         String GIT_DIR)
                  throws GitException
Throws:
GitException

getDefaultRemote

public String getDefaultRemote(String _default_)
                        throws GitException
Throws:
GitException

getDefaultRemote

public String getDefaultRemote()
                        throws GitException
Get the default remote.

Returns:
"origin" if it exists, otherwise return the first remote.
Throws:
GitException - if executing the git command fails

isBareRepository

public boolean isBareRepository()
                         throws GitException
Detect whether a repository is bare or not.

Throws:
GitException

isBareRepository

public boolean isBareRepository(String GIT_DIR)
                         throws GitException
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).
Throws:
GitException

fixSubmoduleUrls

public void fixSubmoduleUrls(String remote,
                             hudson.model.TaskListener listener)
                      throws GitException
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:
listener - The task listener.
Throws:
GitException - if executing the git command fails

setupSubmoduleUrls

public void setupSubmoduleUrls(Revision rev,
                               hudson.model.TaskListener listener)
                        throws GitException
Set up submodule URLs so that they correspond to the remote pertaining to the revision that has been checked out.

Specified by:
setupSubmoduleUrls in interface GitClient
Throws:
GitException

tag

public void tag(String tagName,
                String comment)
         throws GitException
Description copied from interface: GitClient
Create (or update) a tag. If tag already exist it gets updated (equivalent to git tag --force)

Specified by:
tag in interface GitClient
Throws:
GitException

appendNote

public void appendNote(String note,
                       String namespace)
                throws GitException
Specified by:
appendNote in interface GitClient
Throws:
GitException

addNote

public void addNote(String note,
                    String namespace)
             throws GitException
Specified by:
addNote in interface GitClient
Throws:
GitException

launchCommand

public String launchCommand(hudson.util.ArgumentListBuilder args)
                     throws GitException
Launch command using the workspace as working directory

Parameters:
args -
Returns:
command output
Throws:
GitException

launchCommand

public String launchCommand(String... args)
                     throws GitException
Launch command using the workspace as working directory

Parameters:
args -
Returns:
command output
Throws:
GitException

push

public void push(String remoteName,
                 String refspec)
          throws GitException
Specified by:
push in interface GitClient
Throws:
GitException

getBranches

public Set<Branch> getBranches()
                        throws GitException
Specified by:
getBranches in interface GitClient
Throws:
GitException

getRemoteBranches

public Set<Branch> getRemoteBranches()
                              throws GitException
Specified by:
getRemoteBranches in interface GitClient
Throws:
GitException

checkout

public void checkout(String commit)
              throws GitException
Description copied from interface: GitClient
Checks out the specified commit/tag/branch into the workspace.

Specified by:
checkout in interface GitClient
Parameters:
commit - A git object references expression (either a sha1, tag or branch)
Throws:
GitException

checkout

public void checkout(String ref,
                     String branch)
              throws GitException
Description copied from interface: GitClient
Checks out the specified commit/ref into the workspace, creating specified branch (equivalent to git checkout -b branch commit

Specified by:
checkout in interface GitClient
Parameters:
ref - A git object references expression. For backward compatibility, null will checkout current HEAD
branch - name of the branch to create from reference
Throws:
GitException

tagExists

public boolean tagExists(String tagName)
                  throws GitException
Specified by:
tagExists in interface GitClient
Throws:
GitException

deleteBranch

public void deleteBranch(String name)
                  throws GitException
Description copied from interface: GitClient
(force) delete a branch.

Specified by:
deleteBranch in interface GitClient
Throws:
GitException

deleteTag

public void deleteTag(String tagName)
               throws GitException
Specified by:
deleteTag in interface GitClient
Throws:
GitException

lsTree

public List<IndexEntry> lsTree(String treeIsh)
                        throws GitException
Throws:
GitException

revListAll

public List<org.eclipse.jgit.lib.ObjectId> revListAll()
                                               throws GitException
Specified by:
revListAll in interface GitClient
Throws:
GitException

revList

public List<org.eclipse.jgit.lib.ObjectId> revList(String ref)
                                            throws GitException
Specified by:
revList in interface GitClient
Throws:
GitException

isCommitInRepo

public boolean isCommitInRepo(org.eclipse.jgit.lib.ObjectId commit)
Specified by:
isCommitInRepo in interface GitClient

add

public void add(String filePattern)
         throws GitException
Specified by:
add in interface GitClient
Throws:
GitException

branch

public void branch(String name)
            throws GitException
Specified by:
branch in interface GitClient
Throws:
GitException

commit

public void commit(String message)
            throws GitException
Specified by:
commit in interface GitClient
Throws:
GitException

commit

public void commit(String message,
                   org.eclipse.jgit.lib.PersonIdent author,
                   org.eclipse.jgit.lib.PersonIdent committer)
            throws GitException
Specified by:
commit in interface GitClient
Throws:
GitException

getRepository

public org.eclipse.jgit.lib.Repository getRepository()
                                              throws GitException
Description copied from interface: GitClient
Expose the JGit repository this GitClient is using. Don't forget to call Repository.close(), to avoid JENKINS-12188.

Specified by:
getRepository in interface GitClient
Throws:
GitException

getTagNames

public Set<String> getTagNames(String tagPattern)
                        throws GitException
Specified by:
getTagNames in interface GitClient
Throws:
GitException

getTagMessage

public String getTagMessage(String tagName)
                     throws GitException
Specified by:
getTagMessage in interface GitClient
Throws:
GitException

getHeadRev

public org.eclipse.jgit.lib.ObjectId getHeadRev(String remoteRepoUrl,
                                                String branch)
                                         throws GitException
Specified by:
getHeadRev in interface GitClient
Throws:
GitException


Copyright © 2004-2013. All Rights Reserved.