org.jenkinsci.plugins.gitclient
Class JGitAPIImpl

java.lang.Object
  extended by org.jenkinsci.plugins.gitclient.JGitAPIImpl
All Implemented Interfaces:
GitClient

public class JGitAPIImpl
extends Object
implements GitClient

GitClient pure Java implementation using JGit. Goal is to eventually get a full java implementation for GitClient For internal use only, don't use directly. See Git

Author:
Nicolas De Loof

Field Summary
 
Fields inherited from interface org.jenkinsci.plugins.gitclient.GitClient
quietRemoteBranches, verbose
 
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 fos)
          Adds the changelog entries for commits in the range revFrom..revTo.
 void checkout(String ref)
          Checks out the specified commit/tag/branch into the workspace.
 void checkout(String ref, String branch)
          Creates a new branch that points to the specified ref.
 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 ref HEAD points to branch.
 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)
           
 void fetch(String remoteName, org.eclipse.jgit.transport.RefSpec refspec)
          Fetch a remote repository.
 Set<Branch> getBranches()
           
 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
 org.eclipse.jgit.lib.Repository getRepository()
          Expose the JGit repository this GitClient is using.
 List<IndexEntry> getSubmodules(String treeIsh)
           
 String getTagMessage(String tagName)
           
 Set<String> getTagNames(String tagPattern)
           
 boolean hasGitModules()
          Returns true if the repository has Git submodules.
 boolean hasGitRepo()
           
 void init()
           
 boolean isCommitInRepo(org.eclipse.jgit.lib.ObjectId commit)
           
 void merge(org.eclipse.jgit.lib.ObjectId rev)
           
 void prune(org.eclipse.jgit.transport.RemoteConfig repository)
           
 void push(String remoteName, String refspec)
           
 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 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)
           
 void submoduleUpdate(boolean recursive)
           
 void tag(String name, String message)
          Create (or update) a tag.
 boolean tagExists(String tagName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

checkout

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

Specified by:
checkout in interface GitClient
Parameters:
ref - 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
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 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

checkoutBranch

public void checkoutBranch(String branch,
                           String ref)
                    throws GitException
Description copied from interface: GitClient
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:

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. The checkout 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 interface GitClient
Throws:
GitException

add

public void add(String filePattern)
         throws GitException
Specified by:
add 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

branch

public void branch(String name)
            throws GitException
Specified by:
branch 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

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

tag

public void tag(String name,
                String message)
         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

tagExists

public boolean tagExists(String tagName)
                  throws GitException
Specified by:
tagExists 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

getHeadRev

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

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

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

merge

public void merge(org.eclipse.jgit.lib.ObjectId rev)
           throws GitException
Specified by:
merge in interface GitClient
Throws:
GitException

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

addNote

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

appendNote

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

changelog

public void changelog(String revFrom,
                      String revTo,
                      OutputStream fos)
               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

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

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

deleteTag

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

getTagMessage

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

getSubmodules

public List<IndexEntry> getSubmodules(String treeIsh)
                               throws GitException
Specified by:
getSubmodules in interface GitClient
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

getTagNames

public Set<String> getTagNames(String tagPattern)
                        throws GitException
Specified by:
getTagNames in interface GitClient
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

hasGitRepo

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

isCommitInRepo

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

prune

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

push

public void push(String remoteName,
                 String refspec)
          throws GitException
Specified by:
push in interface GitClient
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

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.

setupSubmoduleUrls

public void setupSubmoduleUrls(Revision rev,
                               hudson.model.TaskListener listener)
                        throws GitException
Description copied from interface: GitClient
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

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

submoduleClean

public void submoduleClean(boolean recursive)
                    throws GitException
Specified by:
submoduleClean in interface GitClient
Throws:
GitException

submoduleUpdate

public void submoduleUpdate(boolean recursive)
                     throws GitException
Specified by:
submoduleUpdate in interface GitClient
Throws:
GitException


Copyright © 2004-2013. All Rights Reserved.