Search in sources :

Example 1 with GitConnection

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

the class LogTest method testLogSkip.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testLogSkip(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> firstBucketOfCommits = connection.log(LogParams.create().withSkip(1)).getCommits();
    List<Revision> secondBucketOfCommits = connection.log(LogParams.create().withSkip(3)).getCommits();
    //then
    assertEquals(4, allCommits.size());
    assertEquals(3, firstBucketOfCommits.size());
    assertEquals(firstBucketOfCommits.get(0).getMessage(), "add 3.txt file");
    assertEquals(firstBucketOfCommits.get(0).getBranches().get(0).getName(), "refs/heads/master");
    assertEquals(firstBucketOfCommits.get(0).getDiffCommitFile().get(0).getOldPath(), "/dev/null");
    assertEquals(firstBucketOfCommits.get(0).getDiffCommitFile().get(0).getNewPath(), "3.txt");
    assertEquals(firstBucketOfCommits.get(0).getDiffCommitFile().get(0).getChangeType(), "ADD");
    assertEquals(firstBucketOfCommits.get(1).getMessage(), "add 2.txt file");
    assertEquals(firstBucketOfCommits.get(1).getBranches().get(0).getName(), "refs/heads/master");
    assertEquals(firstBucketOfCommits.get(1).getDiffCommitFile().get(0).getOldPath(), "/dev/null");
    assertEquals(firstBucketOfCommits.get(1).getDiffCommitFile().get(0).getNewPath(), "2.txt");
    assertEquals(firstBucketOfCommits.get(1).getDiffCommitFile().get(0).getChangeType(), "ADD");
    assertEquals(firstBucketOfCommits.get(2).getMessage(), "add 1.txt file");
    assertEquals(firstBucketOfCommits.get(2).getBranches().get(0).getName(), "refs/heads/master");
    assertEquals(firstBucketOfCommits.get(2).getDiffCommitFile().get(0).getOldPath(), "/dev/null");
    assertEquals(firstBucketOfCommits.get(2).getDiffCommitFile().get(0).getNewPath(), "1.txt");
    assertEquals(firstBucketOfCommits.get(2).getDiffCommitFile().get(0).getChangeType(), "ADD");
    assertEquals(1, secondBucketOfCommits.size());
    assertEquals(secondBucketOfCommits.get(0).getMessage(), "add 1.txt file");
    assertEquals(secondBucketOfCommits.get(0).getBranches().get(0).getName(), "refs/heads/master");
    assertEquals(secondBucketOfCommits.get(0).getDiffCommitFile().get(0).getOldPath(), "/dev/null");
    assertEquals(secondBucketOfCommits.get(0).getDiffCommitFile().get(0).getNewPath(), "1.txt");
    assertEquals(secondBucketOfCommits.get(0).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 2 with GitConnection

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

the class LogTest method testSimpleLog.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testSimpleLog(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "README.txt", "someChanges");
    connection.add(AddParams.create(ImmutableList.of("README.txt")));
    connection.commit(CommitParams.create("Initial add"));
    addFile(connection, "README.txt", "newChanges");
    connection.add(AddParams.create(ImmutableList.of("README.txt")));
    connection.commit(CommitParams.create("Second commit"));
    addFile(connection, "README.txt", "otherChanges");
    connection.add(AddParams.create(ImmutableList.of("README.txt")));
    connection.commit(CommitParams.create("Third commit"));
    //when
    List<Revision> commits = connection.log(LogParams.create()).getCommits();
    //then
    assertEquals("Third commit", commits.get(0).getMessage());
    assertEquals("Second commit", commits.get(1).getMessage());
    assertEquals("Initial add", commits.get(2).getMessage());
}
Also used : Revision(org.eclipse.che.api.git.shared.Revision) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 3 with GitConnection

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

the class LsRemoteTest method testShouldThrowUnauthorizedExceptionIfUserTryGetInfoAboutPrivateRepoAndUserIsUnauthorized.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class, expectedExceptions = UnauthorizedException.class, expectedExceptionsMessageRegExp = "fatal: Authentication failed for 'https://bitbucket.org/exoinvitemain/privater.git/'\n")
public void testShouldThrowUnauthorizedExceptionIfUserTryGetInfoAboutPrivateRepoAndUserIsUnauthorized(GitConnectionFactory connectionFactory) throws GitException, UnauthorizedException, IOException {
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    connection.lsRemote("https://bitbucket.org/exoinvitemain/privater.git");
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 4 with GitConnection

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

the class LsRemoteTest method testShouldBeAbleToGetResultFromPublicRepo.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testShouldBeAbleToGetResultFromPublicRepo(GitConnectionFactory connectionFactory) throws GitException, IOException, UnauthorizedException {
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    //when
    Set<RemoteReference> remoteReferenceSet = new HashSet<>(connection.lsRemote("https://github.com/codenvy/everrest.git"));
    //then
    assertTrue(remoteReferenceSet.contains(newDto(RemoteReference.class).withCommitId("259e24c83c8a122af858c8306c3286586404ef3f").withReferenceName("refs/tags/1.1.9")));
}
Also used : RemoteReference(org.eclipse.che.api.git.shared.RemoteReference) GitConnection(org.eclipse.che.api.git.GitConnection) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with GitConnection

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

the class MergeTest method testMergeNoChanges.

@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(branchName, null);
    //when
    MergeResult mergeResult = connection.merge(branchName);
    //then
    assertEquals(mergeResult.getMergeStatus(), MergeResult.MergeStatus.ALREADY_UP_TO_DATE);
}
Also used : MergeResult(org.eclipse.che.api.git.shared.MergeResult) 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