Search in sources :

Example 1 with ResetRequest

use of org.eclipse.che.api.git.shared.ResetRequest in project che by eclipse.

the class GitServiceClientImpl method reset.

@Override
public void reset(DevMachine devMachine, ProjectConfigDto project, String commit, @Nullable ResetRequest.ResetType resetType, @Nullable List<String> filePattern, AsyncRequestCallback<Void> callback) {
    ResetRequest resetRequest = dtoFactory.createDto(ResetRequest.class).withCommit(commit);
    if (resetType != null) {
        resetRequest.setType(resetType);
    }
    if (filePattern != null) {
        resetRequest.setFilePattern(filePattern);
    }
    String url = appContext.getDevMachine().getWsAgentBaseUrl() + RESET + "?projectPath=" + project.getPath();
    asyncRequestFactory.createPostRequest(url, resetRequest).loader(loader).send(callback);
}
Also used : ResetRequest(org.eclipse.che.api.git.shared.ResetRequest)

Example 2 with ResetRequest

use of org.eclipse.che.api.git.shared.ResetRequest in project che by eclipse.

the class GitServiceClientImpl method reset.

@Override
public Promise<Void> reset(DevMachine devMachine, Path project, String commit, ResetRequest.ResetType resetType, Path[] files) {
    ResetRequest resetRequest = dtoFactory.createDto(ResetRequest.class).withCommit(commit);
    if (resetType != null) {
        resetRequest.setType(resetType);
    }
    if (files != null) {
        List<String> fileList = new ArrayList<>(files.length);
        for (Path file : files) {
            fileList.add(file.isEmpty() ? "." : file.toString());
        }
        resetRequest.setFilePattern(fileList);
    }
    String url = devMachine.getWsAgentBaseUrl() + RESET + "?projectPath=" + project;
    return asyncRequestFactory.createPostRequest(url, resetRequest).loader(loader).send();
}
Also used : Path(org.eclipse.che.ide.resource.Path) ArrayList(java.util.ArrayList) ResetRequest(org.eclipse.che.api.git.shared.ResetRequest)

Example 3 with ResetRequest

use of org.eclipse.che.api.git.shared.ResetRequest 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)

Aggregations

ResetRequest (org.eclipse.che.api.git.shared.ResetRequest)3 ArrayList (java.util.ArrayList)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 GitConnection (org.eclipse.che.api.git.GitConnection)1 GitTestUtil.addFile (org.eclipse.che.git.impl.GitTestUtil.addFile)1 Path (org.eclipse.che.ide.resource.Path)1 Test (org.testng.annotations.Test)1