Example #1
0
  @Test
  public void finishHotfixWithNewCommitAndReleaseBranch() throws Exception {
    Git git = RepoUtil.createRepositoryWithMasterAndTag(newDir());
    JGitFlowInitCommand initCommand = new JGitFlowInitCommand();
    JGitFlow flow = initCommand.setDirectory(git.getRepository().getWorkTree()).call();

    flow.releaseStart("1.1").call();

    String releaseName = "release/1.1";

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

    flow.hotfixStart("1.1.1").call();

    // create a new commit
    File junkFile = new File(git.getRepository().getWorkTree(), "junk.txt");
    FileUtils.writeStringToFile(junkFile, "I am junk");
    git.add().addFilepattern(junkFile.getName()).call();
    RevCommit commit = git.commit().setMessage("committing junk file").call();

    // make sure develop doesn't report our commit yet
    assertFalse(GitHelper.isMergedInto(git, commit, flow.getDevelopBranchName()));

    // make sure release doesn't report our commit yet
    assertFalse(GitHelper.isMergedInto(git, commit, releaseName));

    // try to finish
    flow.hotfixFinish("1.1.1").setKeepBranch(false).call();

    // we should be on develop branch
    assertEquals(flow.getDevelopBranchName(), git.getRepository().getBranch());

    // hotfix branch should be gone
    Ref ref2check = git.getRepository().getRef(flow.getHotfixBranchPrefix() + "1.1.1");
    assertNull(ref2check);

    // the develop branch should have our commit
    assertTrue(GitHelper.isMergedInto(git, commit, flow.getDevelopBranchName()));

    // since fast-forward is suppressed the latest commit on develop should be a merge commit with 2
    // parents
    assertEquals(2, GitHelper.getLatestCommit(git, flow.getDevelopBranchName()).getParentCount());

    // the master branch should have our commit
    assertTrue(GitHelper.isMergedInto(git, commit, getTaggedCommit(git, "1.1.1")));

    // since fast-forward is suppressed the latest commit on master should be a merge commit with 2
    // parents
    assertEquals(2, GitHelper.getLatestCommit(git, getTaggedCommit(git, "1.1.1")).getParentCount());

    // the release branch should have our commit
    assertTrue(GitHelper.isMergedInto(git, commit, releaseName));

    // since fast-forward is suppressed the latest commit on the release branch should be a merge
    // commit with 2 parents
    assertEquals(2, GitHelper.getLatestCommit(git, releaseName).getParentCount());
  }
Example #2
0
  @Test
  public void finishHotfixWithMultipleCommits() throws Exception {
    Git git = RepoUtil.createRepositoryWithMasterAndTag(newDir());
    JGitFlowInitCommand initCommand = new JGitFlowInitCommand();
    JGitFlow flow = initCommand.setDirectory(git.getRepository().getWorkTree()).call();

    flow.hotfixStart("1.1").call();

    // create a new commit
    File junkFile = new File(git.getRepository().getWorkTree(), "junk.txt");
    FileUtils.writeStringToFile(junkFile, "I am junk");
    git.add().addFilepattern(junkFile.getName()).call();
    RevCommit commit = git.commit().setMessage("committing junk file").call();

    // create second commit
    File junkFile2 = new File(git.getRepository().getWorkTree(), "junk2.txt");
    FileUtils.writeStringToFile(junkFile2, "I am junk, and so are you");
    git.add().addFilepattern(junkFile2.getName()).call();
    RevCommit commit2 = git.commit().setMessage("updating junk file").call();

    // make sure develop doesn't have our commits yet
    assertFalse(GitHelper.isMergedInto(git, commit, flow.getDevelopBranchName()));
    assertFalse(GitHelper.isMergedInto(git, commit2, flow.getDevelopBranchName()));

    // try to finish
    flow.hotfixFinish("1.1").call();

    // we should be on develop branch
    assertEquals(flow.getDevelopBranchName(), git.getRepository().getBranch());

    // release branch should be gone
    Ref ref2check = git.getRepository().getRef(flow.getHotfixBranchPrefix() + "1.1");
    assertNull(ref2check);

    // the develop branch should have both of our commits now
    assertTrue(GitHelper.isMergedInto(git, commit, flow.getDevelopBranchName()));
    assertTrue(GitHelper.isMergedInto(git, commit2, flow.getDevelopBranchName()));

    // the master branch should have both of our commits now
    assertTrue(GitHelper.isMergedInto(git, commit, getTaggedCommit(git, "1.1")));
    assertTrue(GitHelper.isMergedInto(git, commit2, getTaggedCommit(git, "1.1")));
  }
Example #3
0
 private String getTaggedCommit(Git git, String tagName) throws JGitFlowIOException, IOException {
   return GitHelper.getTaggedCommit(git, git.getRepository().getRef(tagName));
 }