Skip to content

Commit

Permalink
Return error message when trying to recreate a deleted branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiJun committed May 25, 2023
1 parent 30751d8 commit 0e850d4
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ public RefsResponse getBranch(String projectId, String id) {
public RefJson createBranch(String projectId, RefJson branch) {
Instant now = Instant.now();
ContextHolder.setContext(projectId);
Branch b = new Branch();

Optional<Branch> branchesOption = this.branchRepository.findByBranchId(branch.getId());
Branch b = branchesOption.orElseGet(Branch::new);
if (b.isDeleted()) {
throw new BadRequestException("Bad Request Error: Branch was previously deleted.");
}

b.setBranchId(branch.getId());
b.setBranchName(branch.getName());
Expand Down

0 comments on commit 0e850d4

Please sign in to comment.