Search in sources :

Example 61 with GitConnection

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

the class BranchDeleteTest method shouldDeleteNotFullyMergedBranchWithForce.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void shouldDeleteNotFullyMergedBranchWithForce(GitConnectionFactory connectionFactory) throws GitException, IOException, UnauthorizedException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "README.txt", org.eclipse.che.git.impl.GitTestUtil.CONTENT);
    connection.add(AddParams.create(singletonList("README.txt")));
    connection.commit(CommitParams.create("Initial addd"));
    //create new branch and make a commit
    connection.checkout(CheckoutParams.create("newbranch").withCreateNew(true));
    addFile(connection, "newfile", "new file content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("second commit"));
    connection.checkout(CheckoutParams.create("master"));
    //when
    connection.branchDelete("newbranch", true);
    //then
    assertTrue(Sets.symmetricDifference(Sets.newHashSet(connection.branchList(LIST_LOCAL)), Sets.newHashSet(newDto(Branch.class).withName("refs/heads/master").withDisplayName("master").withActive(true).withRemote(false))).isEmpty());
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 62 with GitConnection

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

the class CheckoutTest method testCheckoutTwoFiles.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testCheckoutTwoFiles(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "README.txt", org.eclipse.che.git.impl.GitTestUtil.CONTENT);
    String ORIG_CONTENT_1_TXT = "1.txt original content";
    String ORIG_CONTENT_2_TXT = "2.txt original content";
    addFile(connection, "1.txt", ORIG_CONTENT_1_TXT);
    addFile(connection, "2.txt", ORIG_CONTENT_2_TXT);
    connection.add(AddParams.create(ImmutableList.of("README.txt", "1.txt", "2.txt")));
    connection.commit(CommitParams.create("Initial addd"));
    //when
    //modify the two files
    String MODIFIED_CONTENT_1_TXT = "1.txt modified content";
    String MODIFIED_CONTENT_2_TXT = "2.txt modified content";
    addFile(connection, "1.txt", MODIFIED_CONTENT_1_TXT);
    addFile(connection, "2.txt", MODIFIED_CONTENT_2_TXT);
    //then
    assertTrue(new File(repository, "1.txt").exists());
    assertTrue(new File(repository, "2.txt").exists());
    assertEquals(MODIFIED_CONTENT_1_TXT, Files.toString(new File(connection.getWorkingDir(), "1.txt"), Charsets.UTF_8));
    assertEquals(MODIFIED_CONTENT_2_TXT, Files.toString(new File(connection.getWorkingDir(), "2.txt"), Charsets.UTF_8));
    //when
    connection.checkout(CheckoutParams.create(null).withFiles(ImmutableList.of("1.txt", "2.txt")));
    //then
    assertTrue(new File(repository, "1.txt").exists());
    assertTrue(new File(repository, "2.txt").exists());
    assertEquals(ORIG_CONTENT_1_TXT, Files.toString(new File(connection.getWorkingDir(), "1.txt"), Charsets.UTF_8));
    assertEquals(ORIG_CONTENT_2_TXT, Files.toString(new File(connection.getWorkingDir(), "2.txt"), Charsets.UTF_8));
}
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 63 with GitConnection

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

the class CheckoutTest method testTrackRemoteBranch.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testTrackRemoteBranch(GitConnectionFactory connectionFactory) throws GitException, IOException, UnauthorizedException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "README.txt", org.eclipse.che.git.impl.GitTestUtil.CONTENT);
    connection.add(AddParams.create(singletonList("README.txt")));
    connection.commit(CommitParams.create("Initial add"));
    //when
    //create branch additional branch and make a commit
    connection.branchCreate(FIRST_BRANCH_NAME, null);
    connection.checkout(CheckoutParams.create(FIRST_BRANCH_NAME));
    addFile(connection, "newfile", "new file content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("Commit message"));
    connection.checkout(CheckoutParams.create("master"));
    //check existence of 2 branches
    assertEquals(connection.branchList(null).size(), 2);
    //when
    connection.checkout(CheckoutParams.create(SECOND_BRANCH_NAME).withCreateNew(true).withTrackBranch(FIRST_BRANCH_NAME));
    //then
    assertEquals(connection.branchList(null).size(), 3);
    assertTrue(new File(repository, "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 64 with GitConnection

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

the class CheckoutTest method testSimpleCheckout.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testSimpleCheckout(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "README.txt", org.eclipse.che.git.impl.GitTestUtil.CONTENT);
    connection.add(AddParams.create(singletonList("README.txt")));
    connection.commit(CommitParams.create("Initial addd"));
    //when
    //create additional branch and make a commit
    connection.branchCreate(FIRST_BRANCH_NAME, null);
    connection.checkout(CheckoutParams.create(FIRST_BRANCH_NAME));
    addFile(connection, "newfile", "new file content");
    connection.add(AddParams.create(AddRequest.DEFAULT_PATTERN));
    connection.commit(CommitParams.create("Commit message"));
    connection.checkout(CheckoutParams.create("master"));
    //then
    assertFalse(new File(repository, "newf3ile").exists());
    //when
    connection.checkout(CheckoutParams.create(FIRST_BRANCH_NAME));
    //then
    assertTrue(new File(repository, "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 65 with GitConnection

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

the class CheckoutTest method testCheckoutFromStartPoint.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testCheckoutFromStartPoint(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "README.txt", org.eclipse.che.git.impl.GitTestUtil.CONTENT);
    connection.add(AddParams.create(singletonList("README.txt")));
    connection.commit(CommitParams.create("Initial addd"));
    //when
    //create branch additional branch and make a commit
    connection.branchCreate(FIRST_BRANCH_NAME, null);
    connection.checkout(CheckoutParams.create(FIRST_BRANCH_NAME));
    addFile(connection, "newfile", "new file content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("Commit message"));
    connection.checkout(CheckoutParams.create("master"));
    //check existence of 2 branches
    assertEquals(connection.branchList(null).size(), 2);
    //when
    connection.checkout(CheckoutParams.create(SECOND_BRANCH_NAME).withStartPoint(FIRST_BRANCH_NAME).withCreateNew(true));
    //then
    assertEquals(connection.branchList(null).size(), 3);
    assertTrue(new File(repository, "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)

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