Java 类org.eclipse.jgit.api.CreateBranchCommand 实例源码

项目:fabric8-forge    文件:RepositoryResource.java   
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);
}
项目:jira-dvcs-connector    文件:GitTestSupport.java   
/**
 * 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);
    }
}
项目:che    文件:JGitConnection.java   
@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);
  }
}
项目:cfg4j    文件:GitConfigurationSource.java   
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();
}
项目:verigreen    文件:JGitOperator.java   
@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();
}
项目:easycukes    文件:GitHelper.java   
/**
 * 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);
    }
}
项目:salesforce-migration-assistant    文件:SMAGitTest.java   
/**
 * 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());
}
项目:proctor    文件:GitProctorCore.java   
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;
            }
        });
    }
项目:gitplex-mit    文件:Project.java   
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);
}
  }
项目:JGitFX    文件:GitHelper.java   
/**
 * 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();
}
项目:JGitFX    文件:GitHelper.java   
/**
 * 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, RevCommit startPoint,
        CreateBranchCommand.SetupUpstreamMode upstreamMode) throws GitAPIException {
    return git.checkout()
            .setCreateBranch(true)
            .setName(branchName)
            .setStartPoint(startPoint)
            .setUpstreamMode(upstreamMode)
            .call();
}
项目:JGitFX    文件:GitHelper.java   
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();
}
项目:JGitFX    文件:GitHelper.java   
public static Ref createNewBranchFromRemote(
        Git git, String branchName, String startingPoint,
        CreateBranchCommand.SetupUpstreamMode upstreamMode) throws GitAPIException {
    return git.branchCreate()
            .setStartPoint(startingPoint)
            .setName(branchName)
            .setUpstreamMode(upstreamMode)
            .call();
}
项目:vertx-configuration-service    文件:GitConfigurationStore.java   
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();
  }
}
项目:arquillian-algeron    文件:GitOperations.java   
/**
 * 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);
    }
}
项目:arquillian-algeron    文件:GitOperations.java   
/**
 * 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);
    }
}
项目:mdw    文件:VersionControlGit.java   
/**
 * 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();
    }
}
项目:vertx-config    文件:GitConfigStore.java   
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();
  }
}
项目:GitDirStat    文件:RemoteBranch.java   
public LocalBranch createLocalBranch() throws GitAPIException {
    GitRepository gitRepository = getGitRepository();
    Repository repository = gitRepository.getRepository();
    Git git = gitRepository.getGit();
    CreateBranchCommand branchCreate = git.branchCreate();
    String name = getName();
    String shortenRefName = repository.shortenRemoteBranchName(name);
    branchCreate.setName(shortenRefName);
    branchCreate.setStartPoint(name);
    branchCreate.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);
    Ref call = branchCreate.call();
    return new LocalBranch(gitRepository, call);

}
项目:GitDirStat    文件:RemoteBranch.java   
public LocalBranch createLocalBranch() throws GitAPIException {
    GitRepository gitRepository = getGitRepository();
    Repository repository = gitRepository.getRepository();
    Git git = gitRepository.getGit();
    CreateBranchCommand branchCreate = git.branchCreate();
    String name = getName();
    String shortenRefName = repository.shortenRemoteBranchName(name);
    branchCreate.setName(shortenRefName);
    branchCreate.setStartPoint(name);
    branchCreate.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);
    Ref call = branchCreate.call();
    return new LocalBranch(gitRepository, call);

}
项目:SGit    文件:CheckoutTask.java   
public void checkoutFromRemote(String remoteBranchName, String branchName)
        throws GitAPIException, JGitInternalException, StopTaskException {
    mRepo.getGit().checkout().setCreateBranch(true).setName(branchName)
            .setStartPoint(remoteBranchName).call();
    mRepo.getGit()
            .branchCreate()
            .setUpstreamMode(
                    CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
            .setStartPoint(remoteBranchName).setName(branchName)
            .setForce(true).call();
}
项目:spring-cloud-release-tools    文件:GitRepo.java   
private void trackBranch(CheckoutCommand checkout, String label) {
    checkout.setCreateBranch(true).setName(label)
            .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
            .setStartPoint("origin/" + label);
}
项目:buckaroo    文件:GitTasks.java   
public static Observable<Event> ensureCloneAndCheckout(final GitCommit commit, final Path directory, final boolean overwrite) {
    Preconditions.checkNotNull(commit);
    Preconditions.checkNotNull(directory);
    return Observable.create(emitter -> {
        try {
            // Is there a folder there already?
            if (Files.exists(directory)) {
                // Check the status.
                final Git git = Git.open(directory.toFile());
                final Status status = git.status().call();
                final String remote = git.getRepository()
                    .getConfig()
                    .getString("remote", "origin", "url");
                final boolean isValidStatus = status.isClean() && remote.equalsIgnoreCase(commit.url);
                // Is it invalid?
                if (!isValidStatus) {
                    // Can we destroy files?
                    if (overwrite) {
                        // Delete what we have.
                        Files.deleteIfExists(directory);
                        emitter.onNext(DeleteFileEvent.of(directory));
                    } else {
                        throw new FileAlreadyExistsException(directory.toString());
                    }
                }
            } else {
                // Clone!
                Git.cloneRepository()
                    .setURI(commit.url)
                    .setDirectory(directory.toFile())
                    .call();
                emitter.onNext(GitCloneEvent.of(commit.url, directory));
            }
            // Checkout
            Git.open(directory.toFile())
                .checkout()
                .setName(commit.commit)
                .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
                .call();
            emitter.onNext(GitCheckoutEvent.of(directory, commit.commit));
            emitter.onComplete();
        } catch (final Throwable e) {
            emitter.onError(e);
        }
    });
}
项目:Elegit    文件:BranchManagerUiUpdateTest.java   
@Test
public void testMergeSelectedBranchWithCurrent() throws Exception {
    // first fetch from remote
    RefSpec fetchSpec = new RefSpec
            ("+refs/heads/*:refs/remotes/origin/*");
    new Git(helper.getRepo()).fetch().setRefSpecs(fetchSpec).call();

    // start tracking the remote branch "random"
    new Git(helper.getRepo()).checkout().
            setCreateBranch(true).
            setForce(true).
            setName("random").
            setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).
            setStartPoint("origin/random").
            call();

    // make changes to local file and commit
    File file = Paths.get(this.repoPath.toString(), "test.txt").toFile();
    assertTrue(file.exists());

    try(PrintWriter fileTextWriter = new PrintWriter( file )){
        fileTextWriter.println("Add a line to the file");
    }

    this.helper.addFilePathTest(file.toPath());
    this.helper.commit("Modified test.txt in a unit test!");

    new Git(helper.getRepo()).checkout().setName("master").call();

    // merge master into random
    MergeCommand merge = new Git(helper.getRepo()).merge();
    merge.include(helper.getRepo().resolve("refs/heads/random"));

    MergeResult mergeResult = merge.call();
    assertEquals(mergeResult.getMergeStatus(), MergeResult.MergeStatus.FAST_FORWARD);

    // TODO: fix this if you ever run it
    //CommitTreeController.update(helper);

    // after update, should expect the heads of two branches
    // are the same commit
    helper.getBranchModel().updateLocalBranches();
    assertEquals(helper.getBranchModel().getBranchListTyped(BranchModel.BranchType.LOCAL).size(), 2);

    String masterHead = helper.getBranchModel().getBranchListTyped(BranchModel.BranchType.LOCAL).get(0).getHeadId().getName();
    String randomHead = helper.getBranchModel().getBranchListTyped(BranchModel.BranchType.LOCAL).get(1).getHeadId().getName();

    assertEquals(masterHead, randomHead);
}
项目:appformer    文件:GitImpl.java   
public CreateBranchCommand _branchCreate() {
    return git.branchCreate();
}
项目:pretested-integration-plugin    文件:MatrixProjectCompatibilityTestIT.java   
/**
 * Git Plugin
 *
 * Test that show that a ready/feature_1 branch get integrated into master
 * using a Matrix job type.
 *
 * Pretested integration:
 *  - 'Integration branch' : master (default)
 *  - 'Repository name' : origin (default)
 *  - 'Strategy' : Squash Commit
 *
 * GitSCM:
 *  - 'Name' : (empty)
 *
 * Workflow
 *  - Create a repository containing a 'ready' branch.
 *  - The build is triggered.
 *
 * Results
 *  - We expect that the plugin triggers, and that the commits on ready branch
 *    is merged into our integration branch master and build result becomes SUCCESS.
 *
 * @throws Exception
 */

