Search in sources :

Example 71 with GitConnection

use of org.eclipse.che.api.git.GitConnection in project che by eclipse.

the class AddTest method testAddDeletedFile.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testAddDeletedFile(GitConnectionFactory connectionFactory) throws GitException, IOException {
    // given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "README.txt", CONTENT);
    addFile(connection, "CHANGELOG.txt", "WE'VE FIXED ALL BUGS");
    connection.add(AddParams.create(ImmutableList.of("README.txt", "CHANGELOG.txt")));
    connection.commit(CommitParams.create("Initial add"));
    // when
    // remove file from disk
    deleteFile(connection, "CHANGELOG.txt");
    // add all files to index
    connection.add(AddParams.create(AddRequest.DEFAULT_PATTERN));
    // then
    // the deleted file is added to index, so it becomes removed for git
    List<String> stagedDeletedFiles = connection.status(StatusFormat.SHORT).getRemoved();
    assertEquals(stagedDeletedFiles.size(), 1);
    assertEquals(stagedDeletedFiles.get(0), "CHANGELOG.txt");
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 72 with GitConnection

use of org.eclipse.che.api.git.GitConnection in project che by eclipse.

the class LogTest method testLogSince.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testLogSince(GitConnectionFactory connectionFactory) throws GitException, IOException, InterruptedException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "1.txt", "someChanges");
    connection.add(AddParams.create());
    String firstCommitId = connection.commit(CommitParams.create("add 1.txt file")).getId();
    addFile(connection, "2.txt", "secondChanges");
    connection.add(AddParams.create());
    String secondCommitId = connection.commit(CommitParams.create("add 2.txt file")).getId();
    addFile(connection, "3.txt", "thirdChanges");
    connection.add(AddParams.create());
    String thirdCommitId = connection.commit(CommitParams.create("add 3.txt file")).getId();
    addFile(connection, "4.txt", "fourthChanges");
    connection.add(AddParams.create());
    String fourthCommitId = connection.commit(CommitParams.create("add 4.txt file")).getId();
    //when
    List<Revision> allCommits = connection.log(LogParams.create()).getCommits();
    List<Revision> secondAndThirdAndFourthCommits = connection.log(LogParams.create().withRevisionRangeSince(firstCommitId).withRevisionRangeUntil(fourthCommitId)).getCommits();
    List<Revision> thirdAndFourthCommits = connection.log(LogParams.create().withRevisionRangeSince(secondCommitId).withRevisionRangeUntil(fourthCommitId)).getCommits();
    //then
    assertEquals(4, allCommits.size());
    assertEquals(3, secondAndThirdAndFourthCommits.size());
    assertEquals(2, thirdAndFourthCommits.size());
    assertEquals(secondAndThirdAndFourthCommits.get(0).getMessage(), "add 4.txt file");
    assertEquals(secondAndThirdAndFourthCommits.get(1).getMessage(), "add 3.txt file");
    assertEquals(secondAndThirdAndFourthCommits.get(2).getMessage(), "add 2.txt file");
    assertEquals(thirdAndFourthCommits.get(0).getMessage(), "add 4.txt file");
    assertEquals(thirdAndFourthCommits.get(1).getMessage(), "add 3.txt file");
}
Also used : Revision(org.eclipse.che.api.git.shared.Revision) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 73 with GitConnection

use of org.eclipse.che.api.git.GitConnection in project che by eclipse.

