当前位置: 首页>>代码示例>>Java>>正文


Java CreateBranchCommand类代码示例

本文整理汇总了Java中org.eclipse.jgit.api.CreateBranchCommand的典型用法代码示例。如果您正苦于以下问题:Java CreateBranchCommand类的具体用法?Java CreateBranchCommand怎么用?Java CreateBranchCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CreateBranchCommand类属于org.eclipse.jgit.api包,在下文中一共展示了CreateBranchCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createBranch

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
 * Creates branch on provided repository - git branch name
 *
 * @param repositoryName for which repository
 * @param name of branch
 */
public void createBranch(String repositoryName, String name)
{
    RepositoryContext repositoryContext = repositoryByName.get(repositoryName);

    try
    {
        CreateBranchCommand createBranchCommand = repositoryContext.git.branchCreate();
        createBranchCommand.setName(name);
        createBranchCommand.call();
    }
    catch (GitAPIException e)
    {
        throw new RuntimeException(e);
    }
}
 
开发者ID:edgehosting,项目名称:jira-dvcs-connector,代码行数:22,代码来源:GitTestSupport.java

示例2: createBranch

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
 * Create a new branch in the local git repository
 * (git checkout -b branchname) and finally pushes new branch on the remote repository (git push)
 *
 * @param directory the directory in which the local git repository is located
 * @param username  the username to be used while pushing
 * @param password  the password matching with the provided username to be used
 *                  for authentication
 * @param message   the commit message to be used	 
 */
public static void createBranch(@NonNull File directory, String branchName, String username,
								String password, String message) throws GitAPIException {

	try {
		final Git git = Git.open(directory);

		final UsernamePasswordCredentialsProvider userCredential = new UsernamePasswordCredentialsProvider(
				username, password);

		CreateBranchCommand branchCommand = git.branchCreate();
		branchCommand.setName(branchName);
		branchCommand.call();
		
		// and then commit
		final PersonIdent author = new PersonIdent(username, "");
		git.commit().setCommitter(author).setMessage(message)
				.setAuthor(author).call();
		log.info(message);

		git.push().setCredentialsProvider(userCredential).call();
		log.info("Pushed the changes in remote Git repository...");
	} catch (final GitAPIException | IOException e) {
		log.error(e.getMessage(), e);
	}
}
 
开发者ID:awltech,项目名称:easycukes,代码行数:36,代码来源:GitHelper.java

示例3: checkoutBranch

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
protected void checkoutBranch(Git git, GitContext context) throws GitAPIException {
    String current = currentBranch(git);
    if (Objects.equals(current, branch)) {
        return;
    }
    System.out.println("Checking out branch: " + branch);
    // lets check if the branch exists
    CheckoutCommand command = git.checkout().setName(branch);
    boolean exists = localBranchExists(git, branch);
    if (!exists) {
        command = command.setCreateBranch(true).setForce(true).
                setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).
                setStartPoint(getRemote() + "/" + branch);
    }
    Ref ref = command.call();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Checked out branch " + branch + " with results " + ref.getName());
    }
    configureBranch(git, branch);
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:21,代码来源:RepositoryResource.java