@Test
public void oneBuildBasicSmokeTest() throws Exception {
    repository = TestUtilsFactory.createValidRepository("test-repo");
    File workDir = new File(TestUtilsFactory.WORKDIR,"test-repo");
    Git.cloneRepository().setURI("file:///" + repository.getDirectory().getAbsolutePath()).setDirectory(workDir)
            .setBare(false)
            .setCloneAllBranches(true)
            .setNoCheckout(false)
            .call().close();

    Git git = Git.open(workDir);

    System.out.println("Opening git repository in: " + workDir.getAbsolutePath());

    String readmeFromIntegration = FileUtils.readFileToString(new File(workDir,"readme"));

    git.checkout().setName(FEATURE_BRANCH_NAME).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).setCreateBranch(true).call();
    final int COMMIT_COUNT_ON_FEATURE_BEFORE_EXECUTION = TestUtilsFactory.countCommits(git);
    git.checkout().setName("master").setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).call();

    MatrixProjectBuilder builder = new MatrixProjectBuilder()
    .setGitRepos(Collections.singletonList(new UserRemoteConfig("file://" + repository.getDirectory().getAbsolutePath(), null, null, null)))
    .setUseSlaves(true).setRule(jenkinsRule)
    .setStrategy(TestUtilsFactory.STRATEGY_TYPE.ACCUMULATED);
    builder.setJobType(MatrixProject.class);

    MatrixProject project = (MatrixProject)builder.generateJenkinsJob();
    TestUtilsFactory.triggerProject(project);

    jenkinsRule.waitUntilNoActivityUpTo(60000);

    String readmeFileContents = FileUtils.readFileToString(new File(workDir,"readme"));
    assertEquals(readmeFromIntegration, readmeFileContents);
    git.pull().call();

    assertEquals("3 runs for this particular matrix build", 3, project.getLastBuild().getRuns().size());

    final int COMMIT_COUNT_ON_MASTER_AFTER_EXECUTION = TestUtilsFactory.countCommits(git);
    git.close();
    //We assert that 2 commits from branch gets merged + 1 combined merge commit since we do --no-ff
    assertEquals(COMMIT_COUNT_ON_FEATURE_BEFORE_EXECUTION + 3, COMMIT_COUNT_ON_MASTER_AFTER_EXECUTION);
}
项目:pretested-integration-plugin    文件:UniqueBranchGenerator.java   
/**
 * Requires a bare repository. We clone to a random workspace
 *
 * @throws Exception
 * @return The generator currently being worked on
 */
