當前位置: 首頁>>代碼示例>>Java>>正文


Java CloneCommand.setBranch方法代碼示例

本文整理匯總了Java中org.eclipse.jgit.api.CloneCommand.setBranch方法的典型用法代碼示例。如果您正苦於以下問題:Java CloneCommand.setBranch方法的具體用法?Java CloneCommand.setBranch怎麽用?Java CloneCommand.setBranch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jgit.api.CloneCommand的用法示例。


在下文中一共展示了CloneCommand.setBranch方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: load

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
/**
 * 從指定的git倉庫地址(目前僅支持http和https)和文件名獲取資源,通過UsernameCredential支持鑒權
 * @return 資源的字符串
 * @throws Exception 資源不存在或網絡不通
 */
@Override
public String load() throws Exception {
    //本地臨時目錄,用戶存放clone的代碼
    String tempDirPath = localPath + "/iaac.aliyun.tmp_" + new Date().getTime();
    File tempDir = new File(tempDirPath);
    tempDir.mkdirs();
    String result = null;
    try {
        CloneCommand clone = Git.cloneRepository();
        clone.setURI(url);
        clone.setBranch(this.branch);
        clone.setDirectory(tempDir);

        //設置鑒權
        if (this.credential != null) {
            UsernamePasswordCredentialsProvider usernamePasswordCredentialsProvider = new
                    UsernamePasswordCredentialsProvider(this.credential.getUsername(), this.credential.getPassword());
            //git倉庫地址
            clone.setCredentialsProvider(usernamePasswordCredentialsProvider);
        }
        //執行clone
        Git git = clone.call();
        //從本地路徑中獲取指定的文件
        File file = new File(tempDir.getAbsolutePath() + "/" + this.fileName);
        //返回文件的字符串
        result = FileUtils.readFileToString(file, "utf-8");
    } catch (Exception e) {
        throw e;
    } finally {
        //清除本地的git臨時目錄
        FileUtils.deleteDirectory(tempDir);
    }
    return result;
}
 
開發者ID:peterchen82,項目名稱:iaac4j.aliyun,代碼行數:40,代碼來源:GitLoader.java

示例2: cloneRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
/**
 *
 * Clones a git repository using the given uri and stores it in the parent directory. Checks out the
 * given reference or (if value is null) does not check out a branch
 * (which reduces time needed to complete command).
 * @param cloneURI the uri to the remote repository
 * @param parentDirectory the directory in which to store the git meta directory (".git" directory)
 * @param checkoutRef the ref name ("refs/heads/master"), branch name ("master") or tag name ("v1.2.3"). If
 *                    {@code null} is passed, will not checkout a branch.
 * @param branchesToClone the branches to clone or all branches if passed a {@code null} value.
 * @param monitor reports the progress of the clone command; can be null
 * @return the cloned Git repository
 * @throws GitAPIException
 */
public static Git cloneRepo(String cloneURI, File parentDirectory, String remoteName,
                            String checkoutRef, List<String> branchesToClone, ProgressMonitor monitor) throws GitAPIException {
    CloneCommand clone = Git.cloneRepository();

    if (checkoutRef == null) {
        clone.setNoCheckout(true);
    } else {
        clone.setBranch(checkoutRef);
    }

    if (branchesToClone == null) {
        clone.setCloneAllBranches(true);
    } else {
        clone.setBranchesToClone(branchesToClone);
    }

    if (monitor != null) { clone.setProgressMonitor(monitor); }

    return clone
            .setURI(cloneURI)
            .setDirectory(parentDirectory)
            .setRemote(remoteName)
            .call();
}
 
開發者ID:JordanMartinez,項目名稱:JGitFX,代碼行數:39,代碼來源:GitHelper.java

