@Override
public String branchDelete(Demand demand) throws Exception {
logger.info("删除分支 => {}", JSON.toJSONString(demand, true));
try (Git git = initAndFetch(demand.getProjectId(), demand.getRespository())) {
if (exists(git.getRepository(), R_HEADS + demand.getDemandBranch())) {
//删除本地分支
git.branchDelete().setForce(true).setBranchNames(demand.getDemandBranch()).call();
}
// 判断远程分支是否已存在
RefSpec refSpec = new RefSpec().setSource(null).setDestination(R_HEADS+demand.getDemandBranch());
if (null == refSpec) {
logger.info("远程分支[{}]不存在", demand.getDemandBranch());
return "远程分支"+demand.getDemandBranch()+"不存在";
}
git.push().setRefSpecs(refSpec).setRemote(Constants.DEFAULT_REMOTE_NAME).call();
logger.info("删除分支[{}]成功", demand.getDemandBranch());
return "success";
} catch (Exception e) {
logger.error("Exception while deleteBranch: {}", JSON.toJSONString(demand), e);
throw e;
}
}