public UniqueBranchGenerator build() throws Exception {

    Git git;

    File workDirTarget = new File(repo.getDirectory().getAbsolutePath() + "/../../" + UUID.randomUUID().toString());
    System.out.println(workDirTarget.getAbsolutePath());

    Git.cloneRepository()
            .setURI("file://" + repo.getDirectory().getAbsolutePath())
            .setBare(false)
            .setNoCheckout(false)
            .setCloneAllBranches(true)
            .setDirectory(workDirTarget).call().close();

    File gitMetaDir = new File(workDirTarget.getAbsolutePath() + System.getProperty("file.separator") + ".git");
    System.out.println("Setting .git metadata to work in directory: " + gitMetaDir.getAbsolutePath());

    git = Git.open(gitMetaDir);

    CreateBranchCommand createBranchCommand = git.branchCreate();
    createBranchCommand.setName(branchName);
    createBranchCommand.call();
    git.checkout().setName(branchName).call();

    File repoRoot = git.getRepository().getWorkTree();
    UUID rand = UUID.randomUUID();
    File randomFile = new File(repoRoot, rand.toString() + ".log");
    randomFile.createNewFile();
    git.add().addFilepattern(".").call();

    int cnt = 0;
    for (String msg : commitMessages) {
        FileUtils.writeStringToFile(randomFile, rand.toString() + "-" + cnt + "\n", true);
        CommitCommand commitCommand = git.commit();
        commitCommand.setMessage(msg);
        commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
        commitCommand.call();
        cnt++;
    }

    git.push().setPushAll().call();
    git.checkout().setName("master");
    git.close();

    FileUtils.deleteDirectory(workDirTarget);
    return this;
}
项目:pretested-integration-plugin    文件:TestUtilsFactory.java   
public static Repository createValidRepository(String repoFolderName) throws IOException, GitAPIException {
    File repo = new File(WORKDIR,repoFolderName + ".git"); // bare repo should have suffix .git, and contain what normally in .git

    if (repo.exists()) {
        System.out.format("EXIST:" + repo.getAbsolutePath());
        try {
            TestUtilsFactory.destroyDirectory(repo);
        } catch (InterruptedException e) {
            throw new IOException(e);
        }
    }

    File workDirForRepo = new File(WORKDIR, repoFolderName);
    Repository repository = new FileRepository(repo);
    repository.create(true);

    Git.cloneRepository().setURI("file:///" + repo.getAbsolutePath()).setDirectory(workDirForRepo)
            .setBare(false)
            .setCloneAllBranches(true)
            .setNoCheckout(false)
            .call().close();

    Git git = Git.open(workDirForRepo);

    String FEATURE_BRANCH_NAME = "ready/feature_1";

    File readme = new File(workDirForRepo + "/readme");
    if (!readme.exists()) {
        FileUtils.writeStringToFile(readme, "sample text\n");
    }

    git.add().addFilepattern(readme.getName()).call();
    git.commit().setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "commit message 1")).call();

    FileUtils.writeStringToFile(readme, "changed sample text\n");

    git.add().addFilepattern(readme.getName()).call();
    git.commit().setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "commit message 2")).call();

    CreateBranchCommand createBranchCommand = git.branchCreate();
    createBranchCommand.setName(FEATURE_BRANCH_NAME);
    createBranchCommand.call();

    git.checkout().setName(FEATURE_BRANCH_NAME).call();

    FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 1\n", true);

    git.add().addFilepattern(readme.getName()).call();
    CommitCommand commitCommand = git.commit();
    commitCommand.setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "feature 1 commit 1"));
    commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
    commitCommand.call();

    FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 2\n", true);

    git.add().addFilepattern(readme.getName()).call();
    commitCommand = git.commit();
    commitCommand.setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "feature 1 commit 2"));
    commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
    commitCommand.call();

    git.push().setPushAll().call();

    git.checkout().setName("master").call();

    FileUtils.deleteDirectory(workDirForRepo);
    return repository;
}
项目:pretested-integration-plugin    文件:TestUtilsFactory.java   
public static Repository createRepositoryWithMergeConflict(String repoFolderName) throws IOException, GitAPIException {
    String FEATURE_BRANCH_NAME = "ready/feature_1";

    File repo = new File(WORKDIR,repoFolderName + ".git"); // bare repo should have suffix .git, and contain what normally in .git
    File workDirForRepo = new File(WORKDIR, repoFolderName);
    Repository repository = new FileRepository(repo);
    repository.create(true);

    Git.cloneRepository().setURI("file:///" + repo.getAbsolutePath()).setDirectory(workDirForRepo)
            .setBare(false)
            .setCloneAllBranches(true)
            .setNoCheckout(false)
            .call().close();

    Git git = Git.open(workDirForRepo);

    File readme = new File(workDirForRepo + "/readme");
    if (!readme.exists()) {
        FileUtils.writeStringToFile(readme, "sample text\n");
    }

    git.add().addFilepattern(readme.getName()).call();
    git.commit().setMessage("commit message 1").call();

    FileUtils.writeStringToFile(readme, "changed sample text\n");

    git.add().addFilepattern(readme.getName()).call();
    git.commit().setMessage("commit message 2").call();

    CreateBranchCommand createBranchCommand = git.branchCreate();
    createBranchCommand.setName(FEATURE_BRANCH_NAME);
    createBranchCommand.call();

    git.checkout().setName(FEATURE_BRANCH_NAME).call();

    FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 1\n");

    git.add().addFilepattern(readme.getName()).call();
    CommitCommand commitCommand = git.commit();
    commitCommand.setMessage("feature 1 commit 1");
    commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
    commitCommand.call();

    FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 2\n");

    git.add().addFilepattern(readme.getName()).call();
    commitCommand = git.commit();
    commitCommand.setMessage("feature 1 commit 2");
    commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
    commitCommand.call();

    git.checkout().setName("master").call();

    FileUtils.writeStringToFile(readme, "Merge conflict branch commit 2\n");

    git.add().addFilepattern(readme.getName()).call();
    commitCommand = git.commit();
    commitCommand.setMessage("merge conflict message 1");
    commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
    commitCommand.call();

    git.push().setPushAll().call();

    FileUtils.deleteDirectory(workDirForRepo);

    return repository;
}
项目:pretested-integration-plugin    文件:EnvVarsIT.java   
private void createRepository() throws IOException, GitAPIException {
    File repo = new File(TestUtilsFactory.WORKDIR,"EnvVar - " + UUID.randomUUID().toString().substring(0, 6) + "/.git");
    if (repo.getAbsoluteFile().exists()) {
        FileUtils.deleteDirectory(repo.getParentFile());
    }

    FileRepositoryBuilder builder = new FileRepositoryBuilder();

    repository = builder.setGitDir(repo.getAbsoluteFile())
            .readEnvironment() // scan environment GIT_* variables
            .findGitDir() // scan up the file system tree
            .build();

    if (!repository.isBare() && repository.getBranch() == null) {
        repository.create();
    }

    Git git = new Git(repository);

    File readme = new File(repository.getDirectory().getParent().concat("/" + "readme"));
    FileUtils.writeStringToFile(readme, "commit 1\n");
    git.add().addFilepattern(readme.getName()).call();
    git.commit().setMessage("commit message 1").call();

    CreateBranchCommand createBranchCommand = git.branchCreate();
    createBranchCommand.setName(INTEGRATION_BRANCH);
    createBranchCommand.call();

    createBranchCommand = git.branchCreate();
    createBranchCommand.setName(READY_BRANCH);
    createBranchCommand.call();

    CheckoutCommand checkout = git.checkout();
    checkout.setName(READY_BRANCH);
    checkout.call();

    FileUtils.writeStringToFile(readme, "commit 2\n");
    git.add().addFilepattern(readme.getName()).call();
    git.commit().setMessage("commit message 2").call();

    checkout = git.checkout();
    checkout.setName(INTEGRATION_BRANCH);
    checkout.call();

    DeleteBranchCommand deleteBranchCommand = git.branchDelete();
    deleteBranchCommand.setBranchNames("master");
    deleteBranchCommand.call();

    REPOSITORY = repository.getDirectory().getAbsolutePath();
}
项目:JGitFX    文件:GitHelper.java   
/**
 * Creates a new branch at the given start point and tracks the remote branch. Then, checks out the new branch.
 * @param git the git repository
 * @param branchName the name of the new branch
 * @param startPoint the starting point of the new branch
 * @return the checked out branch
 * @throws GitAPIException
 */
