hudson.plugins.git
Class GitAPI

java.lang.Object
  extended by hudson.plugins.git.GitAPI
All Implemented Interfaces:
IGitAPI

public class GitAPI
extends Object
implements IGitAPI


Constructor Summary
GitAPI(String gitExe, hudson.FilePath workspace, hudson.model.TaskListener listener, hudson.EnvVars environment)
           
 
Method Summary
 void add(String filePattern)
           
 void branch(String name)
           
 void changelog(String revFrom, String revTo, OutputStream outputStream)
           
 void checkout(String commitish)
          Short for checkoutBranch(null, commitish)
 void checkoutBranch(String branch, String commitish)
          Checks out the specified commit/ref into the workspace.
 void clean()
           
 void clone(org.spearce.jgit.transport.RemoteConfig remoteConfig)
          Start from scratch and clone the whole repository.
 void commit(File f)
           
 void deleteBranch(String name)
           
 void deleteTag(String tagName)
           
 String describe(String commitIsh)
           
 void fetch()
           
 void fetch(org.spearce.jgit.transport.RemoteConfig remoteRepository)
           
 void fetch(String repository, String refspec)
           
 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.
 String getAllLogEntries(String branch)
           
 List<Branch> getBranches()
           
 List<Branch> getBranchesContaining(String revspec)
           
 String getDefaultRemote()
          Get the default remote.
 String getDefaultRemote(String _default_)
          Get the default remote.
 hudson.EnvVars getEnvironment()
           
 String getGitExe()
           
 List<Branch> getRemoteBranches()
           
 String getRemoteUrl(String name)
          Get a remote's URL
 String getRemoteUrl(String name, String GIT_DIR)
          From a given repository, get a remote's URL
 List<IndexEntry> getSubmodules(String treeIsh)
           
 String getSubmoduleUrl(String name)
          Get submodule URL
 Set<String> getTagNames(String tagPattern)
           
 List<org.spearce.jgit.lib.Tag> getTagsOnCommit(String revName)
           
 boolean hasGitModules()
           
 boolean hasGitModules(String treeIsh)
           
 boolean hasGitRepo()
          Returns true if the encapsulated directory has ".git" directory
 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(String sha1)
           
 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(String revSpec)
          Merge any changes into the head.
 org.spearce.jgit.lib.ObjectId mergeBase(org.spearce.jgit.lib.ObjectId id1, org.spearce.jgit.lib.ObjectId id2)
           
 void prune(org.spearce.jgit.transport.RemoteConfig repository)
           
 void push(org.spearce.jgit.transport.RemoteConfig repository, String refspec)
           
 List<org.spearce.jgit.lib.ObjectId> revList(String... extraArgs)
           
 List<org.spearce.jgit.lib.ObjectId> revListAll()
           
 List<org.spearce.jgit.lib.ObjectId> revListBranch(String branchId)
           
 org.spearce.jgit.lib.ObjectId revParse(String revName)
           
 void setRemoteUrl(String name, String url)
          Set a remote's URL
 void setRemoteUrl(String name, String url, String GIT_DIR)
          For a given repository, set a remote's URL
 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.
 void setupSubmoduleUrls(String remote, hudson.model.TaskListener listener)
           
 List<String> showRevision(Revision r)
          Given a Revision, show it as if it were an entry from git whatchanged, so that it can be parsed by GitChangeLogParser.
 void submoduleClean(boolean recursive)
          Cleans submodules
 void submoduleInit()
          Init submodules.
 void submoduleSync()
          Sync submodule URLs
 void submoduleUpdate(boolean recursive)
          Update submodules.
 void tag(String tagName, String comment)
           
 boolean tagExists(String tagName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GitAPI

public GitAPI(String gitExe,
              hudson.FilePath workspace,
              hudson.model.TaskListener listener,
              hudson.EnvVars environment)
Method Detail

getGitExe

public String getGitExe()
Specified by:
getGitExe in interface IGitAPI

getEnvironment

public hudson.EnvVars getEnvironment()
Specified by:
getEnvironment in interface IGitAPI

init

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

hasGitRepo

public boolean hasGitRepo()
                   throws GitException
Description copied from interface: IGitAPI
Returns true if the encapsulated directory has ".git" directory

Specified by:
hasGitRepo in interface IGitAPI
Throws:
GitException

hasGitRepo

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

hasGitModules

public boolean hasGitModules()
                      throws GitException
Specified by:
hasGitModules in interface IGitAPI
Throws:
GitException

getSubmodules

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

hasGitModules

public boolean hasGitModules(String treeIsh)
                      throws GitException
Specified by:
hasGitModules in interface IGitAPI
Throws:
GitException

fetch

public void fetch(String repository,
                  String refspec)
           throws GitException
Specified by:
fetch in interface IGitAPI
Throws:
GitException

fetch

public void fetch()
           throws GitException
Specified by:
fetch in interface IGitAPI
Throws:
GitException

clone

public void clone(org.spearce.jgit.transport.RemoteConfig remoteConfig)
           throws GitException
Start from scratch and clone the whole repository. Cloning into an existing directory is not allowed, so the workspace is first deleted entirely, then git clone is performed.

Specified by:
clone in interface IGitAPI
Parameters:
remoteConfig - remote config
Throws:
GitException - if deleting or cloning the workspace fails

clean

public void clean()
           throws GitException
Specified by:
clean in interface IGitAPI
Throws:
GitException

revParse

public org.spearce.jgit.lib.ObjectId revParse(String revName)
                                       throws GitException
Specified by:
revParse in interface IGitAPI
Throws:
GitException

describe

public String describe(String commitIsh)
                throws GitException
Specified by:
describe in interface IGitAPI
Throws:
GitException

prune

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

changelog

public void changelog(String revFrom,
                      String revTo,
                      OutputStream outputStream)
               throws GitException
Specified by:
changelog in interface IGitAPI
Throws:
GitException

showRevision

public List<String> showRevision(Revision r)
                          throws GitException
Given a Revision, show it as if it were an entry from git whatchanged, so that it can be parsed by GitChangeLogParser.

Specified by:
showRevision in interface IGitAPI
Parameters:
r - The Revision object
Returns:
The git show output, in List form.
Throws:
GitException - if errors were encountered running git show.

merge

public void merge(String revSpec)
           throws GitException
Merge any changes into the head.

Specified by:
merge in interface IGitAPI
Parameters:
revSpec - the revision
Throws:
GitException - if the emrge fails

submoduleInit

public void submoduleInit()
                   throws GitException
Init submodules.

Specified by:
submoduleInit in interface IGitAPI
Throws:
GitException - if executing the Git command fails

submoduleSync

public void submoduleSync()
                   throws GitException
Sync submodule URLs

Specified by:
submoduleSync in interface IGitAPI
Throws:
GitException

submoduleUpdate

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

Specified by:
submoduleUpdate in interface IGitAPI
Parameters:
recursive - if true, will recursively update submodules (requires 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 IGitAPI
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

Specified by:
getSubmoduleUrl in interface IGitAPI
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

Specified by:
setSubmoduleUrl in interface IGitAPI
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
Get a remote's URL

Specified by:
getRemoteUrl in interface IGitAPI
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
Set a remote's URL

Specified by:
setRemoteUrl in interface IGitAPI
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
From a given repository, get a remote's URL

Specified by:
getRemoteUrl in interface IGitAPI
Parameters:
name - The name of the remote (e.g. origin)
GIT_DIR - The path to the repository (must be to .git dir)
Throws:
GitException - if executing the git command fails

setRemoteUrl

public void setRemoteUrl(String name,
                         String url,
                         String GIT_DIR)
                  throws GitException
For a given repository, set a remote's URL

Specified by:
setRemoteUrl in interface IGitAPI
Parameters:
name - The name of the remote (e.g. origin)
url - The new value of the remote's URL
GIT_DIR - The path to the repository (must be to .git dir)
Throws:
GitException - if executing the git command fails

getDefaultRemote

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

Specified by:
getDefaultRemote in interface IGitAPI
Parameters:
_default_ - The default remote to use if more than one exists.
Returns:
_default_ if it exists, otherwise return the first remote.
Throws:
GitException - if executing the git command fails

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.

Specified by:
isBareRepository in interface IGitAPI
Throws:
GitException

isBareRepository

public boolean isBareRepository(String GIT_DIR)
                         throws GitException
Detect whether a repository at the given path is bare or not.

Specified by:
isBareRepository in interface IGitAPI
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 .

Specified by:
fixSubmoduleUrls in interface IGitAPI
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 IGitAPI
Throws:
GitException

setupSubmoduleUrls

public void setupSubmoduleUrls(String remote,
                               hudson.model.TaskListener listener)
                        throws GitException
Specified by:
setupSubmoduleUrls in interface IGitAPI
Throws:
GitException

tag

public void tag(String tagName,
                String comment)
         throws GitException
Specified by:
tag in interface IGitAPI
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(org.spearce.jgit.transport.RemoteConfig repository,
                 String refspec)
          throws GitException
Specified by:
push in interface IGitAPI
Throws:
GitException

getBranches

public List<Branch> getBranches()
                         throws GitException
Specified by:
getBranches in interface IGitAPI
Throws:
GitException

getRemoteBranches

public List<Branch> getRemoteBranches()
                               throws GitException,
                                      IOException
Specified by:
getRemoteBranches in interface IGitAPI
Throws:
GitException
IOException

getBranchesContaining

public List<Branch> getBranchesContaining(String revspec)
                                   throws GitException
Specified by:
getBranchesContaining in interface IGitAPI
Throws:
GitException

checkout

public void checkout(String commitish)
              throws GitException
Description copied from interface: IGitAPI
Short for checkoutBranch(null, commitish)

Specified by:
checkout in interface IGitAPI
Throws:
GitException

checkoutBranch

public void checkoutBranch(String branch,
                           String commitish)
                    throws GitException
Description copied from interface: IGitAPI
Checks out the specified commit/ref into the workspace.

Specified by:
checkoutBranch in interface IGitAPI
Parameters:
branch - If non-null, move/create the branch in this name at the specified commit-ish and check out that branch.
Throws:
GitException

tagExists

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

deleteBranch

public void deleteBranch(String name)
                  throws GitException
Specified by:
deleteBranch in interface IGitAPI
Throws:
GitException

deleteTag

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

lsTree

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

revListAll

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

revListBranch

public List<org.spearce.jgit.lib.ObjectId> revListBranch(String branchId)
                                                  throws GitException
Specified by:
revListBranch in interface IGitAPI
Throws:
GitException

revList

public List<org.spearce.jgit.lib.ObjectId> revList(String... extraArgs)
                                            throws GitException
Throws:
GitException

isCommitInRepo

public boolean isCommitInRepo(String sha1)
Specified by:
isCommitInRepo in interface IGitAPI

add

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

branch

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

commit

public void commit(File f)
            throws GitException
Specified by:
commit in interface IGitAPI
Throws:
GitException

fetch

public void fetch(org.spearce.jgit.transport.RemoteConfig remoteRepository)
           throws GitException
Specified by:
fetch in interface IGitAPI
Throws:
GitException

mergeBase

public org.spearce.jgit.lib.ObjectId mergeBase(org.spearce.jgit.lib.ObjectId id1,
                                               org.spearce.jgit.lib.ObjectId id2)
Specified by:
mergeBase in interface IGitAPI

getAllLogEntries

public String getAllLogEntries(String branch)
Specified by:
getAllLogEntries in interface IGitAPI

getTagsOnCommit

public List<org.spearce.jgit.lib.Tag> getTagsOnCommit(String revName)
                                               throws GitException,
                                                      IOException
Specified by:
getTagsOnCommit in interface IGitAPI
Throws:
GitException
IOException

getTagNames

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


Copyright © 2004-2011 Hudson. All Rights Reserved.