예제 #1
0
  @Test(
      dataProvider = "GitConnectionFactory",
      dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
  public void testMergeConflict(GitConnectionFactory connectionFactory) throws Exception {
    // given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    connection.checkout(newDto(CheckoutRequest.class).withName(branchName).withCreateNew(true));
    addFile(connection, "t-merge-conflict", "aaa\n");
    connection.add(newDto(AddRequest.class).withFilepattern(new ArrayList<>(Arrays.asList("."))));
    connection.commit(newDto(CommitRequest.class).withMessage("add file in new branch"));

    connection.checkout(newDto(CheckoutRequest.class).withName("master"));
    addFile(connection, "t-merge-conflict", "bbb\n");
    connection.add(newDto(AddRequest.class).withFilepattern(new ArrayList<>(Arrays.asList("."))));
    connection.commit(newDto(CommitRequest.class).withMessage("add file in new branch"));
    // when
    MergeResult mergeResult = connection.merge(newDto(MergeRequest.class).withCommit(branchName));
    // then
    List<String> conflicts = mergeResult.getConflicts();
    assertEquals(conflicts.size(), 1);
    assertEquals(conflicts.get(0), "t-merge-conflict");

    assertEquals(mergeResult.getMergeStatus(), MergeResult.MergeStatus.CONFLICTING);

    String expContent =
        "<<<<<<< HEAD\n" //
            + "bbb\n" //
            + "=======\n" //
            + "aaa\n" //
            + ">>>>>>> MergeTestBranch\n";
    String actual =
        Files.toString(new File(connection.getWorkingDir(), "t-merge-conflict"), Charsets.UTF_8);
    assertEquals(actual, expContent);
  }
예제 #2
0
 @Test(
     dataProvider = "GitConnectionFactory",
     dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
 public void testMergeNoChanges(GitConnectionFactory connectionFactory) throws Exception {
   // given
   GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
   connection.branchCreate(newDto(BranchCreateRequest.class).withName(branchName));
   // when
   MergeResult mergeResult = connection.merge(newDto(MergeRequest.class).withCommit(branchName));
   // then
   assertEquals(mergeResult.getMergeStatus(), MergeResult.MergeStatus.ALREADY_UP_TO_DATE);
 }
예제 #3
0
  @Test(
      dataProvider = "GitConnectionFactory",
      dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
  public void testMerge(GitConnectionFactory connectionFactory) throws Exception {
    // given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    connection.checkout(newDto(CheckoutRequest.class).withName(branchName).withCreateNew(true));
    File file = addFile(connection, "t-merge", "aaa\n");

    connection.add(newDto(AddRequest.class).withFilepattern(new ArrayList<>(Arrays.asList("."))));
    connection.commit(newDto(CommitRequest.class).withMessage("add file in new branch"));
    connection.checkout(newDto(CheckoutRequest.class).withName("master"));
    // when
    MergeResult mergeResult = connection.merge(newDto(MergeRequest.class).withCommit(branchName));
    // then
    assertEquals(mergeResult.getMergeStatus(), MergeResult.MergeStatus.FAST_FORWARD);
    assertTrue(file.exists());
    assertEquals(Files.toString(file, Charsets.UTF_8), "aaa\n");
    assertEquals(
        connection.log(newDto(LogRequest.class)).getCommits().get(0).getMessage(),
        "add file in new branch");
  }