/**
  * Reads all remotes in a local repository's config and logs remote repository urls. Does this
  * only once per a NB session and repository
  *
  * @param repositoryRoot root of the local repository
  */
 @SuppressWarnings("unchecked")
 private void logRemoteRepositoryAccess(final File repositoryRoot) {
   if (loggedRepositories.add(repositoryRoot)) {
     Git.getInstance()
         .getRequestProcessor(repositoryRoot)
         .post(
             new Runnable() {
               @Override
               public void run() {
                 Set<String> urls = new HashSet<String>();
                 try {
                   GitClient client = Git.getInstance().getClient(repositoryRoot);
                   Map<String, GitRemoteConfig> cfgs =
                       client.getRemotes(GitUtils.NULL_PROGRESS_MONITOR);
                   for (Map.Entry<String, GitRemoteConfig> e : cfgs.entrySet()) {
                     GitRemoteConfig cfg = e.getValue();
                     for (List<String> uris : Arrays.asList(cfg.getUris(), cfg.getPushUris())) {
                       if (!uris.isEmpty()) {
                         urls.addAll(uris);
                       }
                     }
                   }
                 } catch (GitException ex) {
                   // not interested
                 }
                 for (String url : urls) {
                   if (!url.trim().isEmpty()) {
                     Utils.logVCSExternalRepository("GIT", url); // NOI18N
                   }
                 }
               }
             });
   }
 }
Example #2
0
 private static void refreshFS(final Collection<File> filesToRefresh) {
   Git.getInstance()
       .getRequestProcessor()
       .post(
           new Runnable() {
             @Override
             public void run() {
               FileUtil.refreshFor(filesToRefresh.toArray(new File[filesToRefresh.size()]));
             }
           },
           100);
 }
Example #3
0
 private boolean canCommit(File repository) {
   boolean commitPermitted = true;
   RepositoryInfo info = RepositoryInfo.getInstance(repository);
   GitRepositoryState state = info.getRepositoryState();
   if (!state.canCommit()) {
     commitPermitted = false;
     Map<File, GitStatus> conflicts = Collections.emptyMap();
     if (state.equals(GitRepositoryState.MERGING)) {
       try {
         GitClient client = Git.getInstance().getClient(repository);
         conflicts = client.getConflicts(new File[] {repository}, GitUtils.NULL_PROGRESS_MONITOR);
       } catch (GitException ex) {
         LOG.log(Level.INFO, null, ex);
       }
     }
     NotifyDescriptor nd;
     if (conflicts.isEmpty()) {
       nd =
           new NotifyDescriptor.Confirmation(
               NbBundle.getMessage(
                   CommitAction.class,
                   "LBL_CommitAction_CommitNotAllowed_State",
                   state.toString()), // NOI18N
               NbBundle.getMessage(CommitAction.class, "LBL_CommitAction_CannotCommit"),
               NotifyDescriptor.DEFAULT_OPTION,
               NotifyDescriptor.ERROR_MESSAGE); // NOI18N
     } else {
       nd =
           new NotifyDescriptor.Confirmation(
               NbBundle.getMessage(
                   CommitAction.class, "LBL_CommitAction_CommitNotAllowed_Conflicts"), // NOI18N
               NbBundle.getMessage(CommitAction.class, "LBL_CommitAction_CannotCommit"),
               NotifyDescriptor.YES_NO_OPTION,
               NotifyDescriptor.QUESTION_MESSAGE); // NOI18N
     }
     Object retval = DialogDisplayer.getDefault().notify(nd);
     if (retval == NotifyDescriptor.YES_OPTION) {
       GitUtils.openInVersioningView(
           conflicts.keySet(), repository, GitUtils.NULL_PROGRESS_MONITOR);
     }
   }
   return commitPermitted;
 }
Example #4
0
    @Override
    public void perform() {
      try {
        List<File> addCandidates = new LinkedList<File>();
        List<File> deleteCandidates = new LinkedList<File>();
        List<File> commitCandidates = new LinkedList<File>();
        GitCommitParameters parameters = panel.getParameters();
        GitClient client = getClient();

        populateCandidates(addCandidates, deleteCandidates, commitCandidates);

        if (isCanceled()) {
          return;
        }

        String message = parameters.getCommitMessage();
        GitUser author = parameters.getAuthor();
        GitUser commiter = parameters.getCommiter();
        Collection<GitHook> hooks = panel.getHooks();
        try {

          outputInRed(NbBundle.getMessage(CommitAction.class, "MSG_COMMIT_TITLE")); // NOI18N
          outputInRed(NbBundle.getMessage(CommitAction.class, "MSG_COMMIT_TITLE_SEP")); // NOI18N

          if (addCandidates.size() > 0) {
            client.add(addCandidates.toArray(new File[addCandidates.size()]), getProgressMonitor());
          }
          if (deleteCandidates.size() > 0) {
            client.remove(
                deleteCandidates.toArray(new File[deleteCandidates.size()]),
                false,
                getProgressMonitor());
          }

          if (GitModuleConfig.getDefault().getSignOff() && commiter != null) {
            message += "\nSigned-off-by:" + GitCommitParameters.getUserString(commiter); // NOI18N
          }
          String origMessage = message;
          message = beforeCommitHook(commitCandidates, hooks, message);

          GitRevisionInfo info = commit(commitCandidates, message, author, commiter);

          GitModuleConfig.getDefault()
              .putRecentCommitAuthors(GitCommitParameters.getUserString(author));
          GitModuleConfig.getDefault()
              .putRecentCommiter(GitCommitParameters.getUserString(commiter));

          afterCommitHook(commitCandidates, hooks, info, origMessage);

        } catch (GitException ex) {
          GitClientExceptionHandler.notifyException(ex, true);
        } finally {
          refreshFS(commitCandidates);
          Git.getInstance().getFileStatusCache().refreshAllRoots(commitCandidates);
          outputInRed(NbBundle.getMessage(CommitAction.class, "MSG_COMMIT_DONE")); // NOI18N
          output(""); // NOI18N
          Git.getInstance()
              .getHistoryProvider()
              .fireHistoryChange(commitCandidates.toArray(new File[commitCandidates.size()]));
        }
      } catch (GitException ex) {
        LOG.log(Level.WARNING, null, ex);
      }
    }