mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
Merge pull request #1717 from gitbucket/refuse-delete-default-branch
Refuse deletion of the default branch
This commit is contained in:
@@ -46,12 +46,17 @@ trait ProtectedBranchService {
|
|||||||
|
|
||||||
object ProtectedBranchService {
|
object ProtectedBranchService {
|
||||||
|
|
||||||
class ProtectedBranchReceiveHook extends ReceiveHook with ProtectedBranchService {
|
class ProtectedBranchReceiveHook extends ReceiveHook with ProtectedBranchService with RepositoryService with AccountService {
|
||||||
override def preReceive(owner: String, repository: String, receivePack: ReceivePack, command: ReceiveCommand, pusher: String)
|
override def preReceive(owner: String, repository: String, receivePack: ReceivePack, command: ReceiveCommand, pusher: String)
|
||||||
(implicit session: Session): Option[String] = {
|
(implicit session: Session): Option[String] = {
|
||||||
val branch = command.getRefName.stripPrefix("refs/heads/")
|
val branch = command.getRefName.stripPrefix("refs/heads/")
|
||||||
if(branch != command.getRefName){
|
if(branch != command.getRefName){
|
||||||
|
val repositoryInfo = getRepository(owner, repository)
|
||||||
|
if(command.getType == ReceiveCommand.Type.DELETE && repositoryInfo.exists(_.repository.defaultBranch == branch)){
|
||||||
|
Some(s"refusing to delete the branch: ${command.getRefName}.")
|
||||||
|
} else {
|
||||||
getProtectedBranchInfo(owner, repository, branch).getStopReason(receivePack.isAllowNonFastForwards, command, pusher)
|
getProtectedBranchInfo(owner, repository, branch).getStopReason(receivePack.isAllowNonFastForwards, command, pusher)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user