I am looking for ANY help with this. I have gitblit set up, I have used a slightly modified version of one of the groovy hooks scripts. I need a hook script that deploys the head to a folder, which can then be used as a webroot for that site in WAMP. Basically, the changes will be pushed to gitblit, and the script will deploy those changes on our development server, without any manual intervention. I had this working on subversion, with a simple svn update on a working copy as the webroot. Gitblit doesn't seem to be that easy.
If the clone folder already exists, I want it to perform a Pull command on the master. The clone code all works correctly and successfully creates a clone of the repos. But then when I push more changes, and the clone exists, it throws this error:
groovy.lang.MissingMethodException: No signature of method: static org.eclipse.j
git.api.Git.pull() is applicable for argument types: () values: []
The full groovy script is below. I'm a bit of a noob to groovy, and haven't used java properly for years, so any help would give you god-like status. Thanks in advance.
import com.gitblit.GitBlit
import com.gitblit.Keys
import com.gitblit.models.RepositoryModel
import com.gitblit.models.TeamModel
import com.gitblit.models.UserModel
import com.gitblit.utils.JGitUtils
import com.gitblit.utils.StringUtils
import java.text.SimpleDateFormat
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.Config
import org.eclipse.jgit.api.*;
import org.eclipse.jgit.api.errors.*;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.util.FileUtils
import org.slf4j.Logger
// Indicate we have started the script
logger.info("Deploying website (In Repository ${repository.name}) for ${user.username}")
def rootFolder = 'C:/Program Files/wamp/www/git-repositories'
def bare = false
def cloneAllBranches = true
def cloneBranch = 'refs/heads/master'
def includeSubmodules = true
def repoName = repository.name
def destinationFolder = new File(rootFolder, StringUtils.stripDotGit(repoName))
def srcUrl = 'file://' + new File(gitblit.getRepositoriesFolder(), repoName).absolutePath
// if there is already a clone
if (destinationFolder.exists()) {
PullCommand cmd = Git.pull();
}
else
{
// clone the repository
logger.info("cloning ${srcUrl} to ${destinationFolder}")
CloneCommand cmd = Git.cloneRepository();
cmd.setBare(bare)
if (cloneAllBranches)
cmd.setCloneAllBranches(true)
else
cmd.setBranch(cloneBranch)
cmd.setCloneSubmodules(includeSubmodules)
cmd.setURI(srcUrl)
cmd.setDirectory(destinationFolder)
Git git = cmd.call();
git.repository.close()
// report clone operation success back to pushing Git client
clientLogger.info("${repoName} cloned to ${destinationFolder}")
}
UPDATE: There are no more errors, but none of the changes seem to be pulling into the cloned repos:
logger.info("Development clone already exists, pulling changes...")
def cloneLocation = rootFolder + "/" + StringUtils.stripDotGit(repoName) + "";
FileRepository repo = new FileRepository("C:/Program Files/wamp/www/git-repositories/brightercreative.dev");
Git git = new Git(repo);
logger.info("Pulling changes from "+cloneLocation )
git.pull();
git.repository.close();
logger.info("Pulled changes "+cloneLocation )
thanks to @tim_yates for his help on this. Finally figured this out.
def cloneLocation = rootFolder + "/" + StringUtils.stripDotGit(repoName) + "";
// create the file repository object
FileRepository repo = new FileRepository("C:/myclonedrepos/.git");
// use the repository object to create a git object
Git git = new Git(repo);
// create a pull command
PullCommand pullCmd = git.pull();
// call the pull command
pullCmd.call();
git.repository.close();
logger.info("Pulled changes "+cloneLocation )
// report clone operation success back to pushing Git client
clientLogger.info("${repoName} pulled to ${destinationFolder}")