Use dedicated exception for default branch deletion

This commit is contained in:
Rene Pfeuffer
2019-11-11 16:51:46 +01:00
parent f7e42db850
commit 8ed874c103
5 changed files with 32 additions and 3 deletions

View File

@@ -33,6 +33,7 @@
package sonia.scm.repository.spi;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Ref;
import sonia.scm.event.ScmEventBus;
@@ -94,6 +95,8 @@ public class GitBranchCommand extends AbstractGitCommand implements BranchComman
.setForce(true)
.call();
eventBus.post(new PostReceiveRepositoryHookEvent(hookEvent));
} catch (CannotDeleteCurrentBranchException e) {
throw new CannotDeleteDefaultBranchException(context.getRepository(), branchName);
} catch (GitAPIException | IOException ex) {
throw new InternalRepositoryException(entity(context.getRepository()), String.format("Could not delete branch: %s", branchName));
}