|
|
@ -48,15 +48,16 @@ public class IndexService {
|
|
|
|
public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException {
|
|
|
|
public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException {
|
|
|
|
Repository repository = repositoryRepository.findByUrl(repositoryUrl);
|
|
|
|
Repository repository = repositoryRepository.findByUrl(repositoryUrl);
|
|
|
|
if (repository == null) {
|
|
|
|
if (repository == null) {
|
|
|
|
repositoryRepository.save(new Repository(repositoryUrl));
|
|
|
|
repository = repositoryRepository.save(new Repository(repositoryUrl));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Branch branch = branchRepository.findByRepositoryAndName(repository, branchName);
|
|
|
|
Branch branch = branchRepository.findByRepositoryAndName(repository, branchName);
|
|
|
|
if (branch == null) {
|
|
|
|
if (branch == null) {
|
|
|
|
branch = branchRepository.save(new Branch(repository, branchName));
|
|
|
|
branch = branchRepository.save(new Branch(repository, branchName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Commit> commits = gitRepositoryService.getCommits(repositoryUrl, branchName);
|
|
|
|
List<Commit> commits = gitRepositoryService.getCommits(repositoryUrl, branchName);
|
|
|
|
commitRepository.deleteAll(branch.getCommits());
|
|
|
|
List<Commit> commitsToRemove = branch.getCommits();
|
|
|
|
branch.getCommits().clear();
|
|
|
|
branch.getCommits().clear();
|
|
|
|
|
|
|
|
commitRepository.deleteAll(commitsToRemove);
|
|
|
|
branch.setCommits(commits);
|
|
|
|
branch.setCommits(commits);
|
|
|
|
branchRepository.save(branch);
|
|
|
|
branchRepository.save(branch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|