implement deleteBranchCommand for git

This commit is contained in:
Eduard Heimbuch
2019-11-11 11:15:56 +01:00
parent 73cdab4ddc
commit 7cd2cb4ccb
4 changed files with 40 additions and 0 deletions

View File

@@ -45,8 +45,11 @@ import sonia.scm.repository.Repository;
import sonia.scm.repository.api.BranchRequest;
import sonia.scm.repository.util.WorkingCopy;
import java.io.IOException;
import java.util.stream.StreamSupport;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
public class GitBranchCommand extends AbstractGitCommand implements BranchCommand {
private final GitWorkdirFactory workdirFactory;
@@ -73,6 +76,19 @@ public class GitBranchCommand extends AbstractGitCommand implements BranchComman
}
}
@Override
public void delete(String branchName) {
try (Git gitRepo = new Git(context.open())) {
gitRepo
.branchDelete()
.setBranchNames(branchName)
.setForce(true)
.call();
} catch (GitAPIException | IOException ex) {
throw new InternalRepositoryException(entity(context.getRepository()), String.format("Could not delete branch: %s", branchName));
}
}
private void handlePushError(RemoteRefUpdate remoteRefUpdate, BranchRequest request, Repository repository) {
if (remoteRefUpdate.getStatus() != RemoteRefUpdate.Status.OK) {
// TODO handle failed remote update