use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class CommitOperationTest method testCommitEmptiedTree.
@Test
public void testCommitEmptiedTree() throws Exception {
// Set up a directory structure
testUtils.addFileToProject(project.getProject(), "sub1/a.txt", "some text");
testUtils.addFileToProject(project.getProject(), "sub2/b.txt", "some text");
resources.add(project.getProject().getFolder("sub1"));
resources.add(project.getProject().getFolder("sub2"));
new AddToIndexOperation(resources).execute(null);
CommitOperation commitOperation = new CommitOperation(null, null, TestUtils.AUTHOR, TestUtils.COMMITTER, "first commit");
commitOperation.setCommitAll(true);
commitOperation.setRepository(repository);
commitOperation.execute(null);
Iterator<RevCommit> commits;
try (Git git = new Git(repository)) {
commits = git.log().call().iterator();
}
RevCommit secondCommit = commits.next();
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(secondCommit.getTree().getId());
treeWalk.setRecursive(true);
treeWalk.setPostOrderTraversal(true);
assertTrue(treeWalk.next());
assertEquals("sub1/a.txt", treeWalk.getPathString());
assertTrue(treeWalk.next());
assertEquals("sub1", treeWalk.getPathString());
assertTrue(treeWalk.next());
assertEquals("sub2/b.txt", treeWalk.getPathString());
assertTrue(treeWalk.next());
assertEquals("sub2", treeWalk.getPathString());
assertFalse(treeWalk.next());
}
project.getProject().getFolder("sub2").delete(IResource.FORCE, null);
IFile[] filesToCommit = { project.getProject().getFile("sub2/b.txt") };
ArrayList<IFile> notIndexed = new ArrayList<IFile>();
notIndexed.add(filesToCommit[0]);
ArrayList<IFile> notTracked = new ArrayList<IFile>();
commitOperation = new CommitOperation(filesToCommit, notTracked, TestUtils.AUTHOR, TestUtils.COMMITTER, "second commit");
commitOperation.setCommitAll(false);
commitOperation.execute(null);
try (Git git = new Git(repository)) {
commits = git.log().call().iterator();
}
secondCommit = commits.next();
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(secondCommit.getTree().getId());
treeWalk.setRecursive(true);
treeWalk.setPostOrderTraversal(true);
assertTrue(treeWalk.next());
assertEquals("sub1/a.txt", treeWalk.getPathString());
assertTrue(treeWalk.next());
assertEquals("sub1", treeWalk.getPathString());
assertFalse(treeWalk.next());
}
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class CommitOperationTest method testCommitAll.
@Test
public void testCommitAll() throws Exception {
IFile file1 = testUtils.addFileToProject(project.getProject(), "sub/a.txt", "some text");
testUtils.addFileToProject(project.getProject(), "sub/b.txt", "some text");
resources.add(project.getProject().getFolder("sub"));
new AddToIndexOperation(resources).execute(null);
CommitOperation commitOperation = new CommitOperation(null, null, TestUtils.AUTHOR, TestUtils.COMMITTER, "first commit");
commitOperation.setCommitAll(true);
commitOperation.setRepository(repository);
commitOperation.execute(null);
Iterator<RevCommit> commits;
try (Git git = new Git(repository)) {
commits = git.log().call().iterator();
}
RevCommit firstCommit = commits.next();
assertTrue(firstCommit.getCommitTime() > 0);
assertEquals("first commit", firstCommit.getFullMessage());
testUtils.changeContentOfFile(project.getProject(), file1, "changed text");
commitOperation = new CommitOperation(null, null, TestUtils.AUTHOR, TestUtils.COMMITTER, "second commit");
commitOperation.setCommitAll(true);
commitOperation.setRepository(repository);
commitOperation.execute(null);
try (Git git = new Git(repository)) {
commits = git.log().call().iterator();
}
RevCommit secondCommit = commits.next();
assertTrue(secondCommit.getCommitTime() > 0);
assertEquals("second commit", secondCommit.getFullMessage());
secondCommit.getParent(0).equals(firstCommit);
assertEquals("The Author", secondCommit.getAuthorIdent().getName());
assertEquals("The.author@some.com", secondCommit.getAuthorIdent().getEmailAddress());
assertEquals("The Commiter", secondCommit.getCommitterIdent().getName());
assertEquals("The.committer@some.com", secondCommit.getCommitterIdent().getEmailAddress());
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class CommitOperationTest method testCommitStaged.
@Test
public void testCommitStaged() throws Exception {
IFile fileA = testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
IFile fileB = testUtils.addFileToProject(project.getProject(), "foo/b.txt", "some text");
IFile[] filesToCommit = { fileA, fileB };
CommitOperation commitOperation = new CommitOperation(filesToCommit, Arrays.asList(filesToCommit), TestUtils.AUTHOR, TestUtils.COMMITTER, "first commit");
commitOperation.execute(null);
testUtils.changeContentOfFile(project.getProject(), fileA, "new content of A");
testUtils.changeContentOfFile(project.getProject(), fileB, "new content of B");
resources.add(fileA);
resources.add(fileB);
new AddToIndexOperation(resources).execute(null);
commitOperation = new CommitOperation(filesToCommit, EMPTY_FILE_LIST, TestUtils.AUTHOR, TestUtils.COMMITTER, "second commit");
commitOperation.execute(null);
testUtils.assertRepositoryContainsFilesWithContent(repository, "foo/a.txt", "new content of A", "foo/b.txt", "new content of B");
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class PushOperationTest method testPush.
/**
* Push from repository1 "master" into "test" of repository2.
*
* @throws Exception
*/
@Test
public void testPush() throws Exception {
// push from repository1 to repository2
PushOperation pop = createPushOperation();
pop.run(new NullProgressMonitor());
assertEquals(Status.UP_TO_DATE, getStatus(pop.getOperationResult()));
// let's add a new file to the project shared with repository1
IProject proj = importProject(repository1, projectName);
ArrayList<IFile> files = new ArrayList<IFile>();
IFile newFile = testUtils.addFileToProject(proj, "folder2/file2.txt", "New file");
files.add(newFile);
IFile[] fileArr = files.toArray(new IFile[files.size()]);
AddToIndexOperation trop = new AddToIndexOperation(files);
trop.execute(null);
CommitOperation cop = new CommitOperation(fileArr, files, TestUtils.AUTHOR, TestUtils.COMMITTER, "Added file");
cop.execute(null);
proj.delete(false, false, null);
pop = createPushOperation();
pop.run(null);
assertEquals(Status.OK, getStatus(pop.getOperationResult()));
try {
// assert that we cannot run this again
pop.run(null);
fail("Expected Exception not thrown");
} catch (IllegalStateException e) {
// expected
}
pop = createPushOperation();
pop.run(null);
assertEquals(Status.UP_TO_DATE, getStatus(pop.getOperationResult()));
String newFilePath = newFile.getFullPath().toOSString();
File testFile = new File(workdir2, newFilePath);
assertFalse(testFile.exists());
testFile = new File(workdir, newFilePath);
assertTrue(testFile.exists());
// check out test and verify the file is there
BranchOperation bop = new BranchOperation(repository2.getRepository(), "refs/heads/test");
bop.execute(null);
testFile = new File(workdir2, newFilePath);
assertTrue(testFile.exists());
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class RemoveFromIndexOperationTest method shouldUnTrackFilesInFolder.
@Test
public void shouldUnTrackFilesInFolder() throws Exception {
// given
IFile file1 = createFileInRepo("sub/a.txt");
IFile file2 = createFileInRepo("sub/b.txt");
IFolder container = project.getProject().getFolder("sub");
new AddToIndexOperation(asList(file1, file2)).execute(null);
// when
new RemoveFromIndexOperation(asList(container.getLocation())).execute(null);
// then
assertTrue(testRepo.removedFromIndex(file1.getLocation().toPortableString()));
assertTrue(testRepo.removedFromIndex(file2.getLocation().toPortableString()));
}
Aggregations