use of org.eclipse.che.api.git.shared.ShowFileContentResponse 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());
}
use of org.eclipse.che.api.git.shared.ShowFileContentResponse 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());
}
use of org.eclipse.che.api.git.shared.ShowFileContentResponse in project che by eclipse.
the class ComparePresenter method showCompareBetweenRevisions.
/**
*
* @param file
* path of the file
* @param status
* status of the file
* @param revisionA
* hash of the first revision or branch.
* If it is set to {@code null}, compare with empty repository state will be performed
* @param revisionB
* hash of the second revision or branch.
* If it is set to {@code null}, compare with latest repository state will be performed
*/
public void showCompareBetweenRevisions(final Path file, final Status status, @Nullable final String revisionA, @Nullable final String revisionB) {
this.compareWithLatest = false;
final DevMachine devMachine = appContext.getDevMachine();
final Path projectLocation = appContext.getRootProject().getLocation();
view.setTitle(file.toString());
if (status == Status.ADDED) {
service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse response) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA == null ? "" : revisionA + locale.compareReadOnlyTitle());
view.show("", response.getContent(), file.toString(), true);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
} else if (status == Status.DELETED) {
service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse response) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
view.show(response.getContent(), "", file.toString(), true);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
} else {
service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(final ShowFileContentResponse contentAResponse) throws OperationException {
service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse contentBResponse) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
view.show(contentAResponse.getContent(), contentBResponse.getContent(), file.toString(), true);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
}
});
}
}
use of org.eclipse.che.api.git.shared.ShowFileContentResponse in project che by eclipse.
the class JGitConnection method showFileContent.
@Override
public ShowFileContentResponse showFileContent(String file, String version) throws GitException {
String content;
ObjectId revision;
try {
revision = getRepository().resolve(version);
try (RevWalk revWalk = new RevWalk(getRepository())) {
RevCommit revCommit = revWalk.parseCommit(revision);
RevTree tree = revCommit.getTree();
try (TreeWalk treeWalk = new TreeWalk(getRepository())) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(file));
if (!treeWalk.next()) {
throw new GitException("fatal: Path '" + file + "' does not exist in '" + version + "'" + lineSeparator());
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
content = new String(loader.getBytes());
}
}
} catch (IOException exception) {
throw new GitException(exception.getMessage());
}
return newDto(ShowFileContentResponse.class).withContent(content);
}
use of org.eclipse.che.api.git.shared.ShowFileContentResponse in project che by eclipse.
the class ComparePresenter method showCompareWithLatest.
/**
* Show compare window.
*
* @param file
* file name with its full path
* @param status
* status of the file
* @param revision
* hash of revision or branch
*/
public void showCompareWithLatest(final File file, final Status status, final String revision) {
this.comparedFile = file;
this.revision = revision;
this.compareWithLatest = true;
if (status.equals(ADDED)) {
showCompare("");
return;
}
final Optional<Project> project = file.getRelatedProject();
if (!project.isPresent()) {
return;
}
final Path relPath = file.getLocation().removeFirstSegments(project.get().getLocation().segmentCount());
if (status.equals(DELETED)) {
service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse content) throws OperationException {
view.setTitle(file.getLocation().toString());
view.setColumnTitles(locale.compareYourVersionTitle(), revision + locale.compareReadOnlyTitle());
view.show(content.getContent(), "", file.getLocation().toString(), false);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
} else {
service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision).then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse content) throws OperationException {
showCompare(content.getContent());
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
}
}
Aggregations