Search in sources :

Example 16 with GitConnection

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

the class IsInsideWorkTreeTest method shouldReturnFalseOutsideRepositoryDirectory.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void shouldReturnFalseOutsideRepositoryDirectory(GitConnectionFactory connectionFactory) throws ServerException, IOException, UnauthorizedException, URISyntaxException {
    // given
    GitConnection externalDir = connectionFactory.getConnection(regularDir);
    // when
    boolean isInsideWorkingTree = externalDir.isInsideWorkTree();
    // then
    assertFalse(isInsideWorkingTree);
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 17 with GitConnection

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

the class LogTest method testLogWithFileFilter.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testLogWithFileFilter(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"));
    addFile(connection, "newFile.txt", "someChanges");
    connection.add(AddParams.create(ImmutableList.of("newFile.txt")));
    connection.commit(CommitParams.create("Add newFile.txt"));
    //when
    int readMeCommitCount = connection.log(LogParams.create().withFileFilter(Collections.singletonList("README.txt"))).getCommits().size();
    int newFileCommitCount = connection.log(LogParams.create().withFileFilter(Collections.singletonList("newFile.txt"))).getCommits().size();
    List<String> fileFilter = new ArrayList<>();
    fileFilter.add("README.txt");
    fileFilter.add("newFile.txt");
    int allFilesCommitCount = connection.log(LogParams.create().withFileFilter(fileFilter)).getCommits().size();
    //then
    assertEquals(3, readMeCommitCount);
    assertEquals(1, newFileCommitCount);
    assertEquals(4, allFilesCommitCount);
}
Also used : ArrayList(java.util.ArrayList) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 18 with GitConnection

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

the class PushTest method testPushWhenLocalRepositoryIsUpToDate.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testPushWhenLocalRepositoryIsUpToDate(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()));
    //when
    PushResponse pushResponse = localConnection.push(PushParams.create("origin").withRefSpec(singletonList("refs/heads/master:refs/heads/master")).withTimeout(-1));
    //then
    assertEquals(pushResponse.getCommandOutput(), "Everything up-to-date");
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) PushResponse(org.eclipse.che.api.git.shared.PushResponse) Test(org.testng.annotations.Test)

Example 19 with GitConnection

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

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

Example 20 with GitConnection

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

the class PushTest method testSimplePush.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testSimplePush(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    GitConnection remoteConnection = connectionFactory.getConnection(remoteRepo.getAbsolutePath());
    remoteConnection.clone(CloneParams.create(connection.getWorkingDir().getAbsolutePath()).withWorkingDir(remoteConnection.getWorkingDir().getAbsolutePath()));
    addFile(remoteConnection, "newfile", "content");
    remoteConnection.add(AddParams.create(singletonList(".")));
    remoteConnection.commit(CommitParams.create("Fake commit"));
    //when
    remoteConnection.push(PushParams.create("origin").withRefSpec(singletonList("refs/heads/master:refs/heads/test")).withTimeout(-1));
    //then
    //check branches in origin repository
    assertEquals(connection.branchList(null).size(), 1);
    //checkout test branch
    connection.checkout(CheckoutParams.create("test"));
    assertTrue(new File(connection.getWorkingDir(), "newfile").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)

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