0

私はこれについて何か助けを探しています。私は gitblit をセットアップしました。groovy フック スクリプトの 1 つを少し変更したバージョンを使用しました。ヘッドをフォルダに展開するフック スクリプトが必要です。このスクリプトは、WAMP でそのサイトの Web ルートとして使用できます。基本的に、変更は gitblit にプッシュされ、スクリプトはこれらの変更を開発サーバーにデプロイします。手動の介入は必要ありません。私はこれをsubversionで動作させ、作業コピーをwebrootとして単純なsvn更新を行いました。Gitblit はそれほど簡単ではないようです。

クローン フォルダーが既に存在する場合は、マスターでプル コマンドを実行する必要があります。クローン コードはすべて正しく機能し、リポジトリのクローンを正常に作成します。しかし、さらに変更をプッシュし、クローンが存在すると、次のエラーがスローされます。

groovy.lang.MissingMethodException: No signature of method: static org.eclipse.j
git.api.Git.pull() is applicable for argument types: () values: []

完全な groovy スクリプトを以下に示します。私は Groovy には少し初心者で、何年も Java を適切に使用していません。前もって感謝します。

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}")
}

更新: エラーはもうありませんが、クローンされたリポジトリに変更が反映されていないようです:

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 )
4

1 に答える 1

3

@tim_yates の助けに感謝します。最後にこれを理解しました。

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}")
于 2014-03-12T15:56:58.687 に答える