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);
}
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");
}
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);
}
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());
}
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);
}
Aggregations