Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public Mono<MergeStatusDTO> pullArtifactWithoutCheckout(
}
}
})
.onErrorResume(error -> resetToLastCommit(git).flatMap(ignore -> Mono.error(error)))
.onErrorResume(error -> Mono.error(error))
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpan.FS_PULL)
.tap(Micrometer.observation(observationRegistry)),
Expand Down Expand Up @@ -626,7 +626,7 @@ public Mono<MergeStatusDTO> pullApplication(
}
}
})
.onErrorResume(error -> resetToLastCommit(git).flatMap(ignore -> Mono.error(error)))
.onErrorResume(error -> Mono.error(error))
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpan.FS_PULL)
.tap(Micrometer.observation(observationRegistry)),
Expand Down Expand Up @@ -757,15 +757,6 @@ public Mono<GitStatusDTO> getStatus(Path repoPath, String branchName) {
response.setRemoteBranch("untracked");
}

// Remove modified changes from current branch so that checkout to other branches
// will be possible
if (!status.isClean()) {
return resetToLastCommit(git).map(ref -> {
processStopwatch.stopAndLogTimeInMillis();
jgitStatusSpan.end();
return response;
});
}
processStopwatch.stopAndLogTimeInMillis();
jgitStatusSpan.end();
return Mono.just(response);
Expand Down Expand Up @@ -983,13 +974,7 @@ public Mono<String> mergeBranch(Path repoSuffix, String sourceBranch, String des
}
})
.onErrorResume(error -> {
try {
return resetToLastCommit(repoSuffix, destinationBranch)
.thenReturn(error.getMessage());
} catch (GitAPIException | IOException e) {
log.error("Error while hard resetting to latest commit {0}", e);
return Mono.error(e);
}
return Mono.error(error);
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpan.FS_MERGE)
Expand Down Expand Up @@ -1161,31 +1146,13 @@ public Mono<MergeStatusDTO> isMergeBranch(Path repoSuffix, String sourceBranch,
mergeResult.getMergeStatus().name());
return mergeStatus;
})
.flatMap(status -> {
try {
// Revert uncommitted changes if any
return resetToLastCommit(repoSuffix, destinationBranch)
.map(ignore -> {
processStopwatch.stopAndLogTimeInMillis();
return status;
});
} catch (GitAPIException | IOException e) {
log.error("Error for hard resetting to latest commit {0}", e);
return Mono.error(e);
}
})
.onErrorResume(error -> {
MergeStatusDTO mergeStatusDTO = new MergeStatusDTO();
mergeStatusDTO.setMergeAble(false);
mergeStatusDTO.setMessage(error.getMessage());
mergeStatusDTO.setReferenceDoc(ErrorReferenceDocUrl.GIT_MERGE_CONFLICT.getDocUrl());
try {
return resetToLastCommit(repoSuffix, destinationBranch)
.thenReturn(mergeStatusDTO);
} catch (GitAPIException | IOException e) {
log.error("Error while hard resetting to latest commit {0}", e);
return Mono.error(e);
}

return Mono.just(mergeStatusDTO);
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)),
Git::close)
Expand Down Expand Up @@ -1267,12 +1234,11 @@ private Mono<Ref> resetToLastCommit(Git git) {
.subscribeOn(scheduler);
}

