@Before
  public void setUp() throws Exception {

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    FileUtils.mkdir(new File(root.getLocation().toFile(), "Sub"), true);
    gitDir = new File(new File(root.getLocation().toFile(), "Sub"), Constants.DOT_GIT);

    repository = FileRepositoryBuilder.create(gitDir);
    repository.create();

    project = root.getProject(TEST_PROJECT);
    project.create(null);
    project.open(null);
    IProjectDescription description = project.getDescription();
    description.setLocation(root.getLocation().append(TEST_PROJECT_LOC));
    project.move(description, IResource.FORCE, null);

    project2 = root.getProject(TEST_PROJECT2);
    project2.create(null);
    project2.open(null);
    gitDir2 = new File(project2.getLocation().toFile().getAbsoluteFile(), Constants.DOT_GIT);
    repository2 = FileRepositoryBuilder.create(gitDir2);
    repository2.create();

    RepositoryMapping mapping = RepositoryMapping.create(project, gitDir);
    RepositoryMapping mapping2 = RepositoryMapping.create(project2, gitDir2);

    GitProjectData projectData = new GitProjectData(project);
    GitProjectData projectData2 = new GitProjectData(project2);
    projectData.setRepositoryMappings(Collections.singletonList(mapping));
    projectData.store();
    projectData2.setRepositoryMappings(Collections.singletonList(mapping2));
    projectData2.store();
    GitProjectData.add(project, projectData);
    GitProjectData.add(project2, projectData2);

    RepositoryProvider.map(project, GitProvider.class.getName());
    RepositoryProvider.map(project2, GitProvider.class.getName());

    JGitTestUtil.write(
        new File(repository.getWorkTree(), TEST_PROJECT + "/" + TEST_FILE), "Some data");
    JGitTestUtil.write(new File(repository2.getWorkTree(), TEST_FILE2), "Some other data");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    project2.refreshLocal(IResource.DEPTH_INFINITE, null);
    git = new Git(repository);
    git.add().addFilepattern(".").call();
    git.commit().setMessage("Initial commit").call();

    git = new Git(repository2);
    git.add().addFilepattern(".").call();
    git.commit().setMessage("Initial commit").call();
    git.branchRename().setNewName("main").call();
  }
Esempio n. 2
0
 @Test
 public void testRenameOverNonExistingFile() throws IOException {
   File d = new File(trash, "d");
   FileUtils.mkdirs(d);
   File f1 = new File(trash, "d/f");
   File f2 = new File(trash, "d/g");
   JGitTestUtil.write(f1, "f1");
   // test
   FileUtils.rename(f1, f2);
   assertFalse(f1.exists());
   assertTrue(f2.exists());
   assertEquals("f1", JGitTestUtil.read(f2));
 }
Esempio n. 3
0
 @Test
 public void testRenameOverExistingNonEmptyDirectory() throws IOException {
   File d = new File(trash, "d");
   FileUtils.mkdirs(d);
   File f1 = new File(trash, "d/f");
   File f2 = new File(trash, "d/g");
   File d1 = new File(trash, "d/g/h/i");
   File f3 = new File(trash, "d/g/h/f");
   FileUtils.mkdirs(d1);
   JGitTestUtil.write(f1, "f1");
   JGitTestUtil.write(f3, "f3");
   // test
   try {
     FileUtils.rename(f1, f2);
     fail("rename to non-empty directory should fail");
   } catch (IOException e) {
     assertEquals("f1", JGitTestUtil.read(f1)); // untouched source
     assertEquals("f3", JGitTestUtil.read(f3)); // untouched
     // empty directories within f2 may or may not have been deleted
   }
 }
 private static File pathOf(final String name) {
   return JGitTestUtil.getTestResourceFile(name);
 }
Esempio n. 5
0
 protected void deleteTrashFile(final String name) throws IOException {
   JGitTestUtil.deleteTrashFile(db, name);
 }
Esempio n. 6
0
 protected String read(final File file) throws IOException {
   return JGitTestUtil.read(file);
 }
Esempio n. 7
0
 protected File writeTrashFile(final String name, final String data) throws IOException {
   return JGitTestUtil.writeTrashFile(db, name, data);
 }
Esempio n. 8
0
 /**
  * @param link the path of the symbolic link to create
  * @param target the target of the symbolic link
  * @return the path to the symbolic link
  * @throws Exception
  */
 protected Path writeLink(String link, String target) throws Exception {
   return JGitTestUtil.writeLink(db, link, target);
 }