Exemplo n.º 1
0
  @Test
  public void shareProjectWithExternalRepo() throws Exception {
    String repoName = "ExternalRepositoryForShare";
    createProject(projectName0);
    String location1 = createProject(projectName1);
    String location2 = createProject(projectName2);
    createProject(projectName3);

    ExistingOrNewPage existingOrNewPage = sharingWizard.openWizard(projectName1, projectName2);
    SWTBotShell createRepoDialog = existingOrNewPage.clickCreateRepository();
    String repoDir =
        Activator.getDefault().getPreferenceStore().getString(UIPreferences.DEFAULT_REPO_DIR);
    File repoFolder = new File(repoDir, repoName);
    createRepoDialog
        .bot()
        .textWithLabel(UIText.CreateRepositoryPage_DirectoryLabel)
        .setText(repoFolder.getAbsolutePath());
    createRepoDialog.bot().button(IDialogConstants.FINISH_LABEL).click();

    SWTBotCombo combo = bot.comboBoxWithLabel(UIText.ExistingOrNewPage_ExistingRepositoryLabel);
    assertTrue(combo.getText().startsWith(repoName));
    Repository targetRepo = lookupRepository(new File(repoFolder, Constants.DOT_GIT));

    assertTrue(combo.getText().endsWith(targetRepo.getDirectory().getPath()));
    assertEquals(
        targetRepo.getWorkTree().getPath(),
        bot.textWithLabel(UIText.ExistingOrNewPage_WorkingDirectoryLabel).getText());
    String[][] contents = new String[2][3];
    contents[0][0] = projectName1;
    contents[0][1] = new Path(location1).toString();
    contents[0][2] = new Path(targetRepo.getWorkTree().getPath()).append(projectName1).toString();

    contents[1][0] = projectName2;
    contents[1][1] = new Path(location2).toString();
    contents[1][2] = new Path(targetRepo.getWorkTree().getPath()).append(projectName2).toString();
    existingOrNewPage.assertTableContents(contents);

    existingOrNewPage.setRelativePath("a/b");

    contents[0][2] =
        new Path(targetRepo.getWorkTree().getPath()).append("a/b").append(projectName1).toString();
    contents[1][2] =
        new Path(targetRepo.getWorkTree().getPath()).append("a/b").append(projectName2).toString();
    existingOrNewPage.assertTableContents(contents);

    bot.button(IDialogConstants.FINISH_LABEL).click();
    Thread.sleep(1000);
    String location1Path =
        ResourcesPlugin.getWorkspace().getRoot().getProject(projectName1).getLocation().toString();
    assertEquals(contents[0][2], location1Path);
    String location2Path =
        ResourcesPlugin.getWorkspace().getRoot().getProject(projectName2).getLocation().toString();
    assertEquals(contents[1][2], location2Path);
  }
Exemplo n.º 2
0
 /**
  * Creates a test repository from an existing Repository
  *
  * @param repository
  * @throws IOException
  */
 public TestRepository(Repository repository) throws IOException {
   this.repository = repository;
   try {
     workdirPrefix = repository.getWorkTree().getCanonicalPath();
   } catch (IOException err) {
     workdirPrefix = repository.getWorkTree().getAbsolutePath();
   }
   workdirPrefix = workdirPrefix.replace('\\', '/');
   if (!workdirPrefix.endsWith("/")) // $NON-NLS-1$
   workdirPrefix += "/"; // $NON-NLS-1$
 }
  @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();
  }
Exemplo n.º 4
0
 /**
  * Creates a new test repository
  *
  * @param gitDir
  * @throws IOException
  */
 public TestRepository(File gitDir) throws IOException {
   repository = new FileRepository(gitDir);
   repository.create();
   try {
     workdirPrefix = repository.getWorkTree().getCanonicalPath();
   } catch (IOException err) {
     workdirPrefix = repository.getWorkTree().getAbsolutePath();
   }
   workdirPrefix = workdirPrefix.replace('\\', '/');
   if (!workdirPrefix.endsWith("/")) // $NON-NLS-1$
   workdirPrefix += "/"; // $NON-NLS-1$
 }