public static Ref checkoutNewBranchFromRemote(
        Git git, String branchName, String startPoint) throws GitAPIException {
    return checkoutNewBranchFromRemote(git, branchName, startPoint, CreateBranchCommand.SetupUpstreamMode.TRACK);
}
项目:JGitFX    文件:GitHelper.java   
/**
 * Creates a new branch at the given start point and tracks the remote branch. Then, checks out the new branch.
 * @param git the git repository
 * @param branchName the name of the new branch
 * @param startPoint the starting point of the new branch
 * @return the checked out branch
 * @throws GitAPIException
 */
public static Ref checkoutNewBranchFromRemote(
        Git git, String branchName, RevCommit startPoint) throws GitAPIException {
    return checkoutNewBranchFromRemote(git, branchName, startPoint, CreateBranchCommand.SetupUpstreamMode.TRACK);
}
项目:ant-git-tasks    文件:BranchTask.java   
/**
 * Corresponds to the --track/--no-track/--set-upstream options; may be null
 *
 * @see <a href="http://download.eclipse.org/jgit/docs/latest/apidocs/org/eclipse/jgit/api/CreateBranchCommand.SetupUpstreamMode.html">CreateBranchCommand.SetupUpstreamMode string values</a>
 *
 * @antdoc.notrequired
 * @param upstreamMode the upstreamMode to set (Default is --track).
 */
public void setUpstreamMode(String upstreamMode) {
        this.upstreamMode = CreateBranchCommand.SetupUpstreamMode.valueOf(upstreamMode);
}