public Mono<Boolean> resetToLastCommit(Path repoSuffix, String branchName) throws GitAPIException, IOException {
public Mono<Boolean> resetToLastCommit(Path repoSuffix, String branchName) {
return Mono.using(
() -> Git.open(createRepoPath(repoSuffix).toFile()),
git -> this.resetToLastCommit(git)
.flatMap(ref -> checkoutToBranch(repoSuffix, branchName))
.flatMap(checkedOut -> resetToLastCommit(git).thenReturn(true)),
.flatMap(ref -> checkoutToBranch(repoSuffix, branchName).thenReturn(true)),
Git::close);
}

Expand Down Expand Up @@ -1302,7 +1268,7 @@ public Mono<Boolean> resetHard(Path repoSuffix, String branchName) {
}

public Mono<Boolean> rebaseBranch(Path repoSuffix, String branchName) {
return this.checkoutToBranch(repoSuffix, branchName).flatMap(isCheckedOut -> Mono.using(
return this.resetToLastCommit(repoSuffix, branchName).flatMap(isCheckedOut -> Mono.using(
() -> Git.open(createRepoPath(repoSuffix).toFile()),
git -> Mono.fromCallable(() -> {
Span jgitRebaseSpan = observationHelper.createSpan(GitSpan.JGIT_REBASE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public Mono<MergeStatusDTO> pullApplication(
}
}
})
.onErrorResume(error -> resetToLastCommit(git).flatMap(ignore -> Mono.error(error)))
.onErrorResume(error -> Mono.error(error))
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpan.FS_PULL)
.tap(Micrometer.observation(observationRegistry)),
Expand Down Expand Up @@ -626,15 +626,6 @@ public Mono<GitStatusDTO> getStatus(Path repoPath, String branchName) {
response.setRemoteBranch("untracked");
}

// Remove modified changes from current branch so that checkout to other branches
// will be possible
if (!status.isClean()) {
return resetToLastCommit(git).map(ref -> {
processStopwatch.stopAndLogTimeInMillis();
jgitStatusSpan.end();
return response;
});
}
processStopwatch.stopAndLogTimeInMillis();
jgitStatusSpan.end();
return Mono.just(response);
Expand Down Expand Up @@ -853,13 +844,7 @@ public Mono<String> mergeBranch(Path repoSuffix, String sourceBranch, String des
}
})
.onErrorResume(error -> {
try {
return resetToLastCommit(repoSuffix, destinationBranch)
.thenReturn(error.getMessage());
} catch (GitAPIException | IOException e) {
log.error("Error while hard resetting to latest commit {0}", e);
return Mono.error(e);
}
return Mono.error(error);
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS))
.name(GitSpan.FS_MERGE)
Expand Down Expand Up @@ -1028,19 +1013,6 @@ public Mono<MergeStatusDTO> isMergeBranch(Path repoSuffix, String sourceBranch,
mergeResult.getMergeStatus().name());
return mergeStatus;
})
.flatMap(status -> {
try {
// Revert uncommitted changes if any
return resetToLastCommit(repoSuffix, destinationBranch)
.map(ignore -> {
processStopwatch.stopAndLogTimeInMillis();
return status;
});
} catch (GitAPIException | IOException e) {
log.error("Error for hard resetting to latest commit {0}", e);
return Mono.error(e);
}
})
.timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)),
Git::close)
.subscribeOn(scheduler);
Expand Down Expand Up @@ -1121,12 +1093,12 @@ private Mono<Ref> resetToLastCommit(Git git) {
.subscribeOn(scheduler);
}

public Mono<Boolean> resetToLastCommit(Path repoSuffix, String branchName) throws GitAPIException, IOException {
public Mono<Boolean> resetToLastCommit(Path repoSuffix, String branchName) {
return Mono.using(
() -> Git.open(createRepoPath(repoSuffix).toFile()),
git -> this.resetToLastCommit(git)
.flatMap(ref -> checkoutToBranch(repoSuffix, branchName))
.flatMap(checkedOut -> resetToLastCommit(git).thenReturn(true)),
.thenReturn(true),
Git::close);
}

Expand Down Expand Up @@ -1156,7 +1128,7 @@ public Mono<Boolean> resetHard(Path repoSuffix, String branchName) {
}

public Mono<Boolean> rebaseBranch(Path repoSuffix, String branchName) {
return this.checkoutToBranch(repoSuffix, branchName).flatMap(isCheckedOut -> Mono.using(
return this.resetToLastCommit(repoSuffix, branchName).flatMap(isCheckedOut -> Mono.using(
() -> Git.open(createRepoPath(repoSuffix).toFile()),
git -> Mono.fromCallable(() -> {
Span jgitRebaseSpan = observationHelper.createSpan(GitSpan.JGIT_REBASE);
Expand Down
Loading