public class JGitUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static List<ScmFile> |
addAllFiles(org.eclipse.jgit.api.Git git,
ScmFileSet fileSet)
Adds all files in the given fileSet to the repository.
|
static void |
closeRepo(org.eclipse.jgit.api.Git git)
Closes the repository wrapped by the passed git object
|
static org.eclipse.jgit.transport.CredentialsProvider |
getCredentials(GitScmProviderRepository repository)
Creates a credentials provider from the information passed in the
repository.
|
static List<ScmFile> |
getFilesInCommit(org.eclipse.jgit.lib.Repository repository,
org.eclipse.jgit.revwalk.RevCommit commit)
get a list of all files in the given commit
|
static List<ScmFile> |
getFilesInCommit(org.eclipse.jgit.lib.Repository repository,
org.eclipse.jgit.revwalk.RevCommit commit,
File baseDir)
get a list of all files in the given commit
|
static org.eclipse.jgit.lib.ProgressMonitor |
getMonitor()
Construct a logging ProgressMonitor for all JGit operations.
|
static List<org.eclipse.jgit.revwalk.RevCommit> |
getRevCommits(org.eclipse.jgit.lib.Repository repo,
org.eclipse.jgit.revwalk.RevSort[] sortings,
String fromRev,
String toRev,
Date fromDate,
Date toDate,
int maxLines)
Get a list of commits between two revisions.
|
static ScmFileStatus |
getScmFileStatus(org.eclipse.jgit.diff.DiffEntry.ChangeType changeType)
Translate a
FileStatus in the matching ScmFileStatus. |
static List<String> |
getTags(org.eclipse.jgit.lib.Repository repo,
org.eclipse.jgit.revwalk.RevCommit commit)
Get a list of tags that has been set in the specified commit.
|
static List<File> |
getWorkingCopyRelativePaths(File workingCopyDirectory,
ScmFileSet fileSet)
Convert each file in the
fileSet to their relative file path to workingCopyDirectory
and return them in a list. |
static boolean |
hasCommits(org.eclipse.jgit.lib.Repository repo)
Does the Repository have any commits?
|
static org.eclipse.jgit.api.Git |
openRepo(File basedir)
Opens a JGit repository in the current directory or a parent directory.
|
static org.eclipse.jgit.transport.CredentialsProvider |
prepareSession(org.eclipse.jgit.api.Git git,
GitScmProviderRepository repository)
Prepares the in memory configuration of git to connect to the configured
repository.
|
static Iterable<org.eclipse.jgit.transport.PushResult> |
push(org.eclipse.jgit.api.Git git,
GitScmProviderRepository repo,
org.eclipse.jgit.transport.RefSpec refSpec) |
static List<ScmFile> |
removeAllFiles(org.eclipse.jgit.api.Git git,
ScmFileSet fileSet)
Remove all files in the given fileSet from the repository.
|
static String |
toNormalizedFilePath(File file)
Converts the given file to a string only containing forward slashes
|
public static org.eclipse.jgit.api.Git openRepo(File basedir) throws IOException
basedir - The directory to start withIOException - If the repository cannot be openedpublic static void closeRepo(org.eclipse.jgit.api.Git git)
git - public static org.eclipse.jgit.lib.ProgressMonitor getMonitor()
public static org.eclipse.jgit.transport.CredentialsProvider prepareSession(org.eclipse.jgit.api.Git git, GitScmProviderRepository repository)
git - the instance to configure (only in memory, not saved)repository - the repo config to be usedCredentialsProvider in case there are credentials
informations configured in the repository.public static org.eclipse.jgit.transport.CredentialsProvider getCredentials(GitScmProviderRepository repository)
repository - the config to get the details fromnull if there is not enough info to create a
provider withpublic static Iterable<org.eclipse.jgit.transport.PushResult> push(org.eclipse.jgit.api.Git git, GitScmProviderRepository repo, org.eclipse.jgit.transport.RefSpec refSpec) throws org.eclipse.jgit.api.errors.GitAPIException, org.eclipse.jgit.api.errors.InvalidRemoteException, org.eclipse.jgit.api.errors.TransportException
org.eclipse.jgit.api.errors.GitAPIExceptionorg.eclipse.jgit.api.errors.InvalidRemoteExceptionorg.eclipse.jgit.api.errors.TransportExceptionpublic static boolean hasCommits(org.eclipse.jgit.lib.Repository repo)
repo - public static List<ScmFile> getFilesInCommit(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit commit) throws org.eclipse.jgit.errors.MissingObjectException, org.eclipse.jgit.errors.IncorrectObjectTypeException, org.eclipse.jgit.errors.CorruptObjectException, IOException
repository - the repocommit - the commit to get the files fromorg.eclipse.jgit.errors.MissingObjectExceptionorg.eclipse.jgit.errors.IncorrectObjectTypeExceptionorg.eclipse.jgit.errors.CorruptObjectExceptionIOExceptionpublic static List<ScmFile> getFilesInCommit(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit commit, File baseDir) throws org.eclipse.jgit.errors.MissingObjectException, org.eclipse.jgit.errors.IncorrectObjectTypeException, org.eclipse.jgit.errors.CorruptObjectException, IOException
repository - the repocommit - the commit to get the files frombaseDir - the directory to which the returned files should be relative.
May be null in case they should be relative to the working directory root.org.eclipse.jgit.errors.MissingObjectExceptionorg.eclipse.jgit.errors.IncorrectObjectTypeExceptionorg.eclipse.jgit.errors.CorruptObjectExceptionIOExceptionpublic static ScmFileStatus getScmFileStatus(org.eclipse.jgit.diff.DiffEntry.ChangeType changeType)
FileStatus in the matching ScmFileStatus.changeType - public static List<ScmFile> addAllFiles(org.eclipse.jgit.api.Git git, ScmFileSet fileSet) throws org.eclipse.jgit.api.errors.GitAPIException
git - the repo to add the files tofileSet - the set of files within the workspace, the files are added
relative to the basedir of this filesetorg.eclipse.jgit.api.errors.GitAPIExceptionpublic static List<ScmFile> removeAllFiles(org.eclipse.jgit.api.Git git, ScmFileSet fileSet) throws org.eclipse.jgit.api.errors.GitAPIException
git - the repo to remove the files fromfileSet - the set of files within the workspace, the files are removed
relative to the basedir of this filesetorg.eclipse.jgit.api.errors.GitAPIExceptionpublic static List<File> getWorkingCopyRelativePaths(File workingCopyDirectory, ScmFileSet fileSet)
fileSet to their relative file path to workingCopyDirectory
and return them in a list.workingCopyDirectory - the working copy root directoryfileSet - the file set to convertpublic static String toNormalizedFilePath(File file)
file - public static List<org.eclipse.jgit.revwalk.RevCommit> getRevCommits(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevSort[] sortings, String fromRev, String toRev, Date fromDate, Date toDate, int maxLines) throws IOException, org.eclipse.jgit.errors.MissingObjectException, org.eclipse.jgit.errors.IncorrectObjectTypeException
repo - the repository to work onsortings - sortingfromRev - start revisiontoRev - if null, falls back to headfromDate - from which date ontoDate - until which datemaxLines - max number of linesnullIOExceptionorg.eclipse.jgit.errors.MissingObjectExceptionorg.eclipse.jgit.errors.IncorrectObjectTypeExceptionpublic static List<String> getTags(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevCommit commit) throws IOException
repo - the repository to work oncommit - the commit for which we want the tagsnullIOExceptionCopyright © 2003–2024 The Apache Software Foundation. All rights reserved.