Skip to content

Commit

Permalink
fix: Current branch delete exception in delete branch API (appsmithor…
Browse files Browse the repository at this point in the history
…g#12699)

* Handle current branch delete exception

* Updated error message

* Update error message
  • Loading branch information
AnaghHegde committed Apr 8, 2022
1 parent 6cdef28 commit f9f689a
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.appsmith.server.solutions.ImportExportApplicationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.EmptyCommitException;
import org.eclipse.jgit.api.errors.GitAPIException;
Expand Down Expand Up @@ -2070,6 +2071,13 @@ public Mono<Application> deleteBranch(String defaultApplicationId, String branch
return Mono.error(new AppsmithException(AppsmithError.GIT_ACTION_FAILED, " delete branch", "Cannot delete default branch"));
}
return gitExecutor.deleteBranch(repoPath, branchName)
.onErrorResume(throwable -> {
log.error("Delete branch failed ", throwable.getMessage());
if(throwable instanceof CannotDeleteCurrentBranchException) {
return Mono.error(new AppsmithException(AppsmithError.GIT_ACTION_FAILED, "delete branch", "Cannot delete current checked out branch"));
}
return Mono.error(new AppsmithException(AppsmithError.GIT_ACTION_FAILED, "delete branch", throwable.getMessage()));
})
.flatMap(isBranchDeleted -> {
if(Boolean.FALSE.equals(isBranchDeleted)) {
return Mono.error(new AppsmithException(AppsmithError.GIT_ACTION_FAILED, " delete branch. Branch does not exists in the repo"));
Expand Down

0 comments on commit f9f689a

Please sign in to comment.