@Test public void processSimpleMainline() throws Exception { try (Git git = new Git(db)) { commitWithFile(git, "first"); git.tag().setName(TAG_PREFIX + "-" + V_1).call(); git.branchCreate().setName("branch").setStartPoint("HEAD").call(); git.checkout().setName("branch").call(); commitWithFile(git, "branch_1"); final RevCommit branch = commitWithFile(git, "branch_2"); git.checkout().setName(MASTER).call(); git.merge().include(branch).setFastForward(FastForwardMode.NO_FF).setMessage("merge1").call(); git.tag().setName(TAG_PREFIX + "-" + V_2).call(); } final List<TagWrapper> tags = processor.process(db); assertThat(tags, hasSize(3)); assertTag(tags.get(0), NEXT_VERSION, emptyMap()); assertTag(tags.get(1), V_2, of("merge1", asList("branch_2", "branch_1"))); assertTag(tags.get(2), V_1, of("first", emptyList())); }
@Test public void processMainlineWithLongLivingBranches() throws Exception { try (Git git = new Git(db)) { commitWithFile(git, "first"); git.tag().setName(TAG_PREFIX + "-" + V_1).call(); git.branchCreate().setName("branch").setStartPoint("HEAD").call(); git.checkout().setName("branch").call(); commitWithFile(git, "branch_1"); RevCommit branch = commitWithFile(git, "branch_2"); git.checkout().setName(MASTER).call(); git.merge().include(branch).setFastForward(FastForwardMode.NO_FF).setMessage("merge1").call(); git.tag().setName(TAG_PREFIX + "-" + V_2).call(); git.checkout().setName("branch").call(); branch = commitWithFile(git, "branch_3"); git.checkout().setName(MASTER).call(); git.merge().include(branch).setFastForward(FastForwardMode.NO_FF).setMessage("merge2").call(); git.tag().setName(TAG_PREFIX + "-" + V_3).call(); } final List<TagWrapper> tags = processor.process(db); assertThat(tags, hasSize(4)); assertTag(tags.get(0), NEXT_VERSION, emptyMap()); assertTag(tags.get(1), V_3, of("merge2", singletonList("branch_3"))); assertTag(tags.get(2), V_2, of("merge1", asList("branch_2", "branch_1"))); assertTag(tags.get(3), V_1, of("first", emptyList())); }
private List<Commit> mergePullRequestBranchWithTarget(Git git) throws Exception { notifier.message("Merging source " + request.getNumber() + " into target " + request.getTarget().getBranch()); MergeResult result = git.merge() .setFastForward(FastForwardMode.FF_ONLY) .include(git.getRepository().getRef(String.valueOf(request.getNumber()))) .call(); if(!result.getMergeStatus().isSuccessful()) { throw new RuntimeException("Merge not successfull, status " + result.getMergeStatus()); } else { notifier.message("Merged " + request + " : " + result.getMergeStatus()); } return GitUtil.toCommitList(result.getMergedCommits()); }
@Test public void remoteToLocal_merge() throws Exception { pushMirrorSettings(null, null); // Mirror an empty git repository, which will; // - Create /mirror_state.json // - Remove the sample files created by createProject(). mirroringService.mirror().join(); // Create a text file, modify it in two branches ('master' and 'fork') and merge 'fork' into 'master'. addToGitIndex("alphabets.txt", // 'c' and 'x' are missing. "a\nb\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\ny\nz\n"); git.commit().setMessage("Add alphabets.txt").call(); //// Create a new branch 'fork' and add the missing 'x'. git.checkout().setCreateBranch(true).setName("fork").call(); addToGitIndex("alphabets.txt", // Add the missing 'x'. "a\nb\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n"); final RevCommit commit1 = git.commit().setMessage("Add missing 'x'").call(); //// Check out 'master' and add the missing 'c'. git.checkout().setName("master").call(); addToGitIndex("alphabets.txt", // Add the missing 'c'. "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\ny\nz\n"); final RevCommit commit2 = git.commit().setMessage("Add missing 'c'").call(); //// Merge 'fork' into 'master' to create a merge commit. final MergeResult mergeResult = git.merge() .include(commit1.getId()) .setFastForward(FastForwardMode.NO_FF) .setMessage("Merge 'fork'").call(); //// Make sure the merge commit has been added. assertThat(mergeResult.getMergeStatus()).isEqualTo(MergeStatus.MERGED); final RevCommit lastCommit = git.log().all().call().iterator().next(); assertThat(lastCommit.getParentCount()).isEqualTo(2); assertThat(lastCommit.getParents()).containsExactlyInAnyOrder(commit1, commit2); // Run the mirror and ensure alphabets.txt contains all alphabets. mirroringService.mirror().join(); final Entry<JsonNode> expectedMirrorState = expectedMirrorState("/"); final Entry<String> expectedAlphabets = Entry.ofText( "/alphabets.txt", "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n"); assertThat(client.getFiles(projName, REPO_MAIN, Revision.HEAD, "/**").join().values()) .containsExactlyInAnyOrder(expectedMirrorState, expectedAlphabets); }
@Override @Before public void setUp() throws Exception { super.setUp(); /*- The following graph will be created. o tag 2.5, 2.5_annotated, 2.5_annotated_twice |\ | o tag 2.0.1 | o tag 2.0 o | tag 1.3 |/ o c3 | o tag 1.0.1 |/ o tag 1.0 o c2 o c1 */ // TODO(dborowitz): Use try/finally when this doesn't double-close the repo. @SuppressWarnings("resource") Git git = new Git(db); revWalk = new RevWalk(db); // Version 1.0 commit_initial = git.commit().setMessage("c1").call(); git.commit().setMessage("c2").call(); RevCommit commit_v1_0 = git.commit().setMessage("version 1.0").call(); git.tag().setName(TAG_1_0).setObjectId(commit_v1_0).call(); RevCommit c3 = git.commit().setMessage("c3").call(); // Version 1.01 createAndCheckoutBranch(commit_v1_0, BRANCH_1_0); RevCommit commit_v1_0_1 = git.commit().setMessage("verREFS_HEADS_RELsion 1.0.1").call(); git.tag().setName(TAG_1_0_1).setObjectId(commit_v1_0_1).call(); // Version 1.3 createAndCheckoutBranch(c3, BRANCH_1_3); commit_v1_3 = git.commit().setMessage("version 1.3").call(); git.tag().setName(TAG_1_3).setObjectId(commit_v1_3).call(); // Version 2.0 createAndCheckoutBranch(c3, BRANCH_2_0); RevCommit commit_v2_0 = git.commit().setMessage("version 2.0").call(); git.tag().setName(TAG_2_0).setObjectId(commit_v2_0).call(); RevCommit commit_v2_0_1 = git.commit().setMessage("version 2.0.1").call(); git.tag().setName(TAG_2_0_1).setObjectId(commit_v2_0_1).call(); // Version 2.5 createAndCheckoutBranch(commit_v1_3, BRANCH_2_5); git.merge() .include(commit_v2_0_1) .setCommit(false) .setFastForward(FastForwardMode.NO_FF) .call(); commit_v2_5 = git.commit().setMessage("version 2.5").call(); git.tag().setName(TAG_2_5).setObjectId(commit_v2_5).setAnnotated(false).call(); Ref ref_tag_2_5_annotated = git.tag().setName(TAG_2_5_ANNOTATED).setObjectId(commit_v2_5).setAnnotated(true).call(); RevTag tag_2_5_annotated = revWalk.parseTag(ref_tag_2_5_annotated.getObjectId()); git.tag() .setName(TAG_2_5_ANNOTATED_TWICE) .setObjectId(tag_2_5_annotated) .setAnnotated(true) .call(); }