Search in sources :

Example 91 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class GitHistoryProvider method getBaseVersionContent.

@Override
public boolean getBaseVersionContent(FilePath filePath, Processor<CharSequence> processor, final String beforeVersionId, List<String> warnings) throws VcsException {
    if (StringUtil.isEmptyOrSpaces(beforeVersionId) || filePath.getVirtualFile() == null)
        return false;
    // apply if base revision id matches revision
    final VirtualFile root = GitUtil.getGitRoot(filePath);
    if (root == null)
        return false;
    final SHAHash shaHash = GitChangeUtils.commitExists(myProject, root, beforeVersionId, null, "HEAD");
    if (shaHash == null) {
        throw new VcsException("Can not apply patch to " + filePath.getPath() + ".\nCan not find revision '" + beforeVersionId + "'.");
    }
    final ContentRevision content = GitVcs.getInstance(myProject).getDiffProvider().createFileContent(new GitRevisionNumber(shaHash.getValue()), filePath.getVirtualFile());
    if (content == null) {
        throw new VcsException("Can not load content of '" + filePath.getPath() + "' for revision '" + shaHash.getValue() + "'");
    }
    return !processor.process(content.getContent());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SHAHash(git4idea.history.browser.SHAHash) GitRevisionNumber(git4idea.GitRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision)

Example 92 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class GitHistoryUtils method getAuthorTime.

public static long getAuthorTime(@NotNull Project project, @NotNull FilePath path, @NotNull String commitsId) throws VcsException {
    // adjust path using change manager
    path = getLastCommitName(project, path);
    final VirtualFile root = GitUtil.getGitRoot(path);
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.SHOW);
    GitLogParser parser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, AUTHOR_TIME);
    h.setSilent(true);
    h.addParameters("--name-status", parser.getPretty(), "--encoding=UTF-8");
    h.addParameters(commitsId);
    String output = h.run();
    GitLogRecord logRecord = parser.parseOneRecord(output);
    if (logRecord == null)
        throw new VcsException("Can not parse log output \"" + output + "\"");
    return logRecord.getAuthorTimeStamp();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsException(com.intellij.openapi.vcs.VcsException)

Example 93 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class GitChangeUtils method commitExists.

@Nullable
public static SHAHash commitExists(final Project project, final VirtualFile root, final String anyReference, List<VirtualFile> paths, final String... parameters) {
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG);
    h.setSilent(true);
    h.addParameters(parameters);
    h.addParameters("--max-count=1", "--pretty=%H", "--encoding=UTF-8", anyReference, "--");
    if (paths != null && !paths.isEmpty()) {
        h.addRelativeFiles(paths);
    }
    try {
        final String output = h.run().trim();
        if (StringUtil.isEmptyOrSpaces(output))
            return null;
        return new SHAHash(output);
    } catch (VcsException e) {
        return null;
    }
}
Also used : SHAHash(git4idea.history.browser.SHAHash) GitSimpleHandler(git4idea.commands.GitSimpleHandler) VcsException(com.intellij.openapi.vcs.VcsException) Nullable(org.jetbrains.annotations.Nullable)

Example 94 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class GitChangeUtils method resolveReference.

/**
   * Load actual revision number with timestamp basing on a reference: name of a branch or tag, or revision number expression.
   */
@NotNull
public static GitRevisionNumber resolveReference(@NotNull Project project, @NotNull VirtualFile vcsRoot, @NotNull String reference) throws VcsException {
    GitSimpleHandler handler = createRefResolveHandler(project, vcsRoot, reference);
    String output = handler.run();
    StringTokenizer stk = new StringTokenizer(output, "\n\r \t", false);
    if (!stk.hasMoreTokens()) {
        try {
            GitSimpleHandler dh = new GitSimpleHandler(project, vcsRoot, GitCommand.LOG);
            dh.addParameters("-1", "HEAD");
            dh.setSilent(true);
            String out = dh.run();
            LOG.info("Diagnostic output from 'git log -1 HEAD': [" + out + "]");
            dh = createRefResolveHandler(project, vcsRoot, reference);
            out = dh.run();
            LOG.info("Diagnostic output from 'git rev-list -1 --timestamp HEAD': [" + out + "]");
        } catch (VcsException e) {
            LOG.info("Exception while trying to get some diagnostics info", e);
        }
        throw new VcsException(String.format("The string '%s' does not represent a revision number. Output: [%s]\n Root: %s", reference, output, vcsRoot));
    }
    Date timestamp = GitUtil.parseTimestampWithNFEReport(stk.nextToken(), handler, output);
    return new GitRevisionNumber(stk.nextToken(), timestamp);
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitRevisionNumber(git4idea.GitRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 95 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class GitConflictResolver method unmergedFiles.

/**
   * Parse changes from lines
   *
   *
   * @param root    the git root
   * @return a set of unmerged files
   * @throws com.intellij.openapi.vcs.VcsException if the input format does not matches expected format
   */
private List<VirtualFile> unmergedFiles(final VirtualFile root) throws VcsException {
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.error("Repository not found for root " + root);
        return Collections.emptyList();
    }
    GitCommandResult result = myGit.getUnmergedFiles(repository);
    if (!result.success()) {
        throw new VcsException(result.getErrorOutputAsJoinedString());
    }
    String output = StringUtil.join(result.getOutput(), "\n");
    HashSet<String> unmergedPaths = ContainerUtil.newHashSet();
    for (StringScanner s = new StringScanner(output); s.hasMoreData(); ) {
        if (s.isEol()) {
            s.nextLine();
            continue;
        }
        s.boundedToken('\t');
        String relative = s.line();
        unmergedPaths.add(GitUtil.unescapePath(relative));
    }
    if (unmergedPaths.size() == 0) {
        return Collections.emptyList();
    } else {
        List<File> files = ContainerUtil.map(unmergedPaths, new Function<String, File>() {

            @Override
            public File fun(String path) {
                return new File(root.getPath(), path);
            }
        });
        return sortVirtualFilesByPresentation(findVirtualFilesWithRefresh(files));
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) VcsException(com.intellij.openapi.vcs.VcsException) GitCommandResult(git4idea.commands.GitCommandResult) StringScanner(git4idea.util.StringScanner) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

VcsException (com.intellij.openapi.vcs.VcsException)200 VirtualFile (com.intellij.openapi.vfs.VirtualFile)89 File (java.io.File)48 NotNull (org.jetbrains.annotations.NotNull)42 FilePath (com.intellij.openapi.vcs.FilePath)35 Change (com.intellij.openapi.vcs.changes.Change)33 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)26 ArrayList (java.util.ArrayList)24 Nullable (org.jetbrains.annotations.Nullable)23 IOException (java.io.IOException)20 SVNException (org.tmatesoft.svn.core.SVNException)19 Project (com.intellij.openapi.project.Project)17 Ref (com.intellij.openapi.util.Ref)16 Test (org.junit.Test)14 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)13 GitRepository (git4idea.repo.GitRepository)12 Task (com.intellij.openapi.progress.Task)11 List (java.util.List)11 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)10 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)10