Exemplo n.º 5
0
  private boolean handleDelete(
      HttpServletRequest request, HttpServletResponse response, String pathString)
      throws GitAPIException, CoreException, IOException, ServletException {
    IPath path = pathString == null ? Path.EMPTY : new Path(pathString);
    // expected path format is /file/{workspaceId}/{projectId}[/{directoryPath}]
    if (path.segment(0).equals("file") && path.segmentCount() > 2) { // $NON-NLS-1$

      // make sure a clone is addressed
      WebProject webProject = GitUtils.projectFromPath(path);
      if (webProject != null && isAccessAllowed(request.getRemoteUser(), webProject)) {
        File gitDir = GitUtils.getGitDirs(path, Traverse.CURRENT).values().iterator().next();
        Repository repo = new FileRepository(gitDir);
        repo.close();
        FileUtils.delete(repo.getWorkTree(), FileUtils.RECURSIVE | FileUtils.RETRY);
        if (path.segmentCount() == 3)
          return statusHandler.handleRequest(
              request, response, removeProject(request.getRemoteUser(), webProject));
        return true;
      }
      String msg = NLS.bind("Nothing found for the given ID: {0}", path);
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null));
    }
    String msg = NLS.bind("Invalid delete request {0}", pathString);
    return statusHandler.handleRequest(
        request,
        response,
        new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
  }
Exemplo n.º 6
0
 /**
  * Do the copy file action.
  *
  * @throws IOException
  */
 public void copy() throws IOException {
   File srcFile = new File(repo.getWorkTree(), path + "/" + src); // $NON-NLS-1$
   File destFile = new File(repo.getWorkTree(), dest);
   FileInputStream input = new FileInputStream(srcFile);
   try {
     FileOutputStream output = new FileOutputStream(destFile);
     try {
       FileChannel channel = input.getChannel();
       output.getChannel().transferFrom(channel, 0, channel.size());
     } finally {
       output.close();
     }
   } finally {
     input.close();
   }
 }
Exemplo n.º 7
0
 /**
  * Retrieves a collection of files that may be committed based on the user's selection when they
  * performed the commit action. That is, even if the user only selected one folder when the action
  * was performed, if the folder contains any files that could be committed, they will be returned.
  *
  * @return a collection of files that is eligible to be committed based on the user's selection
  */
 private Set<String> getSelectedFiles() {
   Set<String> preselectionCandidates = new LinkedHashSet<String>();
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   // iterate through all the files that may be committed
   for (String fileName : files) {
     URI uri = new File(repo.getWorkTree(), fileName).toURI();
     IFile[] workspaceFiles = root.findFilesForLocationURI(uri);
     if (workspaceFiles.length > 0) {
       IFile file = workspaceFiles[0];
       for (IResource resource : selectedResources) {
         // if any selected resource contains the file, add it as a
         // preselection candidate
         if (resource.contains(file)) {
           preselectionCandidates.add(fileName);
           break;
         }
       }
     } else {
       // could be file outside of workspace
       for (IResource resource : selectedResources) {
         if (resource.getFullPath().toFile().equals(new File(uri))) {
           preselectionCandidates.add(fileName);
         }
       }
     }
   }
   return preselectionCandidates;
 }
Exemplo n.º 8
0
  @Override
  public void open(String repositoryPath) {

    FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
    try {
      repository =
          repositoryBuilder
              .setGitDir(new File(repositoryPath))
              .readEnvironment() // read git environment variables
              .findGitDir()
              .build();
    } catch (IOException e) {
      throw new VisMinerAPIException(e.getMessage(), e);
    }

    git = new Git(repository);
    revWalk = new RevWalk(repository);
    treeWalk = new TreeWalk(repository);
    reader = repository.newObjectReader();

    processBuilder = new ProcessBuilder();
    processBuilder.directory(new File(repository.getDirectory().toString()));

    commands = Arrays.asList("git", "log", "--numstat", "--oneline", "--max-count=1", "");

    this.repositoryPath = repository.getWorkTree().getAbsolutePath();
  }
Exemplo n.º 9
0
 @Override
 public void close() throws IOException {
   File tempDir = null;
   synchronized (this) {
     if (checkedOut != null) tempDir = checkedOut.getWorkTree();
   }
   if (tempDir != null) IO.delete(tempDir);
 }