示例3: fetchMaterial

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Override
public String fetchMaterial(FetchMaterialTask task) {
    String errorMessage = null;
    String materialPath = Paths.get(AgentConfiguration.getInstallInfo().getAgentPipelinesDir(), task.getPipelineName(), task.getDestination()).toString();
    GitMaterial definition = (GitMaterial) task.getMaterialDefinition();
    CloneCommand clone = Git.cloneRepository();
    clone.setURI(definition.getRepositoryUrl());
    clone.setBranch(definition.getBranch());
    clone.setDirectory(new File(materialPath));
    clone.setCloneSubmodules(true);
    UsernamePasswordCredentialsProvider credentials = this.handleCredentials(definition);
    clone.setCredentialsProvider(credentials);
    try {
        Git git = clone.call();
        git.close();
    } catch (GitAPIException e) {
        errorMessage = e.getMessage();
    }

    return errorMessage;
}
 
開發者ID:rndsolutions,項目名稱:hawkcd,代碼行數:22,代碼來源:GitMaterialService.java

示例4: call

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
public Git call(final GitOperationsStep gitOperationsStep, Git git,
    CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder)
    throws InvalidRemoteException, TransportException, GitAPIException {

  CloneCommand cc = Git.cloneRepository().setURI(gitRepoUrl)
      .setDirectory(gitRepoFolder);

  if (!Const.isEmpty(this.branchName)) {
    cc = cc.setBranch(gitOperationsStep
        .environmentSubstitute(this.branchName));
  }
  cc.setCloneAllBranches(this.cloneAllBranches).setCloneSubmodules(
      this.cloneSubModules);
  if (cp != null) {
    cc.setCredentialsProvider(cp);
  }
  return cc.setBare(false).call();
}
 
開發者ID:ivylabs,項目名稱:ivy-pdi-git-steps,代碼行數:19,代碼來源:CloneGitCommand.java

示例5: cloneRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
public static boolean cloneRepo(final String uri, final File cloneTo,
                                final String branch,
                                final GitCloneProgressCallback callback) {
    Git result = null;

    try {
        final CloneCommand clone = Git.cloneRepository()
                .setURI(uri).setDirectory(cloneTo)
                .setBare(false).setRemote(REMOTE_NAME).setNoCheckout(false)
                .setCloneAllBranches(false).setCloneSubmodules(false)
                .setProgressMonitor(callback);

        if (!branch.isEmpty()) {
            if (branch.contains("/")) {
                clone.setBranch(branch.substring(branch.lastIndexOf('/') + 1));
            } else {
                clone.setBranch(branch);
            }
        }

        result = clone.call();
        return true;
    } catch (GitAPIException e) {
        e.printStackTrace();
    } finally {
        if (result != null) {
            result.close();
        }
    }
    return false;
}
 
開發者ID:LonamiWebs,項目名稱:Stringlate,代碼行數:32,代碼來源:GitWrapper.java

示例6: cloneRepo

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
public void cloneRepo(String branch) throws Exception {
    CloneCommand cloneCommand = Git.cloneRepository().setURI(repositoryUrl).setDirectory(localRepo.getDirectory().getParentFile());
    if (branch != null)
        cloneCommand.setBranch(branch);
    if (credentialsProvider != null)
        cloneCommand.setCredentialsProvider(credentialsProvider);
    cloneCommand.call();
}
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:9,代碼來源:VersionControlGit.java

示例7: execute

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Override
public void execute() {
        try {
                CloneCommand cloneCommand = new CloneCommand();

                if (branchToTrack != null) {
                        cloneCommand.setBranch(branchToTrack);
                }

                if (!branchNames.isEmpty()) {
                        cloneCommand.setBranchesToClone(branchNames);
                }

                cloneCommand.setURI(getUri()).
                        setBare(bare).
                        setCloneAllBranches(cloneAllBranches).
                        setCloneSubmodules(cloneSubModules).
                        setNoCheckout(noCheckout).
                        setDirectory(getDirectory());

                setupCredentials(cloneCommand);

                if (getProgressMonitor() != null) {
                        cloneCommand.setProgressMonitor(getProgressMonitor());
                }

                cloneCommand.call();
        }
        catch (Exception e) {
                throw new GitBuildException(String.format(MESSAGE_CLONE_FAILED, getUri()), e);
        }
}
 
開發者ID:rimerosolutions,項目名稱:ant-git-tasks,代碼行數:33,代碼來源:CloneTask.java

