Search in sources :

Example 41 with GitConnection

use of org.eclipse.che.api.git.GitConnection in project che by eclipse.

the class PushTest method testSimplePush.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testSimplePush(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    GitConnection remoteConnection = connectionFactory.getConnection(remoteRepo.getAbsolutePath());
    remoteConnection.clone(CloneParams.create(connection.getWorkingDir().getAbsolutePath()).withWorkingDir(remoteConnection.getWorkingDir().getAbsolutePath()));
    addFile(remoteConnection, "newfile", "content");
    remoteConnection.add(AddParams.create(singletonList(".")));
    remoteConnection.commit(CommitParams.create("Fake commit"));
    //when
    remoteConnection.push(PushParams.create("origin").withRefSpec(singletonList("refs/heads/master:refs/heads/test")).withTimeout(-1));
    //then
    //check branches in origin repository
    assertEquals(connection.branchList(null).size(), 1);
    //checkout test branch
    connection.checkout(CheckoutParams.create("test"));
    assertTrue(new File(connection.getWorkingDir(), "newfile").exists());
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) File(java.io.File) GitTestUtil.addFile(org.eclipse.che.git.impl.GitTestUtil.addFile) Test(org.testng.annotations.Test)

Example 42 with GitConnection

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);
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 43 with GitConnection

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"));
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 44 with GitConnection

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");
}
Also used : RemoteUpdateParams(org.eclipse.che.api.git.params.RemoteUpdateParams) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 45 with GitConnection

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");
}
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) Test(org.testng.annotations.Test)

Aggregations

GitConnection (org.eclipse.che.api.git.GitConnection)102 Test (org.testng.annotations.Test)100 File (java.io.File)19 GitTestUtil.addFile (org.eclipse.che.git.impl.GitTestUtil.addFile)16 Revision (org.eclipse.che.api.git.shared.Revision)9 ArrayList (java.util.ArrayList)6 CommitParams (org.eclipse.che.api.git.params.CommitParams)5 FileOutputStream (java.io.FileOutputStream)3 MergeResult (org.eclipse.che.api.git.shared.MergeResult)3 DiffPage (org.eclipse.che.api.git.DiffPage)2 GitException (org.eclipse.che.api.git.exception.GitException)2 DiffParams (org.eclipse.che.api.git.params.DiffParams)2 ShowFileContentResponse (org.eclipse.che.api.git.shared.ShowFileContentResponse)2 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)1 LineConsumerFactory (org.eclipse.che.api.core.util.LineConsumerFactory)1 PullParams (org.eclipse.che.api.git.params.PullParams)1 RemoteAddParams (org.eclipse.che.api.git.params.RemoteAddParams)1 RemoteUpdateParams (org.eclipse.che.api.git.params.RemoteUpdateParams)1