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());
}
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();
}
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;
}
}
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);
}
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));
}
}
Aggregations