mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 22:15:51 +01:00
Git repository creation works now!
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
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
|
||||
import org.apache.commons.io._
|
||||
|
||||
/**
|
||||
* Creates new repository.
|
||||
@@ -16,33 +15,41 @@ class CreateRepositoryServlet extends ScalatraServlet with ServletBase {
|
||||
/**
|
||||
* Show the new repository form.
|
||||
*/
|
||||
get("/new") {
|
||||
get("/") {
|
||||
html.newrepo.render()
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new repository.
|
||||
*/
|
||||
post("/new") {
|
||||
post("/") {
|
||||
val repositoryName = params("name")
|
||||
val description = params("description")
|
||||
|
||||
val dir = new File(getRepositoryDir(LoginUser, repositoryName), ".git")
|
||||
val dir = getRepositoryDir(LoginUser, repositoryName)
|
||||
val repository = new RepositoryBuilder()
|
||||
.setGitDir(dir)
|
||||
.build()
|
||||
.setBare
|
||||
.build
|
||||
|
||||
repository.create
|
||||
|
||||
|
||||
if(description.nonEmpty){
|
||||
val tmpdir = getInitRepositoryDir(LoginUser, repositoryName)
|
||||
Git.cloneRepository.setURI(dir.toURI.toString).setDirectory(tmpdir).call
|
||||
|
||||
// Create README.md
|
||||
val readme = new File(dir.getParentFile, "README.md")
|
||||
val readme = new File(tmpdir, "README.md")
|
||||
FileUtils.writeStringToFile(readme,
|
||||
repositoryName + "\n===============\n\n" + description, "UTF-8")
|
||||
|
||||
val git = new Git(repository)
|
||||
val git = Git.open(tmpdir)
|
||||
git.add.addFilepattern("README.md").call
|
||||
git.commit.setMessage("Initial commit").call
|
||||
git.push.call
|
||||
|
||||
FileUtils.deleteDirectory(tmpdir)
|
||||
}
|
||||
|
||||
// redirect to the repository
|
||||
|
||||
@@ -112,7 +112,7 @@ class RepositoryViewerServlet extends ScalatraServlet with ServletBase {
|
||||
def getRepositoryInfo(owner: String, repository: String) = {
|
||||
val git = Git.open(getRepositoryDir(owner, repository))
|
||||
RepositoryInfo(
|
||||
owner, repository, "https://github.com/takezoe/%s.git".format(repository),
|
||||
owner, repository, "http://localhost:8080/git/%s/%s.git".format(owner, repository),
|
||||
// branches
|
||||
git.branchList.call.toArray.map { ref =>
|
||||
ref.asInstanceOf[Ref].getName.replaceFirst("^refs/heads/", "")
|
||||
@@ -139,10 +139,15 @@ class RepositoryViewerServlet extends ScalatraServlet with ServletBase {
|
||||
branchList.foreach { branch =>
|
||||
val branchdir = getBranchDir(owner, repository, branch)
|
||||
if(!branchdir.exists){
|
||||
FileUtils.copyDirectory(dir, branchdir)
|
||||
branchdir.mkdirs()
|
||||
Git.cloneRepository
|
||||
.setURI(dir.toURL.toString)
|
||||
.setDirectory(branchdir)
|
||||
.call
|
||||
Git.open(branchdir).checkout.setName(branch).call
|
||||
} else {
|
||||
Git.open(branchdir).pull.call
|
||||
}
|
||||
// TODO コピー元のリポジトリからpullする?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,18 +4,19 @@ import java.io.File
|
||||
|
||||
object Directory {
|
||||
|
||||
val GitBucketHome = "C:/Users/takez_000/gitbucket"
|
||||
val GitBucketHome = "C:/Users/takezoe/gitbucket/"
|
||||
|
||||
def getRepositories(owner: String): List[String] =
|
||||
new File("%s/%s".format(GitBucketHome, owner)).listFiles.filter(_.isDirectory).map(_.getName).toList
|
||||
new File("%s/repositories/%s".format(GitBucketHome, owner))
|
||||
.listFiles.filter(_.isDirectory).map(_.getName.replaceFirst("\\.git$", "")).toList
|
||||
|
||||
def getRepositoryDir(owner: String, repository: String): File =
|
||||
new File("%s/%s/%s/repository".format(GitBucketHome, owner, repository))
|
||||
new File("%s/repositories/%s/%s.git".format(GitBucketHome, owner, repository))
|
||||
|
||||
def getBranchDir(owner: String, repository: String, branch: String): File =
|
||||
new File("%s/%s/%s/branch/%s".format(GitBucketHome, owner, repository, branch))
|
||||
new File("%s/tmp/%s/branches/%s/%s".format(GitBucketHome, owner, repository, branch))
|
||||
|
||||
def getTagDir(owner: String, repository: String, tag: String): File =
|
||||
new File("%s/%s/%s/tags/%s".format(GitBucketHome, owner, repository, tag))
|
||||
def getInitRepositoryDir(owner: String, repository: String): File =
|
||||
new File("%s/tmp/%s/init-%s".format(GitBucketHome, owner, repository))
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
<servlet-class>org.eclipse.jgit.http.server.GitServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>base-path</param-name>
|
||||
<param-value>C:/Users/takez_000/gitbucket/takezoe</param-value>
|
||||
<param-value>C:/Users/takezoe/gitbucket/repositories</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>export-all</param-name>
|
||||
|
||||
Reference in New Issue
Block a user