use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class PushTest method testPushRemote.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testPushRemote(GitConnectionFactory connectionFactory) throws GitException, IOException, URISyntaxException, UnauthorizedException {
//given
GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
GitConnection remoteConnection = connectToInitializedGitRepository(connectionFactory, remoteRepo);
addFile(connection, "README", "README");
connection.add(AddParams.create(singletonList(".")));
connection.commit(CommitParams.create("Init commit."));
//make push
int branchesBefore = remoteConnection.branchList(null).size();
//when
connection.push(PushParams.create(remoteRepo.getAbsolutePath()).withRefSpec(singletonList("refs/heads/master:refs/heads/test")).withTimeout(-1));
//then
int branchesAfter = remoteConnection.branchList(null).size();
assertEquals(branchesAfter - 1, branchesBefore);
}
use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class RemoteUpdateTest method testAddUrl.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testAddUrl(GitConnectionFactory connectionFactory) throws GitException, IOException {
//given
GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
addInitialRemote(connection);
//when
connection.remoteUpdate(RemoteUpdateParams.create("newRemote").withAddUrl(singletonList("new.com")));
//then
assertTrue(parseAllConfig(connection).get("remote.newRemote.url").contains("new.com"));
}
use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class RemoteUpdateTest method testUpdateBranches.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testUpdateBranches(GitConnectionFactory connectionFactory) throws GitException, IOException {
//given
GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
addInitialRemote(connection);
//when
//change branch1 to branch2
RemoteUpdateParams request = RemoteUpdateParams.create("newRemote").withBranches(singletonList("branch2"));
connection.remoteUpdate(request);
//then
assertEquals(parseAllConfig(connection).get("remote.newRemote.fetch").get(0), "+refs/heads/branch2:refs/remotes/newRemote/branch2");
}
use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class ResetTest method testResetSoft.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testResetSoft(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
connection.reset(ResetParams.create("HEAD^", ResetRequest.ResetType.SOFT));
//then
assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), initMessage);
assertTrue(aaa.exists());
assertEquals(connection.status(StatusFormat.SHORT).getAdded().get(0), "aaa");
assertEquals(connection.status(StatusFormat.SHORT).getChanged().get(0), "README.txt");
assertEquals(Files.toString(new File(connection.getWorkingDir(), "README.txt"), Charsets.UTF_8), "MODIFIED\n");
}
use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class ResetTest method testResetHard.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testResetHard(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
connection.reset(ResetParams.create("HEAD^", ResetRequest.ResetType.HARD));
//then
assertEquals(connection.log(LogParams.create()).getCommits().get(0).getMessage(), initMessage);
assertFalse(aaa.exists());
assertTrue(connection.status(StatusFormat.SHORT).isClean());
assertEquals(CONTENT, Files.toString(new File(connection.getWorkingDir(), "README.txt"), Charsets.UTF_8));
}
Aggregations