Временные ряды #59
@ -192,6 +192,7 @@ public class GitRepositoryService {
|
||||
private void cloneOrUpdateRepo(String repositoryUrl, String branchName) throws GitAPIException, IOException {
|
||||
Git git;
|
||||
org.eclipse.jgit.lib.Repository localRepo;
|
||||
validateOrClearRepositoryDirectory(getProjectDirectoryFile(repositoryUrl));
|
||||
if (projectDirExists(getProjectDirectoryFile(repositoryUrl))) {
|
||||
localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
||||
git = new Git(localRepo);
|
||||
@ -210,6 +211,26 @@ public class GitRepositoryService {
|
||||
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 {
|
||||
cloneOrUpdateRepo(url, null);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user