Cloned repositories for internal use are updated after push.

This commit is contained in:
takezoe
2013-04-20 04:57:10 +09:00
parent 934c4af780
commit c531949fd9
4 changed files with 60 additions and 45 deletions

View File

@@ -1,6 +1,8 @@
package util
import java.io.File
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.Ref
/**
* Provides directories used by GitBucket.
@@ -43,4 +45,33 @@ object Directory {
def getInitRepositoryDir(owner: String, repository: String): File =
new File("%s/tmp/%s/init-%s".format(GitBucketHome, owner, repository))
def updateAllBranches(owner: String, repository: String): Unit = {
// TODO debug log
println("[pull]" + owner + "/" + repository)
val dir = Directory.getRepositoryDir(owner, repository)
val git = Git.open(dir)
val branchList = git.branchList.call.toArray.map { ref =>
ref.asInstanceOf[Ref].getName
}.toList
branchList.foreach { branch =>
val branchName = branch.replaceFirst("^refs/heads/", "")
val branchdir = Directory.getBranchDir(owner, repository, branchName)
if(!branchdir.exists){
branchdir.mkdirs()
Git.cloneRepository
.setURI(dir.toURL.toString)
.setBranch(branch)
.setDirectory(branchdir)
.call
Git.open(branchdir).checkout.setName(branchName).call
} else {
Git.open(branchdir).pull.call
}
}
}
}