Search in sources :

Example 76 with GitConnection

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

the class PullTest 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.pull(PullParams.create(null));
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 77 with GitConnection

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

the class FetchTest method testFetchBranch.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testFetchBranch(GitConnectionFactory connectionFactory) throws ServerException, IOException, UnauthorizedException, URISyntaxException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    GitConnection fetchConnection = connectionFactory.getConnection(fetchTestRepo.getAbsolutePath());
    addFile(connection, "README", "readme content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("fetch test"));
    //clone default repo into fetchRepo
    fetchConnection.clone(CloneParams.create(repository.getAbsolutePath()));
    //add new File into defaultRepository
    addFile(connection, "newfile1", "newfile1 content");
    //add file to index and make commit
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("fetch test"));
    String branchName = "branch";
    connection.checkout(CheckoutParams.create(branchName).withCreateNew(true));
    addFile(connection, "otherfile1", "otherfile1 content");
    addFile(connection, "otherfile2", "otherfile2 content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("fetch branch test"));
    //when
    fetchConnection.fetch(FetchParams.create(repository.getAbsolutePath()));
    //then
    //make merge with FETCH_HEAD
    fetchConnection.merge("FETCH_HEAD");
    assertTrue(new File(fetchTestRepo, "otherfile1").exists());
    assertTrue(new File(fetchTestRepo, "otherfile2").exists());
    assertEquals(fetchConnection.log(LogParams.create()).getCommits().get(0).getMessage(), "fetch branch test");
}
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 78 with GitConnection

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

the class FetchTest method testSimpleFetch.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testSimpleFetch(GitConnectionFactory connectionFactory) throws ServerException, IOException, UnauthorizedException, URISyntaxException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    GitConnection fetchConnection = connectionFactory.getConnection(fetchTestRepo.getAbsolutePath());
    addFile(connection, "README", "readme content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("fetch test"));
    //clone default repo into fetchRepo
    fetchConnection.clone(CloneParams.create(connection.getWorkingDir().getAbsolutePath()).withWorkingDir(fetchConnection.getWorkingDir().getAbsolutePath()));
    //add new File into defaultRepository
    addFile(connection, "newfile1", "newfile1 content");
    //add file to index and make commit
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("fetch test"));
    //when
    fetchConnection.fetch(FetchParams.create(repository.getAbsolutePath()));
    //then
    //make merge with FETCH_HEAD
    fetchConnection.merge("FETCH_HEAD");
    assertTrue(new File(fetchTestRepo, "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 79 with GitConnection

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

the class GitTestUtil method connectToGitRepositoryWithContent.

public static GitConnection connectToGitRepositoryWithContent(GitConnectionFactory connectionFactory, File repository) throws GitException, IOException {
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "README.txt", CONTENT);
    connection.add(AddParams.create(singletonList("README.txt")));
    connection.commit(CommitParams.create("Initial commit"));
    return connection;
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection)

Example 80 with GitConnection

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

the class IsInsideWorkTreeTest method shouldReturnTrueInsideWorkingTree.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void shouldReturnTrueInsideWorkingTree(GitConnectionFactory connectionFactory) throws ServerException, IOException, UnauthorizedException, URISyntaxException {
    // given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    // add new dir into working tree
    addFile(connection.getWorkingDir().toPath().resolve("new_directory"), "a", "content of a");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("test"));
    // when
    boolean isInsideWorkingTree = connection.isInsideWorkTree();
    // then
    assertTrue(isInsideWorkingTree);
}
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