public class GitConnection extends Object implements ScmConnection
| Modifier and Type | Field and Description |
|---|---|
protected String |
addressGit
path to the directory of the file to edit
|
protected static String |
DEFAULT_BRANCH
the default branch to use when the requested one was not found
|
protected String |
fileName
the name of the file to edit
|
protected org.eclipse.jgit.lib.Repository |
gitRepo
git existing repository
|
protected File |
localDirectory
the local directory where the repository has been cloned to
|
protected String |
pathToLocalRepos
the path to the directory which contains all the repositories
|
protected String |
REPOSITORY_EXTENSION |
| Constructor and Description |
|---|
GitConnection(String address,
String pathToLocalRepos)
Creates a new connection to a Git repository
|
| Modifier and Type | Method and Description |
|---|---|
BrowseResultDto |
browse(BrowseDto dto) |
void |
changeBranch(String branchName)
Changing for another branch
|
protected void |
cloneRepository(org.eclipse.jgit.transport.CredentialsProvider credentials)
Clones the repository (clone command)
|
CommitResultDto |
commit(CommitDto dto) |
protected void |
doCommit(org.eclipse.jgit.api.Git git,
String authorName,
String authorEmail,
String commitMessage)
Calls the commit command
|
String |
getAddressGit() |
File |
getDiffs(String path,
String username,
String password,
String revision1,
String revision2) |
File |
getFileContent(String path,
String username,
String password) |
File |
getFileContentAtRevision(String path,
String username,
String password,
String revision) |
String |
getFileName() |
String |
getFilePath(String address,
String repositoryRoot,
String username,
String password) |
org.eclipse.jgit.lib.Repository |
getGitRepo() |
String |
getHeadRevisionNumber(String path,
String username,
String password) |
File |
getLocalDirectory() |
String |
getPathToLocalRepos() |
String |
getRepositoryId() |
Map<ScmRevision,String> |
getRevisions(String address,
String username,
String password) |
protected void |
handlePushException(org.eclipse.jgit.api.errors.GitAPIException e)
Handles the exception thrown by a push command
|
protected String |
hash(String toHash,
String algorithm)
Hashes a String with then given algorithms
|
void |
setGitRepo(org.eclipse.jgit.lib.Repository gitRepo) |
void |
setLocalDirectory(File localDirectory) |
void |
setPathToLocalRepos(String pathToLocalRepos) |
void |
updateRepository(String username,
String password)
Updates the repository to the last version by a clone or a pull command
|
protected org.eclipse.jgit.lib.Repository gitRepo
protected File localDirectory
protected String addressGit
protected String fileName
protected String pathToLocalRepos
protected static final String DEFAULT_BRANCH
protected final String REPOSITORY_EXTENSION
public GitConnection(String address, String pathToLocalRepos) throws IOException
address - the address of the Git repository to connect topathToLocalRepos - the path to the local folder which will store the user's repositoriesIOException - if the repository can not be reachedpublic org.eclipse.jgit.lib.Repository getGitRepo()
public void setGitRepo(org.eclipse.jgit.lib.Repository gitRepo)
public File getLocalDirectory()
public void setLocalDirectory(File localDirectory)
public String getAddressGit()
public String getPathToLocalRepos()
public void setPathToLocalRepos(String pathToLocalRepos)
public BrowseResultDto browse(BrowseDto dto)
browse in interface ScmConnectionpublic CommitResultDto commit(CommitDto dto)
commit in interface ScmConnectionpublic File getFileContent(String path, String username, String password) throws AuthenticationException
getFileContent in interface ScmConnectionAuthenticationExceptionpublic String getHeadRevisionNumber(String path, String username, String password) throws AuthenticationException
getHeadRevisionNumber in interface ScmConnectionAuthenticationExceptionpublic String getRepositoryId()
getRepositoryId in interface ScmConnectionpublic String getFileName()
getFileName in interface ScmConnectionpublic String getFilePath(String address, String repositoryRoot, String username, String password)
getFilePath in interface ScmConnectionpublic Map<ScmRevision,String> getRevisions(String address, String username, String password)
getRevisions in interface ScmConnectionpublic File getFileContentAtRevision(String path, String username, String password, String revision) throws AuthenticationException
getFileContentAtRevision in interface ScmConnectionAuthenticationExceptionpublic File getDiffs(String path, String username, String password, String revision1, String revision2) throws AuthenticationException
getDiffs in interface ScmConnectionAuthenticationExceptionpublic void changeBranch(String branchName) throws IOException
branchName - the new branch's nameIOException - if reaching the repository is not possiblepublic void updateRepository(String username, String password) throws RepositoryNotFoundException
username - the username to use to connect to the repositorypassword - the password to use to connect to the repositoryRepositoryNotFoundException - if the repository is not foundprotected void cloneRepository(org.eclipse.jgit.transport.CredentialsProvider credentials)
throws IOException,
AuthenticationException,
RepositoryNotFoundException
credentials - the username and password to use to connect to the repositoryRepositoryNotFoundException - if the repository is not foundIOException - if it is not possible to reach the repositoryAuthenticationException - if there is a problem during the authentication processprotected String hash(String toHash, String algorithm)
toHash - the String to hashalgorithm - the algorithm to use to hash the Stringprotected void doCommit(org.eclipse.jgit.api.Git git,
String authorName,
String authorEmail,
String commitMessage)
throws org.eclipse.jgit.api.errors.GitAPIException
git - the git repository which will receive the commitauthorName - the name of the commit's authorauthorEmail - the e-mail address of the authorcommitMessage - the message that describes the commitorg.eclipse.jgit.api.errors.GitAPIException - if there is a problem during the commit processprotected void handlePushException(org.eclipse.jgit.api.errors.GitAPIException e)
e - the exception thrown by a push commandCopyright © 2015–2017 CodeLutin. All rights reserved.