use of git4idea.commands.GitSimpleHandler 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 git4idea.commands.GitSimpleHandler in project intellij-community by JetBrains.
the class GitChangeUtils method getDiffHandler.
@NotNull
private static GitSimpleHandler getDiffHandler(@NotNull Project project, @NotNull VirtualFile root, @NotNull String diffRange, @Nullable Collection<FilePath> dirtyPaths, boolean reverse) {
GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.DIFF);
if (reverse) {
handler.addParameters("-R");
}
handler.addParameters("--name-status", "--diff-filter=ADCMRUXT", "-M", diffRange);
handler.setSilent(true);
handler.setStdoutSuppressed(true);
handler.endOptions();
if (dirtyPaths != null) {
handler.addRelativePaths(dirtyPaths);
}
return handler;
}
use of git4idea.commands.GitSimpleHandler in project intellij-community by JetBrains.
the class GitChangeUtils method createRefResolveHandler.
@NotNull
private static GitSimpleHandler createRefResolveHandler(@NotNull Project project, @NotNull VirtualFile root, @NotNull String reference) {
GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.REV_LIST);
handler.addParameters("--timestamp", "--max-count=1", reference);
handler.endOptions();
handler.setSilent(true);
return handler;
}
use of git4idea.commands.GitSimpleHandler 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 git4idea.commands.GitSimpleHandler in project intellij-community by JetBrains.
the class GitMergeDialog method updateBranches.
/**
* Setup branches for git root, this method should be called when root is changed.
*/
public void updateBranches() throws VcsException {
VirtualFile root = getSelectedRoot();
GitSimpleHandler handler = new GitSimpleHandler(myProject, root, GitCommand.BRANCH);
handler.setSilent(true);
handler.addParameters("--no-color", "-a", "--no-merged");
String output = handler.run();
myBranchChooser.clear();
for (StringTokenizer lines = new StringTokenizer(output, "\n", false); lines.hasMoreTokens(); ) {
String branch = lines.nextToken().substring(2);
myBranchChooser.addElement(branch, false);
}
}
Aggregations