use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class AddOperationTest method testAddFilesInFolder.
@Test
public void testAddFilesInFolder() throws Exception {
IFile file1 = testUtils.addFileToProject(project.getProject(), "sub/a.txt", "some text");
IFile file2 = testUtils.addFileToProject(project.getProject(), "sub/b.txt", "some text");
resources.add(project.getProject().getFolder("sub"));
new AddToIndexOperation(resources).execute(null);
testRepository.commit("first commit");
assertEquals(file1.getLocalTimeStamp() / 1000, testRepository.lastModifiedInIndex(file1.getLocation().toPortableString()) / 1000);
Thread.sleep(1000);
file1.setContents(new ByteArrayInputStream("other text".getBytes(project.project.getDefaultCharset())), 0, null);
file2.setContents(new ByteArrayInputStream("other text".getBytes(project.project.getDefaultCharset())), 0, null);
assertFalse(file1.getLocalTimeStamp() == testRepository.lastModifiedInIndex(file1.getLocation().toPortableString()));
assertFalse(file2.getLocalTimeStamp() == testRepository.lastModifiedInIndex(file1.getLocation().toPortableString()));
new AddToIndexOperation(resources).execute(null);
assertTrue(testRepository.inIndex(file1.getLocation().toPortableString()));
assertTrue(testRepository.inIndex(file2.getLocation().toPortableString()));
assertEquals(file1.getLocalTimeStamp() / 1000, testRepository.lastModifiedInIndex(file1.getLocation().toPortableString()) / 1000);
assertEquals(file2.getLocalTimeStamp() / 1000, testRepository.lastModifiedInIndex(file2.getLocation().toPortableString()) / 1000);
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class AddOperationTest method testAddFile.
@Test
public void testAddFile() throws Exception {
IFile file1 = testUtils.addFileToProject(project.getProject(), "a.txt", "some text");
resources.add(file1);
new AddToIndexOperation(resources).execute(null);
testRepository.commit("first commit");
assertEquals(file1.getLocalTimeStamp() / 1000, testRepository.lastModifiedInIndex(file1.getLocation().toPortableString()) / 1000);
Thread.sleep(1000);
file1.setContents(new ByteArrayInputStream("other text".getBytes(project.project.getDefaultCharset())), 0, null);
assertFalse(file1.getLocalTimeStamp() / 1000 == testRepository.lastModifiedInIndex(file1.getLocation().toPortableString()) / 1000);
new AddToIndexOperation(resources).execute(null);
assertTrue(testRepository.inIndex(file1.getLocation().toPortableString()));
// does not work yet due to the racy git problem: DirCache.writeTo
// smudges the
// timestamp of an added file
assertEquals(file1.getLocalTimeStamp() / 1000, testRepository.lastModifiedInIndex(file1.getLocation().toPortableString()) / 1000);
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class LocalRepositoryTestCase method stage.
protected static void stage(IFile file) throws Exception {
ArrayList<IFile> unstaged = new ArrayList<IFile>();
unstaged.addAll(Arrays.asList(new IFile[] { file }));
AddToIndexOperation op = new AddToIndexOperation(unstaged);
op.execute(null);
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class GitMoveDeleteHookTest method testMoveFolder.
/**
* Rename "folder" to "dir".
* @param autoStageMoves
* @throws Exception
*/
@Theory
public void testMoveFolder(boolean autoStageMoves) throws Exception {
configureAutoStageMoves(autoStageMoves);
TestProject project = initRepoInsideProjectInsideWorkspace();
testUtils.addFileToProject(project.getProject(), "folder/file.txt", "some text");
testUtils.addFileToProject(project.getProject(), "folder2/file.txt", "some other text");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("folder/file.txt"), project.getProject().getFile("folder2/file.txt") });
addToIndexOperation.execute(null);
DirCache dirCache = DirCache.read(repository.getIndexFile(), FS.DETECTED);
assertNotNull(dirCache.getEntry("folder/file.txt"));
assertNotNull(dirCache.getEntry("folder2/file.txt"));
assertNull(dirCache.getEntry("dir/file.txt"));
assertFalse(project.getProject().getFile("dir/file.txt").exists());
ObjectId oldContentId = dirCache.getEntry("folder/file.txt").getObjectId();
// Modify the content before the move
testUtils.changeContentOfFile(project.getProject(), project.getProject().getFile("folder/file.txt"), "other text");
project.getProject().getFolder("folder").move(project.getProject().getFolder("dir").getFullPath(), false, null);
dirCache.read();
assertTrue(project.getProject().getFile("dir/file.txt").exists());
if (autoStageMoves) {
assertNull(dirCache.getEntry("folder/file.txt"));
assertNotNull(dirCache.getEntry("dir/file.txt"));
// Same content in index as before the move
assertEquals(oldContentId, dirCache.getEntry("dir/file.txt").getObjectId());
} else {
assertNotNull(dirCache.getEntry("folder/file.txt"));
assertNull(dirCache.getEntry("dir/file.txt"));
}
// Not moved file still there
assertNotNull(dirCache.getEntry("folder2/file.txt"));
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class GitMoveDeleteHookTest method testRenameProjectOutsideWorkspaceContainingGitRepo.
/**
* Rename a project outside the workspace containing a Git repository.
* <p>
* Note the similarity of the code with {@link #testMoveAndRenameProjectContainingGitRepo()}
*
* @throws Exception
*/
@Test
public void testRenameProjectOutsideWorkspaceContainingGitRepo() throws Exception {
ResourcesPlugin.getWorkspace().getRoot().getProject("Project-1").delete(true, null);
ResourcesPlugin.getWorkspace().getRoot().getProject("P2").delete(true, null);
TestProject project = initRepoInsideProjectOutsideWorkspace();
testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt") });
addToIndexOperation.execute(null);
IProjectDescription description = project.getProject().getDescription();
description.setName("P2");
project.getProject().move(description, IResource.FORCE | IResource.SHALLOW, null);
IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject("P2");
assertNotNull(RepositoryMapping.getMapping(project2.getProject()));
Repository movedRepo = RepositoryMapping.getMapping(project2).getRepository();
assertEquals("Project-1", movedRepo.getDirectory().getParentFile().getName());
DirCache dc = movedRepo.readDirCache();
assertEquals(1, dc.getEntryCount());
assertEquals("file.txt", dc.getEntry(0).getPathString());
assertFalse(ResourcesPlugin.getWorkspace().getRoot().getProject("Project-1").exists());
}
Aggregations