Skip to content
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