Search in sources :

Example 66 with GitConnection

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

the class CloneTest method testLineConsumerOutputWhenCloning.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testLineConsumerOutputWhenCloning(GitConnectionFactory connectionFactory) throws ServerException, IOException, UnauthorizedException, URISyntaxException {
    //given
    GitConnection remoteConnection = connectToGitRepositoryWithContent(connectionFactory, remoteRepo);
    GitConnection localConnection = connectionFactory.getConnection(localRepo.getAbsolutePath());
    LineConsumerFactory lineConsumerFactory = mock(LineConsumerFactory.class);
    LineConsumer lineConsumer = mock(LineConsumer.class);
    when(lineConsumerFactory.newLineConsumer()).thenReturn(lineConsumer);
    localConnection.setOutputLineConsumerFactory(lineConsumerFactory);
    //when
    localConnection.clone(CloneParams.create(remoteConnection.getWorkingDir().getAbsolutePath()));
    //then
    verify(lineConsumer, atLeastOnce()).writeLine(anyString());
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) GitConnection(org.eclipse.che.api.git.GitConnection) LineConsumerFactory(org.eclipse.che.api.core.util.LineConsumerFactory) Test(org.testng.annotations.Test)

Example 67 with GitConnection

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

the class CommitTest method testChangeMessageOfLastCommitWithSpecifiedPath.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testChangeMessageOfLastCommitWithSpecifiedPath(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    addFile(connection, "NewFile.txt", CONTENT);
    connection.add(AddParams.create(ImmutableList.of("NewFile.txt")));
    connection.commit(CommitParams.create("First commit"));
    int beforeCommitsCount = connection.log(LogParams.create()).getCommits().size();
    //when
    CommitParams commitParams = CommitParams.create("Changed message").withFiles(singletonList("NewFile.txt")).withAmend(true);
    connection.commit(commitParams);
    //then
    int afterCommitsCount = connection.log(LogParams.create()).getCommits().size();
    assertEquals(beforeCommitsCount, afterCommitsCount);
    assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), commitParams.getMessage());
}
Also used : CommitParams(org.eclipse.che.api.git.params.CommitParams) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 68 with GitConnection

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

the class CommitTest method testSimpleCommit.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testSimpleCommit(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    //add new File
    addFile(connection, "DONTREADME", "secret");
    //add changes
    connection.add(AddParams.create(AddRequest.DEFAULT_PATTERN));
    //when
    CommitParams commitParams = CommitParams.create("Commit message").withAmend(false).withAll(false);
    Revision revision = connection.commit(commitParams);
    //then
    assertEquals(revision.getMessage(), commitParams.getMessage());
}
Also used : CommitParams(org.eclipse.che.api.git.params.CommitParams) Revision(org.eclipse.che.api.git.shared.Revision) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 69 with GitConnection

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

the class CommitTest method testCommitWithNotStagedChanges.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class, expectedExceptions = GitException.class, expectedExceptionsMessageRegExp = "No changes added to commit")
public void testCommitWithNotStagedChanges(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    //Prepare unstaged deletion
    addFile(connection, "FileToDelete.txt", "content");
    connection.add(AddParams.create(ImmutableList.of("FileToDelete.txt")));
    connection.commit(CommitParams.create("File to delete"));
    new File(connection.getWorkingDir().getAbsolutePath(), "FileToDelete.txt").delete();
    //Prepare unstaged new file
    addFile(connection, "newFile", "content");
    //Prepare unstaged editing
    write(new File(connection.getWorkingDir(), "README.txt").toPath(), "new content".getBytes());
    //when
    connection.commit(CommitParams.create("test commit"));
}
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 70 with GitConnection

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

the class CommitTest method testChangeMessageOfLastCommit.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testChangeMessageOfLastCommit(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    addFile(connection, "NewFile.txt", CONTENT);
    connection.add(AddParams.create(ImmutableList.of("NewFile.txt")));
    connection.commit(CommitParams.create("First commit"));
    int beforeCommitsCount = connection.log(LogParams.create()).getCommits().size();
    //when
    CommitParams commitParams = CommitParams.create("Changed message").withAmend(true);
    connection.commit(commitParams);
    //then
    int afterCommitsCount = connection.log(LogParams.create()).getCommits().size();
    assertEquals(beforeCommitsCount, afterCommitsCount);
    assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), commitParams.getMessage());
}
Also used : CommitParams(org.eclipse.che.api.git.params.CommitParams) 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