use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class IsInsideWorkTreeTest method shouldReturnFalseOutsideRepositoryDirectory.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void shouldReturnFalseOutsideRepositoryDirectory(GitConnectionFactory connectionFactory) throws ServerException, IOException, UnauthorizedException, URISyntaxException {
// given
GitConnection externalDir = connectionFactory.getConnection(regularDir);
// when
boolean isInsideWorkingTree = externalDir.isInsideWorkTree();
// then
assertFalse(isInsideWorkingTree);
}
use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class LogTest method testLogWithFileFilter.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testLogWithFileFilter(GitConnectionFactory connectionFactory) throws GitException, IOException {
//given
GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
addFile(connection, "README.txt", "someChanges");
connection.add(AddParams.create(ImmutableList.of("README.txt")));
connection.commit(CommitParams.create("Initial add"));
addFile(connection, "README.txt", "newChanges");
connection.add(AddParams.create(ImmutableList.of("README.txt")));
connection.commit(CommitParams.create("Second commit"));
addFile(connection, "README.txt", "otherChanges");
connection.add(AddParams.create(ImmutableList.of("README.txt")));
connection.commit(CommitParams.create("Third commit"));
addFile(connection, "newFile.txt", "someChanges");
connection.add(AddParams.create(ImmutableList.of("newFile.txt")));
connection.commit(CommitParams.create("Add newFile.txt"));
//when
int readMeCommitCount = connection.log(LogParams.create().withFileFilter(Collections.singletonList("README.txt"))).getCommits().size();
int newFileCommitCount = connection.log(LogParams.create().withFileFilter(Collections.singletonList("newFile.txt"))).getCommits().size();
List<String> fileFilter = new ArrayList<>();
fileFilter.add("README.txt");
fileFilter.add("newFile.txt");
int allFilesCommitCount = connection.log(LogParams.create().withFileFilter(fileFilter)).getCommits().size();
//then
assertEquals(3, readMeCommitCount);
assertEquals(1, newFileCommitCount);
assertEquals(4, allFilesCommitCount);
}
use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class PushTest method testPushWhenLocalRepositoryIsUpToDate.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
public void testPushWhenLocalRepositoryIsUpToDate(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
//given
GitConnection remoteConnection = connectToGitRepositoryWithContent(connectionFactory, repository);
GitConnection localConnection = connectionFactory.getConnection(remoteRepo.getAbsolutePath());
localConnection.clone(CloneParams.create(remoteConnection.getWorkingDir().getAbsolutePath()));
//when
PushResponse pushResponse = localConnection.push(PushParams.create("origin").withRefSpec(singletonList("refs/heads/master:refs/heads/master")).withTimeout(-1));
//then
assertEquals(pushResponse.getCommandOutput(), "Everything up-to-date");
}
use of org.eclipse.che.api.git.GitConnection in project che by eclipse.
the class PushTest method testWhenThereAreNoAnyRemotes.
@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class, expectedExceptions = GitException.class, expectedExceptionsMessageRegExp = "No remote repository specified. " + "Please, specify either a URL or a remote name from which new revisions should be fetched in request.")
public void testWhenThereAreNoAnyRemotes(GitConnectionFactory connectionFactory) throws Exception {
//given
GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
//when
connection.push(PushParams.create(null));
}
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());
}
Aggregations