use of org.eclipse.che.api.git.exception.GitException in project che by eclipse.
the class PushTest method testPushWhenLocalRepositoryIsNotSynchronisedWithRemote.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testPushWhenLocalRepositoryIsNotSynchronisedWithRemote(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
//given
GitConnection remoteConnection = connectToGitRepositoryWithContent(connectionFactory, repository);
GitConnection localConnection = connectionFactory.getConnection(remoteRepo.getAbsolutePath());
localConnection.clone(CloneParams.create(remoteConnection.getWorkingDir().getAbsolutePath()));
addFile(remoteConnection, "newfile", "content");
remoteConnection.add(AddParams.create(singletonList(".")));
remoteConnection.commit(CommitParams.create("Fake commit"));
//when
String errorMessage = "";
try {
localConnection.push(PushParams.create("origin").withTimeout(-1));
} catch (GitException exception) {
errorMessage = exception.getMessage();
}
//then
assertTrue(errorMessage.contains("master -> master"));
assertTrue(errorMessage.contains(remoteConnection.getWorkingDir().getAbsolutePath()));
}
use of org.eclipse.che.api.git.exception.GitException in project che by eclipse.
the class GitHubService method updateSSHKey.
@POST
@Path("ssh/generate")
public void updateSSHKey() throws ApiException {
final String host = "github.com";
SshPair sshPair = null;
try {
sshPair = sshServiceClient.getPair("vcs", host);
} catch (NotFoundException ignored) {
}
if (sshPair != null) {
if (sshPair.getPublicKey() == null) {
sshServiceClient.removePair("vcs", host);
sshPair = sshServiceClient.generatePair(newDto(GenerateSshPairRequest.class).withService("vcs").withName(host));
}
} else {
sshPair = sshServiceClient.generatePair(newDto(GenerateSshPairRequest.class).withService("vcs").withName(host));
}
// update public key
try {
githubKeyUploader.uploadKey(sshPair.getPublicKey());
} catch (IOException e) {
LOG.error("Upload github ssh key fail", e);
throw new GitException(e.getMessage(), e);
}
}
use of org.eclipse.che.api.git.exception.GitException in project che by eclipse.
the class JGitConnection method cloneWithSparseCheckout.
@Override
public void cloneWithSparseCheckout(String directory, String remoteUrl) throws GitException, UnauthorizedException {
//TODO rework this code when jgit will support sparse-checkout. Tracked issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=383772
if (directory == null) {
throw new GitException("Subdirectory for sparse-checkout is not specified");
}
clone(CloneParams.create(remoteUrl));
final String sourcePath = getWorkingDir().getPath();
final String keepDirectoryPath = sourcePath + "/" + directory;
IOFileFilter folderFilter = new DirectoryFileFilter() {
public boolean accept(File dir) {
String directoryPath = dir.getPath();
return !(directoryPath.startsWith(keepDirectoryPath) || directoryPath.startsWith(sourcePath + "/.git"));
}
};
Collection<File> files = org.apache.commons.io.FileUtils.listFilesAndDirs(getWorkingDir(), TrueFileFilter.INSTANCE, folderFilter);
try {
DirCache index = getRepository().lockDirCache();
int sourcePathLength = sourcePath.length() + 1;
files.stream().filter(File::isFile).forEach(file -> index.getEntry(file.getPath().substring(sourcePathLength)).setAssumeValid(true));
index.write();
index.commit();
for (File file : files) {
if (keepDirectoryPath.startsWith(file.getPath())) {
continue;
}
if (file.exists()) {
FileUtils.delete(file, FileUtils.RECURSIVE);
}
}
} catch (IOException exception) {
String message = generateExceptionMessage(exception);
throw new GitException(message, exception);
}
}
use of org.eclipse.che.api.git.exception.GitException in project che by eclipse.
the class JGitConnection method init.
@Override
public void init(boolean isBare) throws GitException {
File workDir = repository.getWorkTree();
if (!workDir.exists()) {
throw new GitException(format(ERROR_INIT_FOLDER_MISSING, workDir));
}
// If create fails and the .git folder didn't exist we want to remove it.
// We have to do this here because the create command doesn't revert its own changes in case of failure.
boolean removeIfFailed = !repository.getDirectory().exists();
try {
repository.create(isBare);
} catch (IOException exception) {
if (removeIfFailed) {
deleteRepositoryFolder();
}
throw new GitException(exception.getMessage(), exception);
}
}
use of org.eclipse.che.api.git.exception.GitException in project che by eclipse.
the class JGitConnection method rm.
@Override
public void rm(RmParams params) throws GitException {
List<String> files = params.getItems();
RmCommand rmCommand = getGit().rm();
rmCommand.setCached(params.isCached());
if (files != null) {
files.forEach(rmCommand::addFilepattern);
}
try {
rmCommand.call();
} catch (GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
Aggregations