in ddm-rrm-git-integration/src/main/java/com/epam/digital/data/platform/management/gitintegration/service/JGitServiceImpl.java [467:491]
private void doRollback(Git git, String filePath, File repositoryDirectory) {
try {
var lastCommit = git.log().call().iterator().next();
var parentCommit = lastCommit.getParent(0);
var isFileExistsInLastCommit = checkFileExistsInCommit(git, filePath, lastCommit);
var isFileExistsInParentCommit = checkFileExistsInCommit(git, filePath, parentCommit);
if (!isFileExistsInLastCommit && !isFileExistsInParentCommit) {
throw new GitFileNotFoundException(
String.format("Rollback failed, file %s doesn't exist", filePath), filePath);
}
if (isFileExistsInParentCommit) {
log.debug("Revert changed file to state as parent commit");
rollbackFileToParentCommit(git, filePath, parentCommit);
} else {
log.debug("Delete file because the parent commit does not contain it");
var file = new File(repositoryDirectory, FilenameUtils.normalize(filePath));
var isDeleted = file.delete();
log.debug("The file {} been deleted", isDeleted ? "has" : "has not");
}
} catch (GitAPIException e) {
throw new IllegalStateException(
String.format("Log command doesn't expected to throw such exception: %s", e.getMessage()),
e);
}
}