|
|
@ -192,6 +192,7 @@ public class GitRepositoryService {
|
|
|
|
private void cloneOrUpdateRepo(String repositoryUrl, String branchName) throws GitAPIException, IOException {
|
|
|
|
private void cloneOrUpdateRepo(String repositoryUrl, String branchName) throws GitAPIException, IOException {
|
|
|
|
Git git;
|
|
|
|
Git git;
|
|
|
|
org.eclipse.jgit.lib.Repository localRepo;
|
|
|
|
org.eclipse.jgit.lib.Repository localRepo;
|
|
|
|
|
|
|
|
validateOrClearRepositoryDirectory(getProjectDirectoryFile(repositoryUrl));
|
|
|
|
if (projectDirExists(getProjectDirectoryFile(repositoryUrl))) {
|
|
|
|
if (projectDirExists(getProjectDirectoryFile(repositoryUrl))) {
|
|
|
|
localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
|
|
|
localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
|
|
|
git = new Git(localRepo);
|
|
|
|
git = new Git(localRepo);
|
|
|
@ -210,6 +211,26 @@ public class GitRepositoryService {
|
|
|
|
git.close();
|
|
|
|
git.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void validateOrClearRepositoryDirectory(File projectDirectory) {
|
|
|
|
|
|
|
|
if (projectDirectory.exists()) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Git.open(projectDirectory).status().call();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
deleteDirectory(projectDirectory);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean deleteDirectory(File directoryToBeDeleted) {
|
|
|
|
|
|
|
|
File[] allContents = directoryToBeDeleted.listFiles();
|
|
|
|
|
|
|
|
if (allContents != null) {
|
|
|
|
|
|
|
|
for (File file : allContents) {
|
|
|
|
|
|
|
|
deleteDirectory(file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return directoryToBeDeleted.delete();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void cloneOrUpdateRepo(String url) throws GitAPIException, IOException {
|
|
|
|
private void cloneOrUpdateRepo(String url) throws GitAPIException, IOException {
|
|
|
|
cloneOrUpdateRepo(url, null);
|
|
|
|
cloneOrUpdateRepo(url, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|