Search in sources :

Example 81 with GitConnection

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

the class IsInsideWorkTreeTest method shouldReturnFalseInsideDotGitDirectory.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void shouldReturnFalseInsideDotGitDirectory(GitConnectionFactory connectionFactory) throws ServerException, IOException, UnauthorizedException, URISyntaxException {
    // given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    Path internalDir = connection.getWorkingDir().toPath().resolve(".git");
    // when
    GitConnection internalDirConnection = connectionFactory.getConnection(internalDir.toFile());
    boolean isInsideWorkingTree = internalDirConnection.isInsideWorkTree();
    // then
    assertFalse(isInsideWorkingTree);
}
Also used : Path(java.nio.file.Path) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 82 with GitConnection

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

the class LogTest method testLogMaxCount.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testLogMaxCount(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "1.txt", "someChanges");
    connection.add(AddParams.create());
    connection.commit(CommitParams.create("add 1.txt file"));
    addFile(connection, "2.txt", "newChanges");
    connection.add(AddParams.create());
    connection.commit(CommitParams.create("add 2.txt file"));
    addFile(connection, "3.txt", "otherChanges");
    connection.add(AddParams.create());
    connection.commit(CommitParams.create("add 3.txt file"));
    addFile(connection, "4.txt", "someChanges");
    connection.add(AddParams.create());
    connection.commit(CommitParams.create("add 4.txt file"));
    //when
    List<Revision> allCommits = connection.log(LogParams.create()).getCommits();
    List<Revision> firstBucketOfCommits = connection.log(LogParams.create().withMaxCount(4)).getCommits();
    List<Revision> secondBucketOfCommits = connection.log(LogParams.create().withMaxCount(2)).getCommits();
    //then
    assertEquals(4, allCommits.size());
    assertEquals(4, firstBucketOfCommits.size());
    assertEquals(firstBucketOfCommits.get(0).getMessage(), "add 4.txt file");
    assertEquals(firstBucketOfCommits.get(1).getMessage(), "add 3.txt file");
    assertEquals(firstBucketOfCommits.get(2).getMessage(), "add 2.txt file");
    assertEquals(firstBucketOfCommits.get(3).getMessage(), "add 1.txt file");
    assertEquals(2, secondBucketOfCommits.size());
    assertEquals(secondBucketOfCommits.get(0).getMessage(), "add 4.txt file");
    assertEquals(secondBucketOfCommits.get(1).getMessage(), "add 3.txt file");
}
Also used : Revision(org.eclipse.che.api.git.shared.Revision) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 83 with GitConnection

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

the class RemoteAddTest method testSimpleRemoteAdd.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testSimpleRemoteAdd(GitConnectionFactory connectionFactory) throws GitException, IOException {
    //given
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    int beforeCount = connection.remoteList(null, false).size();
    //when
    connection.remoteAdd(RemoteAddParams.create("origin", "some.url"));
    //then
    int afterCount = connection.remoteList(null, false).size();
    assertEquals(afterCount, beforeCount + 1);
}
Also used : GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 84 with GitConnection

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

the class RemoteAddTest method testAddNotAllBranchesTracked.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testAddNotAllBranchesTracked(GitConnectionFactory connectionFactory) throws GitException, URISyntaxException, IOException, UnauthorizedException {
    //given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    connection.branchCreate("b1", null);
    connection.branchCreate("b2", null);
    connection.branchCreate("b3", null);
    GitConnection connection2 = connectionFactory.getConnection(remoteRepo.getAbsolutePath());
    connection2.init(false);
    //when
    //add remote tracked only to b1 and b3 branches.
    RemoteAddParams params = RemoteAddParams.create("origin", connection.getWorkingDir().getAbsolutePath()).withBranches(ImmutableList.of("b1", "b3"));
    connection2.remoteAdd(params);
    //then
    //make pull
    connection2.pull(PullParams.create("origin"));
    assertTrue(Sets.symmetricDifference(Sets.newHashSet(connection2.branchList(LIST_REMOTE)), Sets.newHashSet(newDto(Branch.class).withName("refs/remotes/origin/b1").withDisplayName("origin/b1").withActive(false).withRemote(true), newDto(Branch.class).withName("refs/remotes/origin/b3").withDisplayName("origin/b3").withActive(false).withRemote(true))).isEmpty());
}
Also used : RemoteAddParams(org.eclipse.che.api.git.params.RemoteAddParams) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 85 with GitConnection

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

the class RemoteDeleteTest method testRemoteDelete.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testRemoteDelete(GitConnectionFactory connectionFactory) throws GitException, IOException {
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    connection.remoteAdd(RemoteAddParams.create("origin", "host.com:username/Repo.git"));
    //now it is 1 remote
    assertEquals(connection.remoteList(null, false).size(), 1);
    //try delete not existing remote
    try {
        connection.remoteDelete("donotexists");
        fail("should be exception");
    } catch (GitException ignored) {
    }
    connection.remoteDelete("origin");
    //now it is 0 remotes
    assertEquals(connection.remoteList(null, false).size(), 0);
}
Also used : GitException(org.eclipse.che.api.git.exception.GitException) GitConnection(org.eclipse.che.api.git.GitConnection) 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