use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class GitMoveDeleteHookTest method testMoveFile.
@Theory
public void testMoveFile(boolean autoStageMoves) throws Exception {
configureAutoStageMoves(autoStageMoves);
TestProject project = initRepoInsideProjectInsideWorkspace();
testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
testUtils.addFileToProject(project.getProject(), "file2.txt", "some more text");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt"), project.getProject().getFile("file2.txt") });
addToIndexOperation.execute(null);
// Validate pre-conditions
DirCache dirCache = DirCache.read(repository.getIndexFile(), FS.DETECTED);
assertNotNull(dirCache.getEntry("file.txt"));
assertNotNull(dirCache.getEntry("file2.txt"));
assertNull(dirCache.getEntry("data.txt"));
assertFalse(project.getProject().getFile("data.txt").exists());
ObjectId oldContentId = dirCache.getEntry("file.txt").getObjectId();
// Modify the content before the move
testUtils.changeContentOfFile(project.getProject(), project.getProject().getFile("file.txt"), "other text");
project.getProject().getFile("file.txt").move(project.getProject().getFile("data.txt").getFullPath(), false, null);
dirCache.read();
assertTrue(project.getProject().getFile("data.txt").exists());
if (autoStageMoves) {
assertNotNull(dirCache.getEntry("data.txt"));
// Same content in index as before the move
assertEquals(oldContentId, dirCache.getEntry("data.txt").getObjectId());
} else {
assertNull(dirCache.getEntry("data.txt"));
}
// Not moved file still in its old place
assertNotNull(dirCache.getEntry("file2.txt"));
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class AddOperationTest method testTrackFilesInFolder.
@Test
public void testTrackFilesInFolder() throws Exception {
IFile file1 = testUtils.addFileToProject(project.getProject(), "sub/a.txt", "some text");
IFile file2 = testUtils.addFileToProject(project.getProject(), "sub/b.txt", "some text");
assertFalse(testRepository.inIndex(file1.getLocation().toPortableString()));
assertFalse(testRepository.inIndex(file2.getLocation().toPortableString()));
resources.add(project.getProject().getFolder("sub"));
new AddToIndexOperation(resources).execute(null);
assertTrue(testRepository.inIndex(file1.getLocation().toPortableString()));
assertTrue(testRepository.inIndex(file2.getLocation().toPortableString()));
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class AddOperationTest method testTrackFile.
@Test
public void testTrackFile() throws Exception {
IFile file1 = testUtils.addFileToProject(project.getProject(), "a.txt", "some text");
assertFalse(testRepository.inIndex(file1.getLocation().toPortableString()));
resources.add(file1);
new AddToIndexOperation(resources).execute(null);
assertTrue(testRepository.inIndex(file1.getLocation().toPortableString()));
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class CommitOperationTest method testCommitIndexSubset.
@Test
public void testCommitIndexSubset() 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);
IFile[] filesToCommit2 = { fileA };
commitOperation = new CommitOperation(filesToCommit2, 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", "some text");
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class CommitOperationTest method testCommitAddedToIndexDeletedInWorkspace.
@Test
public void testCommitAddedToIndexDeletedInWorkspace() throws Exception {
testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
resources.add(project.getProject().getFolder("foo"));
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);
testUtils.addFileToProject(project.getProject(), "zar/b.txt", "some text");
resources.add(project.getProject().getFolder("zar"));
new AddToIndexOperation(resources).execute(null);
IFile zarFile = project.getProject().getFile("zar/b.txt");
IPath zarFilePath = zarFile.getLocation();
// delete file and refresh. Deleting using the resource would trigger
// GitMoveDeleteHook which removes the file from the index
assertTrue("could not delete file " + zarFilePath.toOSString(), zarFilePath.toFile().delete());
zarFile.refreshLocal(0, null);
assertFalse(project.getProject().getFile("zar/b.txt").exists());
IFile[] filesToCommit = new IFile[] { project.getProject().getFile("zar/b.txt") };
commitOperation = new CommitOperation(filesToCommit, null, TestUtils.AUTHOR, TestUtils.COMMITTER, "first commit");
commitOperation.setRepository(repository);
try {
commitOperation.execute(null);
// TODO this is very ugly. CommitCommand should be extended
// not to throw an JGitInternalException in case of an empty
// commit
fail("expected CoreException");
} catch (CoreException e) {
assertEquals("No changes", e.getCause().getMessage());
}
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(repository.resolve("HEAD^{tree}"));
assertTrue(treeWalk.next());
assertEquals("foo", treeWalk.getPathString());
treeWalk.enterSubtree();
assertTrue(treeWalk.next());
assertEquals("foo/a.txt", treeWalk.getPathString());
assertFalse(treeWalk.next());
}
}
Aggregations