Search in sources :

Example 91 with GitConnection

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

the class RemoveTest method testCachedRemove.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testCachedRemove(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    //when
    connection.rm(RmParams.create(singletonList("README.txt")).withCached(true));
    //then
    assertTrue(new File(connection.getWorkingDir(), "README.txt").exists());
    assertEquals(connection.status(StatusFormat.SHORT).getRemoved().get(0), "README.txt");
    assertEquals(connection.status(StatusFormat.SHORT).getUntracked().get(0), "README.txt");
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) File(java.io.File) Test(org.testng.annotations.Test)

Example 92 with GitConnection

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

the class ResetTest method testResetMixed.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testResetMixed(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
    ResetRequest resetRequest = newDto(ResetRequest.class).withCommit("HEAD^");
    connection.reset(ResetParams.create("HEAD^", ResetRequest.ResetType.MIXED));
    //then
    assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), initMessage);
    assertTrue(aaa.exists());
    assertEquals(connection.status(StatusFormat.SHORT).getUntracked().get(0), "aaa");
    assertEquals(connection.status(StatusFormat.SHORT).getModified().get(0), "README.txt");
    assertEquals(Files.toString(new File(connection.getWorkingDir(), "README.txt"), Charsets.UTF_8), "MODIFIED\n");
}
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) ResetRequest(org.eclipse.che.api.git.shared.ResetRequest) Test(org.testng.annotations.Test)

Example 93 with GitConnection

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

the class StatusTest method testEmptyStatus.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testEmptyStatus(GitConnectionFactory connectionFactory) throws Exception {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    //when
    final Status status = connection.status(StatusFormat.SHORT);
    //then
    assertTrue(status.getAdded().isEmpty());
    assertTrue(status.getChanged().isEmpty());
    assertTrue(status.getConflicting().isEmpty());
    assertTrue(status.getMissing().isEmpty());
    assertTrue(status.getRemoved().isEmpty());
    assertTrue(status.getUntracked().isEmpty());
    assertTrue(status.getUntrackedFolders().isEmpty());
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 94 with GitConnection

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

the class StatusTest method testChanged.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testChanged(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")));
    //commit "a" and "b"
    connection.commit(CommitParams.create("add 2 test files"));
    //modify "a"
    addFile(connection, "a", "modified content of a");
    //add "a"
    connection.add(AddParams.create(ImmutableList.of("a")));
    //change "a"
    addFile(connection, "a", "changed content of a");
    //when
    final Status status = connection.status(StatusFormat.SHORT);
    //then
    assertEquals(status.getChanged(), ImmutableList.of("a"));
    assertTrue(status.getAdded().isEmpty());
    assertTrue(status.getUntracked().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)

Example 95 with GitConnection

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

the class StatusTest method testRemovedFromIndex.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testRemovedFromIndex(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")));
    //commit "a" and "b"
    connection.commit(CommitParams.create("add 2 test files"));
    //remove "a" from index
    connection.rm(RmParams.create(ImmutableList.of("a")));
    //when
    final Status status = connection.status(StatusFormat.SHORT);
    //then
    assertEquals(status.getRemoved(), ImmutableList.of("a"));
    assertTrue(status.getAdded().isEmpty());
    assertTrue(status.getChanged().isEmpty());
    assertTrue(status.getConflicting().isEmpty());
    assertTrue(status.getMissing().isEmpty());
    assertTrue(status.getUntracked().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