Search in sources :

Example 31 with GitConnection

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

the class PushTest method testPushWhenLocalRepositoryIsNotSynchronisedWithRemote.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testPushWhenLocalRepositoryIsNotSynchronisedWithRemote(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
    //given
    GitConnection remoteConnection = connectToGitRepositoryWithContent(connectionFactory, repository);
    GitConnection localConnection = connectionFactory.getConnection(remoteRepo.getAbsolutePath());
    localConnection.clone(CloneParams.create(remoteConnection.getWorkingDir().getAbsolutePath()));
    addFile(remoteConnection, "newfile", "content");
    remoteConnection.add(AddParams.create(singletonList(".")));
    remoteConnection.commit(CommitParams.create("Fake commit"));
    //when
    String errorMessage = "";
    try {
        localConnection.push(PushParams.create("origin").withTimeout(-1));
    } catch (GitException exception) {
        errorMessage = exception.getMessage();
    }
    //then
    assertTrue(errorMessage.contains("master -> master"));
    assertTrue(errorMessage.contains(remoteConnection.getWorkingDir().getAbsolutePath()));
}
Also used : GitException(org.eclipse.che.api.git.exception.GitException) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 32 with GitConnection

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

the class DiffTest method testDiffNameOnlyCachedNoCommit.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testDiffNameOnlyCachedNoCommit(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    makeCommitInMaster(connection);
    //when
    connection.add(AddParams.create(singletonList("aaa")));
    List<String> diff = readDiff(DiffParams.create().withFileFilter(null).withType(DiffType.NAME_ONLY).withNoRenames(false).withRenameLimit(0).withCommitA(null).withCached(true), connection);
    //then
    assertEquals(diff.size(), 1);
    assertTrue(diff.contains("aaa"));
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 33 with GitConnection

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

the class FetchTest method testWhenThereAreNoAnyRemotes.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class, expectedExceptions = GitException.class, expectedExceptionsMessageRegExp = "No remote repository specified.  " + "Please, specify either a URL or a remote name from which new revisions should be fetched in request.")
public void testWhenThereAreNoAnyRemotes(GitConnectionFactory connectionFactory) throws Exception {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    //when
    connection.fetch(FetchParams.create(null));
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 34 with GitConnection

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

the class GetCommitersTest method testGetCommitters.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testGetCommitters(GitConnectionFactory connectionFactory) throws GitException, IOException {
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    //given
    addFile(connection, "newfile", "newfile content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("test commit"));
    //when
    List<GitUser> committers = connection.getCommiters();
    //then
    assertEquals(committers.size(), 1);
    assertEquals(committers.get(0), getTestGitUser());
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) GitUser(org.eclipse.che.api.git.shared.GitUser) Test(org.testng.annotations.Test)

Example 35 with GitConnection

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

the class GitTestUtil method connectToInitializedGitRepository.

public static GitConnection connectToInitializedGitRepository(GitConnectionFactory connectionFactory, File repository) throws GitException, IOException {
    GitConnection connection = getTestUserConnection(connectionFactory, repository);
    connection.init(false);
    return connection;
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection)

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