示例4: branchCreate

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
@Override
public Branch branchCreate(String name, String startPoint) throws GitException {
  CreateBranchCommand createBranchCommand = getGit().branchCreate().setName(name);
  if (startPoint != null) {
    createBranchCommand.setStartPoint(startPoint);
  }
  try {
    Ref brRef = createBranchCommand.call();
    String refName = brRef.getName();
    String displayName = Repository.shortenRefName(refName);
    return newDto(Branch.class)
        .withName(refName)
        .withDisplayName(displayName)
        .withActive(false)
        .withRemote(false);
  } catch (GitAPIException exception) {
    throw new GitException(exception.getMessage(), exception);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:JGitConnection.java

示例5: checkoutToBranch

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
private void checkoutToBranch(String branch) throws GitAPIException {
  CheckoutCommand checkoutCommand = clonedRepo.checkout()
      .setCreateBranch(false)
      .setName(branch);

  List<Ref> refList = clonedRepo.branchList().call();
  if (!anyRefMatches(refList, branch)) {
    checkoutCommand = checkoutCommand
        .setCreateBranch(true)
        .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
        .setStartPoint("origin/" + branch);
  }

  checkoutCommand
      .call();
}
 
开发者ID:cfg4j,项目名称:cfg4j,代码行数:17,代码来源:GitConfigurationSource.java

示例6: createBranch

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
@Override
public String createBranch(String commitId, String branchName) {
    
    Ref result = null;
    CreateBranchCommand branchCreate = _git.branchCreate();
    branchCreate.setName(branchName);
    branchCreate.setStartPoint(commitId);
    try {
        result = branchCreate.call();
    } catch (Throwable e) {
        throw new RuntimeException(String.format(
                "Failed creating branch: %s for commit [%s]",
                branchName,
                commitId), e);
    }
    
    return result.getName();
}
 
开发者ID:Verigreen,项目名称:verigreen,代码行数:19,代码来源:JGitOperator.java

示例7: testPullRequest

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
 * Test the ghprb constructor.
 *
 * @throws Exception
 */
@Test
public void testPullRequest() throws Exception
{
    Map<String, byte[]> expectedContents = new HashMap<String, byte[]>();
    expectedContents.put("src/pages/modifyThis.page", contents.getBytes());
    expectedContents.put("src/pages/modifyThis.page-meta.xml", contents.getBytes());
    expectedContents.put("src/triggers/addThis.trigger", contents.getBytes());
    expectedContents.put("src/triggers/addThis.trigger-meta.xml", contents.getBytes());

    String oldBranch = "refs/remotes/origin/oldBranch";
    CreateBranchCommand cbc = new Git(repository).branchCreate();
    cbc.setName(oldBranch);
    cbc.setStartPoint(oldSha);
    cbc.call();

    git = new SMAGit(gitDir, newSha, "oldBranch", SMAGit.Mode.PRB);

    Map<String, byte[]> allMetadata = git.getAllMetadata();

    assertEquals(expectedContents.size(), allMetadata.size());
}
 
开发者ID:aesanch2,项目名称:salesforce-migration-assistant,代码行数:27,代码来源:SMAGitTest.java

示例8: checkoutBranch

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
public void checkoutBranch(final String branchName) {

        workspaceProvider.synchronizedOperation(new Callable<Void>() {
            @Override
            public Void call() {
                try {
                    git.branchCreate()
                            .setName(branchName)
                            .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
                            .setStartPoint("origin/" + branchName)
                            .setForce(true)
                            .call();
                    git.checkout().setName(branchName).call();
                } catch (final GitAPIException e) {
                    LOGGER.error("Unable to create/checkout branch " + branchName, e);
                }
                return null;
            }
        });
    }
 
开发者ID:indeedeng,项目名称:proctor,代码行数:21,代码来源:GitProctorCore.java

示例9: createBranch

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
public void createBranch(String branchName, String branchRevision) {
try {
	CreateBranchCommand command = git().branchCreate();
	command.setName(branchName);
	command.setStartPoint(getRevCommit(branchRevision));
	command.call();
} catch (GitAPIException e) {
	throw new RuntimeException(e);
}
  }
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:11,代码来源:Project.java

示例10: checkoutNewBranchFromRemote

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
 * Creates a new branch at the given start point and checks it out.
 * @param git the git repository
 * @param branchName the name of the new branch
 * @param startPoint the starting point of the new branch
 * @param upstreamMode whether to track the upstream branch or not.
 * @return the checked out branch
 * @throws GitAPIException
 */
public static Ref checkoutNewBranchFromRemote(
        Git git, String branchName, String startPoint,
        CreateBranchCommand.SetupUpstreamMode upstreamMode) throws GitAPIException {
    return git.checkout()
            .setCreateBranch(true)
            .setName(branchName)
            .setStartPoint(startPoint)
            .setUpstreamMode(upstreamMode)
            .call();
}
 
开发者ID:JordanMartinez,项目名称:JGitFX,代码行数:20,代码来源:GitHelper.java

示例11: createNewBranchFromRemote

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
public static Ref createNewBranchFromRemote(
        Git git, String branchName, RevCommit startingPoint,
        CreateBranchCommand.SetupUpstreamMode upstreamMode) throws GitAPIException {
    return git.branchCreate()
            .setStartPoint(startingPoint)
            .setName(branchName)
            .setUpstreamMode(upstreamMode)
            .call();
}
 
开发者ID:JordanMartinez,项目名称:JGitFX,代码行数:10,代码来源:GitHelper.java

示例12: initializeGit

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
private Git initializeGit() throws IOException, GitAPIException {
  if (path.isDirectory()) {
    Git git = Git.open(path);
    String current = git.getRepository().getBranch();
    if (branch.equalsIgnoreCase(current)) {
      PullResult pull = git.pull().setRemote(remote).call();
      if (!pull.isSuccessful()) {
        LOGGER.warn("Unable to pull the branch + '" + branch +
            "' from the remote repository '" + remote + "'");
      }
      return git;
    } else {
      git.checkout().
          setName(branch).
          setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).
          setStartPoint(remote + "/" + branch).
          call();
      return git;
    }
  } else {
    return Git.cloneRepository()
        .setURI(url)
        .setBranch(branch)
        .setRemote(remote)
        .setDirectory(path)
        .call();
  }
}
 
开发者ID:cescoffier,项目名称:vertx-configuration-service,代码行数:29,代码来源:GitConfigurationStore.java

示例13: checkoutBranch

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
 * Checkout existing branch.
 *
 * @param git
 *     instance.
 * @param branch
 *     to move
 * @param remote
 *     repository name
 *
 * @return Ref to current branch
 */
public Ref checkoutBranch(Git git, String branch, String remote) {
    try {
        return git.checkout()
            .setCreateBranch(true)
            .setName(branch)
            .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
            .setStartPoint(remote + "/" + branch)
            .call();
    } catch (GitAPIException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:arquillian,项目名称:arquillian-algeron,代码行数:25,代码来源:GitOperations.java

示例14: createBranchAndCheckout

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
 * Executes a checkout -b command using given branch.
 *
 * @param git
 *     instance.
 * @param branch
 *     to create and checkout.
 *
 * @return Ref to current branch.
 */
public Ref createBranchAndCheckout(Git git, String branch) {
    try {
        return git.checkout()
            .setCreateBranch(true)
            .setName(branch)
            .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
            .call();
    } catch (GitAPIException e) {
        throw new IllegalStateException(e);
    }
}
 
开发者ID:arquillian,项目名称:arquillian-algeron,代码行数:22,代码来源:GitOperations.java

示例15: checkout

import org.eclipse.jgit.api.CreateBranchCommand; //导入依赖的package包/类
/**
 * Does not do anything if already on target branch.
 */
public void checkout(String branch) throws Exception {
    if (!branch.equals(getBranch())) {
        createBranchIfNeeded(branch);
        git.checkout().setName(branch).setStartPoint("origin/" + branch)
            .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).call();
        // for some reason jgit needs this when branch is switched
        git.checkout().setName(branch).call();
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:13,代码来源:VersionControlGit.java


注:本文中的org.eclipse.jgit.api.CreateBranchCommand类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。