Exemplo n.º 10
0
 /**
  * This method implements how to handle conflicts when {@link #failOnConflict} is false
  *
  * @throws CheckoutConflictException
  */
 private void cleanUpConflicts() throws CheckoutConflictException {
   // TODO: couldn't we delete unsaved worktree content here?
   for (String c : conflicts) {
     File conflict = new File(repo.getWorkTree(), c);
     if (!conflict.delete())
       throw new CheckoutConflictException(
           MessageFormat.format(JGitText.get().cannotDeleteFile, c));
     removeEmptyParents(conflict);
   }
   for (String r : removed) {
     File file = new File(repo.getWorkTree(), r);
     if (!file.delete())
       throw new CheckoutConflictException(
           MessageFormat.format(JGitText.get().cannotDeleteFile, file.getAbsolutePath()));
     removeEmptyParents(file);
   }
 }
Exemplo n.º 11
0
  private void removeEmptyParents(File f) {
    File parentFile = f.getParentFile();

    while (!parentFile.equals(repo.getWorkTree())) {
      if (!parentFile.delete()) break;
      parentFile = parentFile.getParentFile();
    }
  }
Exemplo n.º 12
0
  @SuppressWarnings("resource" /* java 7 */)
  @Test
  public void relativeGitDirRef() throws Exception {
    Repository repo1 = createWorkRepository();
    File dir = new File(repo1.getWorkTree(), "dir");
    assertTrue(dir.mkdir());
    File dotGit = new File(dir, Constants.DOT_GIT);
    new FileWriter(dotGit).append("gitdir: ../" + Constants.DOT_GIT).close();

    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    builder.setWorkTree(dir);
    builder.setMustExist(true);
    Repository repo2 = builder.build();

    assertEquals(repo1.getDirectory(), repo2.getDirectory());
    assertEquals(dir, repo2.getWorkTree());
  }
Exemplo n.º 13
0
 /**
  * create an initial commit containing a file "dummy" in the
  *
  * @param message commit message
  * @return commit object
  * @throws IOException
  * @throws NoHeadException
  * @throws NoMessageException
  * @throws ConcurrentRefUpdateException
  * @throws JGitInternalException
  * @throws WrongRepositoryStateException
  */
 public RevCommit createInitialCommit(String message)
     throws IOException, NoHeadException, NoMessageException, ConcurrentRefUpdateException,
         JGitInternalException, WrongRepositoryStateException {
   String repoPath = repository.getWorkTree().getAbsolutePath();
   File file = new File(repoPath, "dummy");
   file.createNewFile();
   track(file);
   return commit(message);
 }
Exemplo n.º 14
0
  // Paths we feed to Git should be relative to the git repo. Absolute paths are not appreciated.
  private String getPath(File file, Repository repository) {
    String workTreePath = repository.getWorkTree().getAbsolutePath();
    String pagePath = file.getAbsolutePath();

    assert pagePath.startsWith(workTreePath);

    // Add 1 for trailing '/' (not included in abs. path)
    pagePath = pagePath.substring(workTreePath.length() + 1);
    // git stores paths unix-style
    pagePath = pagePath.replace(File.separatorChar, '/');
    return pagePath;
  }
