Search in sources :

Example 46 with GitConnection

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

the class ResetTest method testResetHard.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testResetHard(GitConnectionFactory connectionFactory) throws Exception {
    //given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    File aaa = addFile(connection, "aaa", "aaa\n");
    FileOutputStream fos = new FileOutputStream(new File(connection.getWorkingDir(), "README.txt"));
    fos.write("MODIFIED\n".getBytes());
    fos.flush();
    fos.close();
    String initMessage = connection.log(LogParams.create()).getCommits().get(0).getMessage();
    connection.add(AddParams.create(new ArrayList<>(singletonList("."))));
    connection.commit(CommitParams.create("add file"));
    //when
    connection.reset(ResetParams.create("HEAD^", ResetRequest.ResetType.HARD));
    //then
    assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), initMessage);
    assertFalse(aaa.exists());
    assertTrue(connection.status(StatusFormat.SHORT).isClean());
    assertEquals(CONTENT, Files.toString(new File(connection.getWorkingDir(), "README.txt"), Charsets.UTF_8));
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) 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 47 with GitConnection

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

the class ShowFileContentTest method testShowContentOfNotExistFile.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class, expectedExceptions = GitException.class, expectedExceptionsMessageRegExp = "fatal: Path 'dummyFile' does not exist in 'HEAD'\n")
public void testShowContentOfNotExistFile(GitConnectionFactory connectionFactory) throws Exception {
    //given
    //create new repository
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "newfile", "new file content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("Test commit"));
    //when
    connection.showFileContent("dummyFile", "HEAD");
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 48 with GitConnection

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

the class ShowFileContentTest method testShowFileContentFromBranch.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testShowFileContentFromBranch(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
    //given
    //create new repository
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "newFile", "new file content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("Test commit"));
    connection.branchCreate("new-branch", null);
    //when
    final ShowFileContentResponse response = connection.showFileContent("newFile", "new-branch");
    //then
    assertEquals("new file content", response.getContent());
}
Also used : ShowFileContentResponse(org.eclipse.che.api.git.shared.ShowFileContentResponse) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 49 with GitConnection

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

the class ShowFileContentTest method testShowFileContentFromHead.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testShowFileContentFromHead(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
    //given
    //create new repository
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "newFile", "new file content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("Test commit"));
    //when
    final ShowFileContentResponse response = connection.showFileContent("newFile", "HEAD");
    //then
    assertEquals("new file content", response.getContent());
}
Also used : ShowFileContentResponse(org.eclipse.che.api.git.shared.ShowFileContentResponse) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 50 with GitConnection

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

the class StatusTest method testModified.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testModified(GitConnectionFactory connectionFactory) throws Exception {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "a", "a content");
    addFile(connection, "b", "b content");
    //add "a" and "b"
    connection.add(AddParams.create(ImmutableList.of("a", "b")));
    //modify "a"
    addFile(connection, "a", "new content of a");
    //when
    final Status status = connection.status(StatusFormat.SHORT);
    //then
    assertEquals(status.getModified(), ImmutableList.of("a"));
    assertTrue(status.getUntracked().isEmpty());
    assertTrue(status.getChanged().isEmpty());
    assertTrue(status.getConflicting().isEmpty());
    assertTrue(status.getMissing().isEmpty());
    assertTrue(status.getRemoved().isEmpty());
    assertTrue(status.getUntrackedFolders().isEmpty());
}
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