Search in sources :

Example 6 with GitConnection

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

the class MergeTest method testMerge.

@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(CheckoutParams.create(branchName).withCreateNew(true));
    File file = addFile(connection, "t-merge", "aaa\n");
    connection.add(AddParams.create(new ArrayList<>(singletonList("."))));
    connection.commit(CommitParams.create("add file in new branch"));
    connection.checkout(CheckoutParams.create("master"));
    //when
    MergeResult mergeResult = connection.merge(branchName);
    //then
    assertEquals(mergeResult.getMergeStatus(), MergeResult.MergeStatus.FAST_FORWARD);
    assertTrue(file.exists());
    assertEquals(Files.toString(file, Charsets.UTF_8), "aaa\n");
    assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), "add file in new branch");
}
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 7 with GitConnection

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

the class PullTest method testWhenThereAreNoAnyRemotesBehindTheProxy.

@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 testWhenThereAreNoAnyRemotesBehindTheProxy(GitConnectionFactory connectionFactory) throws Exception {
    //given
    System.setProperty("http.proxyUser", "user1");
    System.setProperty("http.proxyPassword", "paswd1");
    System.setProperty("https.proxyUser", "user2");
    System.setProperty("https.proxyPassword", "paswd2");
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    //when
    connection.pull(PullParams.create(null));
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 8 with GitConnection

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

the class PullTest method testPullRemote.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testPullRemote(GitConnectionFactory connectionFactory) throws GitException, IOException, URISyntaxException, UnauthorizedException {
    //given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    String branchName = "remoteBranch";
    connection.checkout(CheckoutParams.create(branchName).withCreateNew(true));
    addFile(connection, "remoteFile", "");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("remote test"));
    GitConnection connection2 = connectToGitRepositoryWithContent(connectionFactory, remoteRepo);
    //when
    PullParams params = PullParams.create(connection.getWorkingDir().getAbsolutePath()).withRefSpec("refs/heads/remoteBranch:refs/heads/remoteBranch");
    connection2.pull(params);
    //then
    assertTrue(new File(remoteRepo.getAbsolutePath(), "remoteFile").exists());
}
Also used : PullParams(org.eclipse.che.api.git.params.PullParams) 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 9 with GitConnection

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

the class PullTest method testSimplePull.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testSimplePull(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
    //given
    //create new repository clone of default
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    GitConnection connection2 = connectionFactory.getConnection(remoteRepo.getAbsolutePath());
    connection2.clone(CloneParams.create(connection.getWorkingDir().getAbsolutePath()));
    addFile(connection, "newfile1", "new file1 content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("Test commit"));
    //when
    connection2.pull(PullParams.create("origin").withTimeout(-1));
    //then
    assertTrue(new File(remoteRepo.getAbsolutePath(), "newfile1").exists());
}
Also used : 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 10 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)

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