Exemplo n.º 15
0
  @Override
  public ResourceMap generateOutputs(Map<String, List<Object>> parameters, IProgressMonitor monitor)
      throws Exception {
    File workingDir = null;
    File gitDir = null;

    // Get existing checkout if available
    synchronized (this) {
      if (checkedOut != null) {
        workingDir = checkedOut.getWorkTree();
        gitDir = new File(workingDir, ".git");
      }
    }

    if (workingDir == null) {
      // Need to do a new checkout
      workingDir = Files.createTempDirectory("checkout").toFile();
      gitDir = new File(workingDir, ".git");
      String branch = params.branch != null ? params.branch : GitCloneTemplateParams.DEFAULT_BRANCH;

      try {
        CloneCommand cloneCmd =
            Git.cloneRepository()
                .setURI(params.cloneUrl)
                .setDirectory(workingDir)
                .setNoCheckout(true);
        cloneCmd.setProgressMonitor(new EclipseGitProgressTransformer(monitor));
        cloneCmd.setBranchesToClone(Collections.singleton(branch));
        Git git = cloneCmd.call();

        git.checkout().setCreateBranch(true).setName("_tmp").setStartPoint(branch).call();
        checkedOut = git.getRepository();
      } catch (JGitInternalException e) {
        Throwable cause = e.getCause();
        if (cause instanceof Exception) throw (Exception) cause;
        throw e;
      }
    }

    final File exclude = gitDir;
    FileFilter filter =
        new FileFilter() {
          @Override
          public boolean accept(File path) {
            return !path.equals(exclude);
          }
        };
    return toResourceMap(workingDir, filter);
  }
  @SuppressWarnings("unchecked")
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    rootNodes.clear();

    input = (List<String>) newInput;
    if (input == null) return;

    VirtualNode virtualNode = new VirtualNode();
    Node parentNode = virtualNode;
    NoResourceNode noResourceNode = null;

    IPath repositoryRoot = new Path(repository.getWorkTree().getAbsolutePath());

    for (String pathString : input) {
      IPath path;
      if (mode == Mode.FULL_PATHS) path = repositoryRoot.append(pathString);
      else if (mode == Mode.RESOURCE_PATHS)
        path = resolveResourcePath(repositoryRoot.append(pathString));
      else path = new Path(pathString);
      if (path == null) {
        path = repositoryRoot.append(pathString);
        if (noResourceNode == null) {
          noResourceNode =
              new NoResourceNode(
                  virtualNode, UIText.FileTreeContentProvider_NonWorkspaceResourcesNode);
        }
        parentNode = noResourceNode;
      } else parentNode = virtualNode;
      for (int i = 0; i < path.segmentCount(); i++) {
        String segment = path.segment(i);
        Node foundNode = null;
        for (Node node : parentNode.getChildren()) {
          if (node.getName().equals(segment)) {
            foundNode = node;
            break;
          }
        }
        if (foundNode == null) {
          if (i < path.segmentCount() - 1) parentNode = new FolderNode(parentNode, segment);
          else new FileNode(parentNode, segment);
        } else {
          parentNode = foundNode;
        }
      }
    }

    rootNodes.addAll(virtualNode.getChildren());
  }
Exemplo n.º 17
0
 /**
  * Checks the first level of the working directory
  *
  * @throws Exception
  */
 @Test
 public void testExpandWorkDir() throws Exception {
   SWTBotTree tree = getOrOpenView().bot().tree();
   Repository myRepository = lookupRepository(repositoryFile);
   List<String> children = Arrays.asList(myRepository.getWorkTree().list());
   List<String> treeChildren =
       myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand().getNodes();
   assertTrue(children.containsAll(treeChildren) && treeChildren.containsAll(children));
   myRepoViewUtil
       .getWorkdirItem(tree, repositoryFile)
       .expand()
       .getNode(PROJ1)
       .expand()
       .getNode(FOLDER)
       .expand()
       .getNode(FILE1);
 }
