(refs #224)Add delete branch button

This commit is contained in:
takezoe
2014-02-03 08:00:43 +09:00
parent a87bd2a928
commit 2764caae29
2 changed files with 31 additions and 8 deletions

View File

@@ -3,7 +3,7 @@ package app
import util.Directory._
import util.Implicits._
import util.ControlUtil._
import _root_.util.{ReferrerAuthenticator, JGitUtil, FileUtil, StringUtil}
import _root_.util._
import service._
import org.scalatra._
import java.io.File
@@ -12,15 +12,16 @@ import org.eclipse.jgit.lib._
import org.apache.commons.io.FileUtils
import org.eclipse.jgit.treewalk._
import java.util.zip.{ZipEntry, ZipOutputStream}
import scala.Some
class RepositoryViewerController extends RepositoryViewerControllerBase
with RepositoryService with AccountService with ReferrerAuthenticator
with RepositoryService with AccountService with ReferrerAuthenticator with CollaboratorsAuthenticator
/**
* The repository viewer.
*/
trait RepositoryViewerControllerBase extends ControllerBase {
self: RepositoryService with AccountService with ReferrerAuthenticator =>
self: RepositoryService with AccountService with ReferrerAuthenticator with CollaboratorsAuthenticator =>
/**
* Returns converted HTML from Markdown for preview.
@@ -150,10 +151,23 @@ trait RepositoryViewerControllerBase extends ControllerBase {
val revCommit = git.log.add(git.getRepository.resolve(branchName)).setMaxCount(1).call.iterator.next
(branchName, revCommit.getCommitterIdent.getWhen)
}
repo.html.branches(branchInfo, repository)
repo.html.branches(branchInfo, hasWritePermission(repository.owner, repository.name, context.loginAccount), repository)
}
})
/**
* Deletes branch.
*/
get("/:owner/:repository/delete/:branchName")(collaboratorsOnly { repository =>
val branchName = params("branchName")
if(repository.repository.defaultBranch != branchName){
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
git.branchDelete().setBranchNames(branchName).call()
}
}
redirect(s"/${repository.owner}/${repository.name}/branches")
})
/**
* Displays tags.
*/