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