use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class MergeTest method testMerge.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testMerge(GitConnectionFactory connectionFactory) throws Exception {
//given
GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
connection.checkout(CheckoutParams.create(branchName).withCreateNew(true));
File file = addFile(connection, "t-merge", "aaa\n");
connection.add(AddParams.create(new ArrayList<>(singletonList("."))));
connection.commit(CommitParams.create("add file in new branch"));
connection.checkout(CheckoutParams.create("master"));
//when
MergeResult mergeResult = connection.merge(branchName);
//then
assertEquals(mergeResult.getMergeStatus(), MergeResult.MergeStatus.FAST_FORWARD);
assertTrue(file.exists());
assertEquals(Files.toString(file, Charsets.UTF_8), "aaa\n");
assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), "add file in new branch");
}
use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class PullTest method testWhenThereAreNoAnyRemotesBehindTheProxy.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class, expectedExceptions = GitException.class, expectedExceptionsMessageRegExp = "No remote repository specified. " + "Please, specify either a URL or a remote name from which new revisions should be fetched in request.")
public void testWhenThereAreNoAnyRemotesBehindTheProxy(GitConnectionFactory connectionFactory) throws Exception {
//given
System.setProperty("http.proxyUser", "user1");
System.setProperty("http.proxyPassword", "paswd1");
System.setProperty("https.proxyUser", "user2");
System.setProperty("https.proxyPassword", "paswd2");
GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
//when
connection.pull(PullParams.create(null));
}
use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class PullTest method testPullRemote.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testPullRemote(GitConnectionFactory connectionFactory) throws GitException, IOException, URISyntaxException, UnauthorizedException {
//given
GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
String branchName = "remoteBranch";
connection.checkout(CheckoutParams.create(branchName).withCreateNew(true));
addFile(connection, "remoteFile", "");
connection.add(AddParams.create(singletonList(".")));
connection.commit(CommitParams.create("remote test"));
GitConnection connection2 = connectToGitRepositoryWithContent(connectionFactory, remoteRepo);
//when
PullParams params = PullParams.create(connection.getWorkingDir().getAbsolutePath()).withRefSpec("refs/heads/remoteBranch:refs/heads/remoteBranch");
connection2.pull(params);
//then
assertTrue(new File(remoteRepo.getAbsolutePath(), "remoteFile").exists());
}
use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class PullTest method testSimplePull.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testSimplePull(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
//given
//create new repository clone of default
GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
GitConnection connection2 = connectionFactory.getConnection(remoteRepo.getAbsolutePath());
connection2.clone(CloneParams.create(connection.getWorkingDir().getAbsolutePath()));
addFile(connection, "newfile1", "new file1 content");
connection.add(AddParams.create(singletonList(".")));
connection.commit(CommitParams.create("Test commit"));
//when
connection2.pull(PullParams.create("origin").withTimeout(-1));
//then
assertTrue(new File(remoteRepo.getAbsolutePath(), "newfile1").exists());
}
use of org.eclipse.che.api.git.GitConnection 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()));
}
Aggregations