Exemplo n.º 18
0
  @SuppressWarnings("resource" /* java 7 */)
  @Test
  public void scanWithGitDirRef() throws Exception {
    Repository repo1 = createWorkRepository();
    File dir = createTempDirectory("dir");
    File dotGit = new File(dir, Constants.DOT_GIT);
    new FileWriter(dotGit).append("gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
    FileRepositoryBuilder builder = new FileRepositoryBuilder();

    builder.setWorkTree(dir);
    builder.findGitDir(dir);
    assertEquals(repo1.getDirectory(), builder.getGitDir());
    builder.setMustExist(true);
    Repository repo2 = builder.build();

    assertEquals(repo1.getDirectory(), repo2.getDirectory());
    assertEquals(dir, repo2.getWorkTree());
  }
Exemplo n.º 19
0
 private void fillTreeItemWithGitDirectory(
     RepositoryMapping m, TreeItem treeItem, boolean isAlternative) {
   if (m.getGitDir() == null)
     treeItem.setText(2, UIText.ExistingOrNewPage_SymbolicValueEmptyMapping);
   else {
     IPath relativePath = new Path(m.getGitDir());
     if (isAlternative) {
       IPath withoutLastSegment = relativePath.removeLastSegments(1);
       IPath path;
       if (withoutLastSegment.isEmpty()) path = Path.fromPortableString("."); // $NON-NLS-1$
       else path = withoutLastSegment;
       treeItem.setText(0, path.toString());
     }
     treeItem.setText(2, relativePath.toOSString());
     try {
       IProject project = m.getContainer().getProject();
       Repository repo =
           new RepositoryBuilder().setGitDir(m.getGitDirAbsolutePath().toFile()).build();
       File workTree = repo.getWorkTree();
       IPath workTreePath = Path.fromOSString(workTree.getAbsolutePath());
       if (workTreePath.isPrefixOf(project.getLocation())) {
         IPath makeRelativeTo = project.getLocation().makeRelativeTo(workTreePath);
         String repoRelativePath =
             makeRelativeTo.append("/.project").toPortableString(); // $NON-NLS-1$
         ObjectId headCommitId = repo.resolve(Constants.HEAD);
         if (headCommitId != null) {
           // Not an empty repo
           RevWalk revWalk = new RevWalk(repo);
           RevCommit headCommit = revWalk.parseCommit(headCommitId);
           RevTree headTree = headCommit.getTree();
           TreeWalk projectInRepo = TreeWalk.forPath(repo, repoRelativePath, headTree);
           if (projectInRepo != null) {
             // the .project file is tracked by this repo
             treeItem.setChecked(true);
           }
           revWalk.dispose();
         }
       }
       repo.close();
     } catch (IOException e1) {
       Activator.logError(UIText.ExistingOrNewPage_FailedToDetectRepositoryMessage, e1);
     }
   }
 }
Exemplo n.º 20
0
  /**
   * @param checked pass true to get the checked elements, false to get the selected elements
   * @return map between project and repository root directory (converted to an absolute path) for
   *     all projects selected by user
   */
  public Map<IProject, File> getProjects(boolean checked) {
    final Object[] elements;
    if (!internalMode)
      if (checked) elements = projectMoveViewer.getCheckedElements();
      else {
        ISelection selection = viewer.getSelection();
        elements = ((IStructuredSelection) selection).toArray();
      }
    else if (checked) elements = viewer.getCheckedElements();
    else {
      ISelection selection = viewer.getSelection();
      if (selection instanceof IStructuredSelection)
        elements = ((IStructuredSelection) selection).toArray();
      else elements = new Object[0];
    }

    Map<IProject, File> ret = new HashMap<IProject, File>(elements.length);
    for (Object ti : elements) {
      if (!internalMode) {
        File workdir = selectedRepository.getWorkTree();
        IProject project = (IProject) ti;
        IPath targetLocation = new Path(relPath.getText()).append(project.getName());
        File targetFile = new File(workdir, targetLocation.toOSString());
        ret.put(project, targetFile);

      } else {
        final IProject project = ((ProjectAndRepo) ti).getProject();
        String path = ((ProjectAndRepo) ti).getRepo();
        final IPath selectedRepo = Path.fromOSString(path);
        IPath localPathToRepo = selectedRepo;
        if (!selectedRepo.isAbsolute()) {
          localPathToRepo = project.getLocation().append(selectedRepo);
        }
        ret.put(project, localPathToRepo.toFile());
      }
    }
    return ret;
  }
Exemplo n.º 21
0
  private boolean doCheckout()
      throws CorruptObjectException, IOException, MissingObjectException,
          IncorrectObjectTypeException, CheckoutConflictException, IndexWriteException {
    toBeDeleted.clear();

    ObjectReader objectReader = repo.getObjectDatabase().newReader();
    try {
      if (headCommitTree != null) preScanTwoTrees();
      else prescanOneTree();

      if (!conflicts.isEmpty()) {
        if (failOnConflict)
          throw new CheckoutConflictException(conflicts.toArray(new String[conflicts.size()]));
        else cleanUpConflicts();
      }

      // update our index
      builder.finish();

      File file = null;
      String last = ""; // $NON-NLS-1$
      // when deleting files process them in the opposite order as they have
      // been reported. This ensures the files are deleted before we delete
      // their parent folders
      for (int i = removed.size() - 1; i >= 0; i--) {
        String r = removed.get(i);
        file = new File(repo.getWorkTree(), r);
        if (!file.delete() && file.exists()) {
          // The list of stuff to delete comes from the index
          // which will only contain a directory if it is
          // a submodule, in which case we shall not attempt
          // to delete it. A submodule is not empty, so it
          // is safe to check this after a failed delete.
          if (!file.isDirectory()) toBeDeleted.add(r);
        } else {
          if (!isSamePrefix(r, last)) removeEmptyParents(new File(repo.getWorkTree(), last));
          last = r;
        }
      }
      if (file != null) removeEmptyParents(file);

      for (String path : updated.keySet()) {
        // ... create/overwrite this file ...
        file = new File(repo.getWorkTree(), path);
        if (!file.getParentFile().mkdirs()) {
          // ignore
        }

        DirCacheEntry entry = dc.getEntry(path);

        // submodules are handled with separate operations
        if (FileMode.GITLINK.equals(entry.getRawMode())) continue;

        checkoutEntry(repo, file, entry, objectReader);
      }

      // commit the index builder - a new index is persisted
      if (!builder.commit()) throw new IndexWriteException();
    } finally {
      objectReader.release();
    }
    return toBeDeleted.size() == 0;
  }
Exemplo n.º 22
0
  protected void updateControls() {
    setMessage(null);
    setErrorMessage(null);
    if (!internalMode) {
      setDescription(UIText.ExistingOrNewPage_DescriptionExternalMode);
      if (this.selectedRepository != null) {
        workDir.setText(this.selectedRepository.getWorkTree().getPath());
        String relativePath = relPath.getText();
        File testFile = new File(this.selectedRepository.getWorkTree(), relativePath);
        if (!testFile.exists())
          setMessage(
              NLS.bind(UIText.ExistingOrNewPage_FolderWillBeCreatedMessage, relativePath),
              IMessageProvider.WARNING);
        IPath targetPath = new Path(selectedRepository.getWorkTree().getPath());
        targetPath = targetPath.append(relPath.getText());
        moveProjectsLabelProvider.targetFolder = targetPath;
        projectMoveViewer.refresh(true);
        browseRepository.setEnabled(true);
        for (Object checked : projectMoveViewer.getCheckedElements()) {
          IProject prj = (IProject) checked;
          IPath projectMoveTarget = targetPath.append(prj.getName());
          boolean mustMove = !prj.getLocation().equals(projectMoveTarget);
          File targetTest = new File(projectMoveTarget.toOSString());
          if (mustMove && targetTest.exists()) {
            setErrorMessage(
                NLS.bind(UIText.ExistingOrNewPage_ExistingTargetErrorMessage, prj.getName()));
            break;
          }
          File parent = targetTest.getParentFile();
          while (parent != null) {
            if (new File(parent, ".project").exists()) { // $NON-NLS-1$
              setErrorMessage(
                  NLS.bind(
                      UIText.ExistingOrNewPage_NestedProjectErrorMessage,
                      new String[] {prj.getName(), targetTest.getPath(), parent.getPath()}));
              break;
            }
            parent = parent.getParentFile();
          }
          // break after the first error
          if (getErrorMessage() != null) break;
        }
      } else workDir.setText(UIText.ExistingOrNewPage_NoRepositorySelectedMessage);
      setPageComplete(
          getErrorMessage() == null
              && selectedRepository != null
              && projectMoveViewer.getCheckedElements().length > 0);
    } else {
      setDescription(UIText.ExistingOrNewPage_description);
      IPath p = proposeNewRepositoryPath(tree.getSelection());
      minumumPath = p;
      if (p != null) {
        repositoryToCreate.setText(p.toOSString());
      } else {
        repositoryToCreate.setText(""); // $NON-NLS-1$
      }
      createRepo.setEnabled(p != null);
      repositoryToCreate.setEnabled(p != null);
      dotGitSegment.setEnabled(p != null);

      boolean pageComplete = viewer.getCheckedElements().length > 0;
      for (Object checkedElement : viewer.getCheckedElements()) {
        String path = ((ProjectAndRepo) checkedElement).getRepo();
        if (((ProjectAndRepo) checkedElement).getRepo() != null && path.equals("")) { // $NON-NLS-1$
          pageComplete = false;
        }
      }
      setPageComplete(pageComplete);
      // provide a warning if Repository is created in workspace
      for (IProject project : myWizard.projects) {
        if (createRepo.isEnabled()
            && ResourcesPlugin.getWorkspace()
                .getRoot()
                .getLocation()
                .isPrefixOf(project.getLocation())) {
          setMessage(
              UIText.ExistingOrNewPage_RepoCreationInWorkspaceCreationWarning,
              IMessageProvider.WARNING);
          break;
        }
      }
    }

    externalComposite.setVisible(!internalMode);
    parentRepoComposite.setVisible(internalMode);
    GridData gd;
    gd = (GridData) parentRepoComposite.getLayoutData();
    gd.exclude = !internalMode;

    gd = (GridData) externalComposite.getLayoutData();
    gd.exclude = internalMode;

    ((Composite) getControl()).layout(true);
  }
 // TODO: move to utils
 private IFile findFile(String path) {
   URI uri = new File(repository.getWorkTree(), path).toURI();
   IFile[] workspaceFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri);
   if (workspaceFiles.length > 0) return workspaceFiles[0];
   else return null;
 }