mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
Initial Import.
This commit is contained in:
51
src/main/scala/app/CreateRepositoryServlet.scala
Normal file
51
src/main/scala/app/CreateRepositoryServlet.scala
Normal file
@@ -0,0 +1,51 @@
|
||||
package app
|
||||
|
||||
import util.Directory._
|
||||
|
||||
import org.scalatra._
|
||||
import java.io.File
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib._
|
||||
import org.apache.commons.io.FileUtils
|
||||
|
||||
/**
|
||||
* Creates new repository.
|
||||
*/
|
||||
class CreateRepositoryServlet extends ScalatraServlet with ServletBase {
|
||||
|
||||
/**
|
||||
* Show the new repository form.
|
||||
*/
|
||||
get("/new") {
|
||||
html.newrepo.render()
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new repository.
|
||||
*/
|
||||
post("/new") {
|
||||
val repositoryName = params("name")
|
||||
val description = params("description")
|
||||
|
||||
val dir = new File(getRepositoryDir(LoginUser, repositoryName), ".git")
|
||||
val repository = new RepositoryBuilder()
|
||||
.setGitDir(dir)
|
||||
.build()
|
||||
|
||||
repository.create
|
||||
|
||||
if(description.nonEmpty){
|
||||
// Create README.md
|
||||
val readme = new File(dir.getParentFile, "README.md")
|
||||
FileUtils.writeStringToFile(readme,
|
||||
repositoryName + "\n===============\n\n" + description, "UTF-8")
|
||||
|
||||
val git = new Git(repository)
|
||||
git.add.addFilepattern("README.md").call
|
||||
git.commit.setMessage("Initial commit").call
|
||||
}
|
||||
|
||||
// redirect to the repository
|
||||
redirect("/%s/%s".format(LoginUser, repositoryName))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user