public interface Git
This interface defines the calls that are useful for Dragom. It is not meant to be a full-featured implementation of the Git API, nor is it meant to be fully polished.
Implementations of this interface are intended to be obtained using
ServiceLocator so they can easily be doubled for testing purposes. The
main implementation is DefaultGitImpl which therefore has a no-argument
constructor. This is why setup methods such as setPathExecutable(java.nio.file.Path) are
part of this interface.
Mainly used by GitScmPluginImpl. But also useful for Dragom test
scripts that need to act on repositories outside of Dragom tools themselves, to
simulate remote changes for instance.
Although an interface design is a good practice, its utility here is rather low since implementing a double for testing purposes can be quite complex.
This class relies on Git being installed locally. It interfaces with the Git command line.
| Modifier and Type | Interface and Description |
|---|---|
static class |
Git.AheadBehindInfo
Ahead/behind information returned by
getAheadBehindInfo(java.nio.file.Path). |
static class |
Git.AllowExitCode
Enumerates the possible values for the allowExitCode parameter of the
executeGitCommand method.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCommit(Path pathWorkspace,
String message,
Map<String,String> mapCommitAttr,
boolean indPush)
Synchronizes the working copy with the index and commits.
|
void |
checkout(Path pathWorkspace,
org.azyva.dragom.model.Version version)
Git checkout.
|
void |
clone(String reposUrl,
org.azyva.dragom.model.Version version,
Path pathWorkspace)
Git clone.
|
void |
config(Path pathWorkspace,
String param,
String value)
Sets a configuration parameter within the Git workspace (local
repository).
|
String |
convertToRef(org.azyva.dragom.model.Version version)
Converts a
Version to a Git reference such as refs/tags/<tag> or
refs/remotes/origin/<branch>. |
void |
createBranch(Path pathModuleWorkspace,
String branch,
boolean indSwitch)
Creates a branch.
|
void |
createTag(Path pathModuleWorkspace,
String tag,
String message)
Creates a tag.
|
int |
executeGitCommand(String[] arrayArg,
boolean indProvideCredentials,
Git.AllowExitCode allowExitCode,
Path pathWorkingDirectory,
StringBuilder stringBuilderOutput)
Helper method to execute a Git command.
|
void |
fetch(Path path,
String reposUrl,
String refspec,
boolean indFetchingIntoCurrentBranch)
Git fetch.
|
Git.AheadBehindInfo |
getAheadBehindInfo(Path pathWorkspace)
Determines if the remote repository contains changes that are not in the
local repository (behind) and/or if the local repository contains changes
that are not in the remote repository (ahead).
|
String |
getBranch(Path pathWorkspace)
Returns the current branch or null if detached.
|
List<org.azyva.dragom.model.Version> |
getListVersionStatic(Path pathWorkspace)
Returns the List of all static Version's (tags).
|
org.azyva.dragom.model.Version |
getVersion(Path pathWorkspace)
Returns the current version.
|
boolean |
isLocalChanges(Path pathWorkspace)
Verifies there are local changes that are not pushed.
|
boolean |
isReposExists() |
boolean |
isVersionExists(Path pathWorkspace,
org.azyva.dragom.model.Version version)
Tests if a Version exists.
|
boolean |
mergeSimple(Path pathWorkspace)
Merges the current branch's remote counterpart into the current branch.
|
boolean |
pull(Path pathWorkspace)
Git pull.
|
void |
push(Path pathWorkspace)
Pushes all refs, branches and tags.
|
void |
push(Path pathWorkspace,
String gitRef)
Git push.
|
boolean |
rebaseSimple(Path pathWorkspace)
Rebases the current branch on its remote counterpart.
|
void |
setPassword(String password)
Sets the password to access Git repositories.
|
void |
setPathExecutable(Path pathExecutable)
Sets the Path to the git executable.
|
void |
setReposUrl(String reposUrl)
Sets the repository URL.
|
void |
setUser(String user)
Sets the user to access Git repositories.
|
boolean |
validateCredentials() |
void setPathExecutable(Path pathExecutable)
pathExecutable - See description.void setReposUrl(String reposUrl)
reposUrl - See description.void setUser(String user)
If not null and the repository URL contains a user (i.e.: https://jsmith@acme.com/my-repos.git), the user specified must be the same.
user - See description.void setPassword(String password)
setUser(java.lang.String)) is null.password - See description.int executeGitCommand(String[] arrayArg, boolean indProvideCredentials, Git.AllowExitCode allowExitCode, Path pathWorkingDirectory, StringBuilder stringBuilderOutput)
Mostly used internally, but can be used by callers in order to submit a Git command that is not directly supported by this class.
arrayArg - Command line arguments to Git.indProvideCredentials - Indicates to provide the user credentials to
Git, if available.allowExitCode - Specifies which exit codes are allowed and will not
trigger an exception.pathWorkingDirectory - Path to the working directory. The command will be
executed with this current working directory. If null current working directy
is used.stringBuilderOutput - If not null, any output (stdout) of the command will
be copied in this StringBuilder.boolean validateCredentials()
boolean isReposExists()
String getBranch(Path pathWorkspace)
Can be used to check if the current Version is branch by comparing to null.
pathWorkspace - Path to the workspace.void config(Path pathWorkspace, String param, String value)
pathWorkspace - Path to the workspace.param - Parameter name.value - Parameter value.void clone(String reposUrl, org.azyva.dragom.model.Version version, Path pathWorkspace)
reposUrl - Repository URL. Can be null in which case the repository URL
specified with setReposUrl(java.lang.String) is used. Specifying the repository URL
allows the caller to clone from a local repository. When reposUrl is
specified it must use the file:// protocol.version - Version to checkout after clone. If null, no version is
checked out, not even master.pathWorkspace - Path to the workspace.void fetch(Path path, String reposUrl, String refspec, boolean indFetchingIntoCurrentBranch)
path - Path.reposUrl - Repository URL. Can be null in which case fetch occurs from
the remote named "origin" within the configuration of the workspace, and thus
implicitly from the remote repository specified with setReposUrl(java.lang.String).
Can be a repository URL in which case refspec should be specified otherwise
Git will not know which refs to update. This allows the caller to fetch
between local repositories. When reposUrl is specified, it must use the
file:// protocol.refspec - The Git refspec to pass to git fetch. See the documentation for
git fetch for more information. Can be null if no refspec is to be passed to
git, letting git essentially use the default
refs/heads/*:refs/remotes/origin/heads/* refspec.indFetchingIntoCurrentBranch - This is to handle the special case where
the caller knows what is fetched into is the current branch, meaning that
refspec is specifed and ends with ":refs/heads/...". In such a case this
method specifies the --update-head-ok option to "git fetch" (otherwise git
complains that fetching into the current local branch is not allowed).boolean pull(Path pathWorkspace)
pathWorkspace - Path to the workspace.boolean rebaseSimple(Path pathWorkspace)
pathWorkspace - Path to the workspace.boolean mergeSimple(Path pathWorkspace)
pathWorkspace - Path to the workspace.void push(Path pathWorkspace, String gitRef)
If gitRef is not null --set-upstream used. This is to allow to always set the upstream tracking information because the push can be delayed and new branches can be pushed on the call to this method other than the one immediately after creating the branch.
In the case gitRef is a tag, --set-upstream has no effect.
pathWorkspace - Path to the workspace.gitRef - Git reference to push. If null, the current branch is pushed.void checkout(Path pathWorkspace, org.azyva.dragom.model.Version version)
pathWorkspace - Path to the workspace.version - Version to checkout.boolean isVersionExists(Path pathWorkspace, org.azyva.dragom.model.Version version)
pathWorkspace - Path to the workspace.version - Version.Git.AheadBehindInfo getAheadBehindInfo(Path pathWorkspace)
pathWorkspace - Path to the workspace.boolean isLocalChanges(Path pathWorkspace)
pathWorkspace - Path to the workspace.void push(Path pathWorkspace)
pathWorkspace - Path to the workspace.org.azyva.dragom.model.Version getVersion(Path pathWorkspace)
If not on a branch, returns the tag corresponding to the current commit, if any.
pathWorkspace - Path to the workspace.List<org.azyva.dragom.model.Version> getListVersionStatic(Path pathWorkspace)
pathWorkspace - Path to the workspace.void createBranch(Path pathModuleWorkspace, String branch, boolean indSwitch)
pathModuleWorkspace - Path to the workspace.branch - Branch.indSwitch - Indicates whether we must switch (checkout) to the new
branch.void createTag(Path pathModuleWorkspace, String tag, String message)
pathModuleWorkspace - Path to the workspace.tag - Tag.message - Tag message.void addCommit(Path pathWorkspace, String message, Map<String,String> mapCommitAttr, boolean indPush)
pathWorkspace - Path to the workspace.message - Commit message.mapCommitAttr - Map of commit attributes.indPush - Indicates to perform a push immediately after the commit.String convertToRef(org.azyva.dragom.model.Version version)
Version to a Git reference such as refs/tags/<tag> or
refs/remotes/origin/<branch>.
In the case of a dynamic Version, the remote branch is used.
version - Version.Copyright © 2015–2016 AZYVA INC.. All rights reserved.