示例8: cloneAndCheckout

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
void cloneAndCheckout(BuildRequest request) throws ScmException {
    final Path dir = request.getProjectRootDirectory();

    final SrcVersion srcVersion = request.getSrcVersion();
    ScmException lastException = null;

    /* Try the urls one after another and exit on the first success */
    for (String url : request.getScmUrls()) {
        String useUrl = stripUriPrefix(url);
        log.info("srcdeps: attempting to clone version {} from SCM URL {}", request.getSrcVersion(), useUrl);

        CloneCommand cmd = Git.cloneRepository().setURI(useUrl).setDirectory(dir.toFile());

        switch (srcVersion.getWellKnownType()) {
        case branch:
        case tag:
            cmd.setBranch(srcVersion.getScmVersion());
            break;
        case revision:
            cmd.setCloneAllBranches(true);
            break;
        default:
            throw new IllegalStateException("Unexpected " + WellKnownType.class.getName() + " value '"
                    + srcVersion.getWellKnownType() + "'.");
        }

        try (Git git = cmd.call()) {
            git.checkout().setName(srcVersion.getScmVersion()).call();

            /*
             * workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474093
             */
            git.getRepository().close();

            /* return on the first success */
            return;
        } catch (Exception e) {
            log.warn("srcdeps: could not checkout version {} from SCM URL {}: {}: {}", request.getSrcVersion(),
                    useUrl, e.getClass().getName(), e.getMessage());
            lastException = new ScmException(String.format("Could not checkout from URL [%s]", useUrl), e);
        }
    }
    throw lastException;
}
 
開發者ID:srcdeps,項目名稱:srcdeps-core,代碼行數:45,代碼來源:JGitScm.java

示例9: createMember

import org.eclipse.jgit.api.CloneCommand; //導入方法依賴的package包/類
@Override
public void createMember(RequestContext ctx, ResourceState state, Responder responder) throws Exception {
    String gitUrl = state.getPropertyAsString("url");
    String id = state.id();
    String branch = state.getPropertyAsString("branch");
    String user = state.getPropertyAsString("user");
    String password = state.getPropertyAsString("pwd");
    String passphrase = state.getPropertyAsString("passphrase");

    if (!hasValue(gitUrl)) {
        responder.invalidRequest(String.format(INVALID_REQUEST_MESSAGE, gitUrl));
        return;
    }

    if (!hasValue(id)) {
        int start = gitUrl.lastIndexOf('/');
        int end = gitUrl.indexOf(".git", start);
        id = gitUrl.substring(start + 1, end);
    }

    File installDir = new File(this.appsDir, id);
    boolean cloneSucceeded = false;

    try {
        CloneCommand cloneCommand = Git.cloneRepository()
                .setURI(gitUrl)
                .setRemote("upstream")
                .setDirectory(installDir);

        if (hasValue(branch)) {
            // Set branch to checkout
            cloneCommand.setBranch(branch);
        }

        if (hasValue(user) && hasValue(password)) {
            // Set credentials for cloning
            cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password));
        }

        if (hasValue(passphrase)) {
            // Set SSH factory
            SshSessionFactory.setInstance(new LiveOakSshSessionFactory(passphrase));
        }

        Git repo = cloneCommand.call();
        repo.close();
        cloneSucceeded = true;
    } catch (InvalidRemoteException ire) {
        responder.invalidRequest(String.format(INVALID_REQUEST_MESSAGE, gitUrl));
        return;
    } catch (TransportException te) {
        responder.invalidRequest("Unable to connect to git repo due to: " + te.getMessage());
        return;
    } finally {
        if (!cloneSucceeded && installDir.exists()) {
            // Remove application directory
            FileHelper.deleteNonEmpty(installDir);
        }
    }

    InternalApplication app = this.registry.createApplication(id, (String) state.getProperty("name"), installDir, dir -> {
        try {
            Git gitRepo = GitHelper.initRepo(dir);
            GitHelper.addAllAndCommit(gitRepo, ctx.securityContext().getUser(), "Import LiveOak application from git: " + gitUrl);
            gitRepo.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    responder.resourceCreated(app.resource());
}
 
開發者ID:liveoak-io,項目名稱:liveoak,代碼行數:72,代碼來源:GitApplicationsResource.java


注:本文中的org.eclipse.jgit.api.CloneCommand.setBranch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。