the class LogTest method testLogWithSkipAndMaxCount.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testLogWithSkipAndMaxCount(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "1.txt", "someChanges");
    connection.add(AddParams.create());
    connection.commit(CommitParams.create("add 1.txt file"));
    addFile(connection, "2.txt", "newChanges");
    connection.add(AddParams.create());
    connection.commit(CommitParams.create("add 2.txt file"));
    addFile(connection, "3.txt", "otherChanges");
    connection.add(AddParams.create());
    connection.commit(CommitParams.create("add 3.txt file"));
    addFile(connection, "4.txt", "someChanges");
    connection.add(AddParams.create());
    connection.commit(CommitParams.create("add 4.txt file"));
    //when
    List<Revision> allCommits = connection.log(LogParams.create()).getCommits();
    List<Revision> firstBacketOfCommits = connection.log(LogParams.create().withSkip(1).withMaxCount(2)).getCommits();
    List<Revision> secondBacketOfCommits = connection.log(LogParams.create().withSkip(2).withMaxCount(2)).getCommits();
    //then
    assertEquals(4, allCommits.size());
    assertEquals(2, firstBacketOfCommits.size());
    assertEquals(firstBacketOfCommits.get(0).getMessage(), "add 3.txt file");
    assertEquals(firstBacketOfCommits.get(0).getBranches().get(0).getName(), "refs/heads/master");
    assertEquals(firstBacketOfCommits.get(0).getDiffCommitFile().get(0).getOldPath(), "/dev/null");
    assertEquals(firstBacketOfCommits.get(0).getDiffCommitFile().get(0).getNewPath(), "3.txt");
    assertEquals(firstBacketOfCommits.get(0).getDiffCommitFile().get(0).getChangeType(), "ADD");
    assertEquals(firstBacketOfCommits.get(1).getMessage(), "add 2.txt file");
    assertEquals(firstBacketOfCommits.get(1).getBranches().get(0).getName(), "refs/heads/master");
    assertEquals(firstBacketOfCommits.get(1).getDiffCommitFile().get(0).getOldPath(), "/dev/null");
    assertEquals(firstBacketOfCommits.get(1).getDiffCommitFile().get(0).getNewPath(), "2.txt");
    assertEquals(firstBacketOfCommits.get(1).getDiffCommitFile().get(0).getChangeType(), "ADD");
    assertEquals(2, secondBacketOfCommits.size());
    assertEquals(secondBacketOfCommits.get(0).getMessage(), "add 2.txt file");
    assertEquals(secondBacketOfCommits.get(0).getBranches().get(0).getName(), "refs/heads/master");
    assertEquals(secondBacketOfCommits.get(0).getDiffCommitFile().get(0).getOldPath(), "/dev/null");
    assertEquals(secondBacketOfCommits.get(0).getDiffCommitFile().get(0).getNewPath(), "2.txt");
    assertEquals(secondBacketOfCommits.get(0).getDiffCommitFile().get(0).getChangeType(), "ADD");
    assertEquals(secondBacketOfCommits.get(1).getMessage(), "add 1.txt file");
    assertEquals(secondBacketOfCommits.get(1).getBranches().get(0).getName(), "refs/heads/master");
    assertEquals(secondBacketOfCommits.get(1).getDiffCommitFile().get(0).getOldPath(), "/dev/null");
    assertEquals(secondBacketOfCommits.get(1).getDiffCommitFile().get(0).getNewPath(), "1.txt");
    assertEquals(secondBacketOfCommits.get(1).getDiffCommitFile().get(0).getChangeType(), "ADD");
}
Also used : Revision(org.eclipse.che.api.git.shared.Revision) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 74 with GitConnection

use of org.eclipse.che.api.git.GitConnection in project che by eclipse.

the class MergeTest method testMergeConflict.

@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(CheckoutParams.create(branchName).withCreateNew(true));
    addFile(connection, "t-merge-conflict", "aaa\n");
    connection.add(AddParams.create(new ArrayList<>(singletonList("."))));
    connection.commit(CommitParams.create("add file in new branch"));
    connection.checkout(CheckoutParams.create("master"));
    addFile(connection, "t-merge-conflict", "bbb\n");
    connection.add(AddParams.create(new ArrayList<>(singletonList("."))));
    connection.commit(CommitParams.create("add file in new branch"));
    //when
    MergeResult mergeResult = connection.merge(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);
}
Also used : ArrayList(java.util.ArrayList) MergeResult(org.eclipse.che.api.git.shared.MergeResult) GitConnection(org.eclipse.che.api.git.GitConnection) File(java.io.File) GitTestUtil.addFile(org.eclipse.che.git.impl.GitTestUtil.addFile) Test(org.testng.annotations.Test)

Example 75 with GitConnection

use of org.eclipse.che.api.git.GitConnection in project che by eclipse.

the class PullTest method testPullWithRefSpec.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testPullWithRefSpec(GitConnectionFactory connectionFactory) throws ServerException, URISyntaxException, IOException, UnauthorizedException {
    //given
    //create new repository clone of default
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    GitConnection connection2 = connectionFactory.getConnection(remoteRepo.getAbsolutePath());
    connection2.clone(CloneParams.create(connection.getWorkingDir().getAbsolutePath()));
    //add new branch
    connection.checkout(CheckoutParams.create("b1").withCreateNew(true));
    addFile(connection, "newfile1", "new file1 content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("Test commit"));
    int branchesBefore = connection2.branchList(null).size();
    //when
    connection2.pull(PullParams.create("origin").withRefSpec("refs/heads/b1:refs/heads/b1").withTimeout(-1));
    int branchesAfter = connection2.branchList(null).size();
    assertEquals(branchesAfter, branchesBefore + 1);
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Aggregations

GitConnection (org.eclipse.che.api.git.GitConnection)102 Test (org.testng.annotations.Test)100 File (java.io.File)19 GitTestUtil.addFile (org.eclipse.che.git.impl.GitTestUtil.addFile)16 Revision (org.eclipse.che.api.git.shared.Revision)9 ArrayList (java.util.ArrayList)6 CommitParams (org.eclipse.che.api.git.params.CommitParams)5 FileOutputStream (java.io.FileOutputStream)3 MergeResult (org.eclipse.che.api.git.shared.MergeResult)3 DiffPage (org.eclipse.che.api.git.DiffPage)2 GitException (org.eclipse.che.api.git.exception.GitException)2 DiffParams (org.eclipse.che.api.git.params.DiffParams)2 ShowFileContentResponse (org.eclipse.che.api.git.shared.ShowFileContentResponse)2 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)1 LineConsumerFactory (org.eclipse.che.api.core.util.LineConsumerFactory)1 PullParams (org.eclipse.che.api.git.params.PullParams)1 RemoteAddParams (org.eclipse.che.api.git.params.RemoteAddParams)1 RemoteUpdateParams (org.eclipse.che.api.git.params.RemoteUpdateParams)1