public class GitUtils extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
GitUtils.TeamscaleGitCredentialsProvider
Basic credentials provider for the jgit library that automatically accepts
requests whether we trust a source.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ANONYMOUS_BRANCH_NAME
Base name for anonymous branches.
|
static java.lang.String |
HEAD
Git HEAD ref.
|
static java.lang.String |
MASTER_BRANCH
Name of the master branch.
|
static int |
REMOTE_OPERATION_TIMEOUT_SECONDS
Timeout in number of seconds, used for general remote git operations.
|
static java.lang.String |
SEPARATOR
Separator used for paths returned via the API.
|
Constructor and Description |
---|
GitUtils() |
Modifier and Type | Method and Description |
---|---|
static org.eclipse.jgit.lib.Repository |
cloneAndSetUpRepository(java.io.File localDirectory,
java.net.URI location,
GitUtils.TeamscaleGitCredentialsProvider credentials)
Sets up a repository by cloning it.
|
static void |
configureCommand(java.net.URI location,
GitUtils.TeamscaleGitCredentialsProvider credentials,
org.eclipse.jgit.api.TransportCommand<?,?> command)
Configures the given command by adding ssh credentials and configuring a
timeeout.
|
static GitUtils.TeamscaleGitCredentialsProvider |
createCredentialsProvider(java.lang.String userName,
java.lang.String password,
java.lang.String sshPrivateKey)
Creates a user-name password credentials provider that may also keep an SSH
private key.
|
static org.eclipse.jgit.diff.DiffFormatter |
createDiffFormatter(org.eclipse.jgit.lib.Repository repository)
Creates a
DiffFormatter to retrieve changes from the repository |
static org.eclipse.jgit.api.FetchCommand |
createFetchCommand(org.eclipse.jgit.api.Git git,
java.net.URI location,
GitUtils.TeamscaleGitCredentialsProvider credentialsProvider)
Returns a fetch command for updating a local git repository.
|
static org.eclipse.jgit.treewalk.TreeWalk |
createTreeWalk(org.eclipse.jgit.lib.Repository repository)
Creates a
TreeWalk instance for the given repository |
static java.util.Optional<org.eclipse.jgit.diff.DiffEntry.ChangeType> |
determineChangeType(org.eclipse.jgit.diff.DiffEntry diff)
Determines the change type for a given entry.
|
static org.eclipse.jgit.revwalk.RevCommit |
getCommit(org.eclipse.jgit.lib.Repository repository,
java.lang.String revisionBranchOrTag)
Returns the commit denoted by the given commit id/tag/head.
|
static org.eclipse.jgit.lib.Repository |
getExistingRepository(java.net.URI localGitRepoURI)
Tries to find an existing bare or cloned repository along the given URI (with
"file" scheme).
|
static java.util.Optional<org.eclipse.jgit.lib.ObjectId> |
getId(org.eclipse.jgit.lib.Repository repository,
org.eclipse.jgit.revwalk.RevCommit commit,
java.lang.String path)
Returns the id of the object described by the given path in the given
revision.
|
static EGitProtocol |
getProtocolFromUrl(java.lang.String url)
Determine protocol used in given url.
|
static java.util.Optional<java.lang.Long> |
getTimestampFromRevision(org.eclipse.jgit.lib.Repository repository,
java.lang.String revision)
Returns a timestamp for the given revision in the given repository.
|
static boolean |
isActualFile(int modeBits)
Returns whether a "file" with the given mode bits is an actual file and not,
e.g., a symlink which is not tracked by Teamscale.
|
static boolean |
isAnonymousBranchName(java.lang.String branchName)
Returns true, if and only if the branch name starts with the
ANONYMOUS_BRANCH_NAME . |
static boolean |
isCommitHash(java.lang.String revision)
Returns whether the given revision is a valid commit hash or HEAD reference.
|
static java.lang.String |
rewriteGitAtUrl(java.lang.String url)
Because the git library does not support the git@ url format, we fix it by
converting it to a plain ssh url
|
public static final int REMOTE_OPERATION_TIMEOUT_SECONDS
public static final java.lang.String MASTER_BRANCH
public static final java.lang.String SEPARATOR
public static final java.lang.String HEAD
public static final java.lang.String ANONYMOUS_BRANCH_NAME
public GitUtils()
public static org.eclipse.jgit.lib.Repository getExistingRepository(java.net.URI localGitRepoURI) throws RepositoryException
RepositoryException
- if no repository could be foundpublic static org.eclipse.jgit.lib.Repository cloneAndSetUpRepository(java.io.File localDirectory, java.net.URI location, GitUtils.TeamscaleGitCredentialsProvider credentials) throws RepositoryException
RepositoryException
public static void configureCommand(java.net.URI location, GitUtils.TeamscaleGitCredentialsProvider credentials, org.eclipse.jgit.api.TransportCommand<?,?> command)
public static GitUtils.TeamscaleGitCredentialsProvider createCredentialsProvider(java.lang.String userName, java.lang.String password, java.lang.String sshPrivateKey)
Note: The SSH private key is not used automatically but must
be explicitly requested by calling
configureCommand(URI, TeamscaleGitCredentialsProvider, TransportCommand)
prior to the Git command.
public static org.eclipse.jgit.revwalk.RevCommit getCommit(org.eclipse.jgit.lib.Repository repository, java.lang.String revisionBranchOrTag) throws RepositoryException
RepositoryException
public static java.util.Optional<org.eclipse.jgit.lib.ObjectId> getId(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit commit, java.lang.String path) throws RepositoryException
RepositoryException
public static org.eclipse.jgit.diff.DiffFormatter createDiffFormatter(org.eclipse.jgit.lib.Repository repository)
DiffFormatter
to retrieve changes from the repositorypublic static org.eclipse.jgit.treewalk.TreeWalk createTreeWalk(org.eclipse.jgit.lib.Repository repository)
TreeWalk
instance for the given repositorypublic static EGitProtocol getProtocolFromUrl(java.lang.String url)
null if url is
malformed.
public static java.util.Optional<java.lang.Long> getTimestampFromRevision(org.eclipse.jgit.lib.Repository repository, java.lang.String revision)
public static boolean isCommitHash(java.lang.String revision)
public static boolean isAnonymousBranchName(java.lang.String branchName)
ANONYMOUS_BRANCH_NAME
.public static java.lang.String rewriteGitAtUrl(java.lang.String url)
public static java.util.Optional<org.eclipse.jgit.diff.DiffEntry.ChangeType> determineChangeType(org.eclipse.jgit.diff.DiffEntry diff)
DiffEntry.ChangeType.ADD
. Returns Optional.empty()
if the entry
was and still is not an actual file and should hence be ignored entirely.public static boolean isActualFile(int modeBits)
public static org.eclipse.jgit.api.FetchCommand createFetchCommand(org.eclipse.jgit.api.Git git, java.net.URI location, GitUtils.TeamscaleGitCredentialsProvider credentialsProvider)