本文整理汇总了Java中git4idea.commands.GitCommand类的典型用法代码示例。如果您正苦于以下问题:Java GitCommand类的具体用法?Java GitCommand怎么用?Java GitCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GitCommand类属于git4idea.commands包,在下文中一共展示了GitCommand类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addGithubRemote
import git4idea.commands.GitCommand; //导入依赖的package包/类
public static boolean addGithubRemote(@NotNull Project project,
@NotNull GitRepository repository,
@NotNull String remote,
@NotNull String url) {
final GitSimpleHandler handler = new GitSimpleHandler(project, repository.getRoot(), GitCommand.REMOTE);
handler.setSilent(true);
try {
handler.addParameters("add", remote, url);
handler.run();
if (handler.getExitCode() != 0) {
GithubNotifications.showError(project, "Can't add remote", "Failed to add GitHub remote: '" + url + "'. " + handler.getStderr());
return false;
}
// catch newly added remote
repository.update();
return true;
}
catch (VcsException e) {
GithubNotifications.showError(project, "Can't add remote", e);
return false;
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:GithubUtil.java
示例2: getLastCommitMessage
import git4idea.commands.GitCommand; //导入依赖的package包/类
@Nullable
@Override
protected String getLastCommitMessage(@NotNull VirtualFile root) throws VcsException {
GitSimpleHandler h = new GitSimpleHandler(myProject, root, GitCommand.LOG);
h.addParameters("--max-count=1");
String formatPattern;
if (GitVersionSpecialty.STARTED_USING_RAW_BODY_IN_FORMAT.existsIn(myVcs.getVersion())) {
formatPattern = "%B";
}
else {
// only message: subject + body; "%-b" means that preceding line-feeds will be deleted if the body is empty
// %s strips newlines from subject; there is no way to work around it before 1.7.2 with %B (unless parsing some fixed format)
formatPattern = "%s%n%n%-b";
}
h.addParameters("--pretty=format:" + formatPattern);
return h.run();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GitCheckinEnvironment.java
示例3: annotate
import git4idea.commands.GitCommand; //导入依赖的package包/类
private GitFileAnnotation annotate(@NotNull final FilePath repositoryFilePath,
@Nullable final VcsRevisionNumber revision,
@NotNull final List<VcsFileRevision> revisions,
@NotNull final VirtualFile file) throws VcsException {
GitSimpleHandler h = new GitSimpleHandler(myProject, GitUtil.getGitRoot(repositoryFilePath), GitCommand.BLAME);
h.setStdoutSuppressed(true);
h.setCharset(file.getCharset());
h.addParameters("--porcelain", "-l", "-t", "-w");
if (revision == null) {
h.addParameters("HEAD");
}
else {
h.addParameters(revision.asString());
}
h.endOptions();
h.addRelativePaths(repositoryFilePath);
String output = h.run();
GitFileAnnotation annotation = parseAnnotations(revision, file, output);
annotation.addLogEntries(revisions);
return annotation;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:GitAnnotationProvider.java
示例4: mergeCommit
import git4idea.commands.GitCommand; //导入依赖的package包/类
public void mergeCommit(VirtualFile root) throws VcsException {
GitSimpleHandler handler = new GitSimpleHandler(myProject, root, GitCommand.COMMIT);
handler.setStdoutSuppressed(false);
File gitDir = new File(VfsUtilCore.virtualToIoFile(root), GitUtil.DOT_GIT);
File messageFile = new File(gitDir, GitRepositoryFiles.MERGE_MSG);
if (!messageFile.exists()) {
final GitBranch branch = GitBranchUtil.getCurrentBranch(myProject, root);
final String branchName = branch != null ? branch.getName() : "";
handler.addParameters("-m", "Merge branch '" + branchName + "' of " + root.getPresentableUrl() + " with conflicts.");
} else {
handler.addParameters("-F", messageFile.getAbsolutePath());
}
handler.endOptions();
handler.run();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:GitMerger.java
示例5: getUnmergedPaths
import git4idea.commands.GitCommand; //导入依赖的package包/类
/**
* Returns absolute paths to files which are currently unmerged, and also populates myUnmergedPaths with relative paths.
*/
public @NotNull Set<String> getUnmergedPaths() throws VcsException {
String root = myRoot.getPath();
final GitSimpleHandler h = new GitSimpleHandler(myProject, myRoot, GitCommand.LS_FILES);
h.setSilent(true);
h.addParameters("--unmerged");
final String result = h.run();
final Set<String> paths = new HashSet<String>();
for (StringScanner s = new StringScanner(result); s.hasMoreData();) {
if (s.isEol()) {
s.nextLine();
continue;
}
s.boundedToken('\t');
final String relative = s.line();
if (!myUnmergedPaths.add(relative)) {
continue;
}
String path = root + "/" + GitUtil.unescapePath(relative);
paths.add(path);
}
return paths;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:MergeChangeCollector.java
示例6: listAsStrings
import git4idea.commands.GitCommand; //导入依赖的package包/类
@Deprecated
public static void listAsStrings(final Project project, final VirtualFile root, final Collection<String> tags,
@Nullable final String containingCommit) throws VcsException {
GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.TAG);
handler.setSilent(true);
handler.addParameters("-l");
if (containingCommit != null) {
handler.addParameters("--contains");
handler.addParameters(containingCommit);
}
for (String line : handler.run().split("\n")) {
if (line.length() == 0) {
continue;
}
tags.add(new String(line));
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GitTag.java
示例7: loadStashStack
import git4idea.commands.GitCommand; //导入依赖的package包/类
public static void loadStashStack(@NotNull Project project, @NotNull VirtualFile root, @NotNull Charset charset,
final Consumer<StashInfo> consumer) {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH.readLockingCommand());
h.setSilent(true);
h.addParameters("list");
String out;
try {
h.setCharset(charset);
out = h.run();
}
catch (VcsException e) {
GitUIUtil.showOperationError(project, e, h.printableCommandLine());
return;
}
for (StringScanner s = new StringScanner(out); s.hasMoreData();) {
consumer.consume(new StashInfo(s.boundedToken(':'), s.boundedToken(':'), s.line().trim()));
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:GitStashUtils.java
示例8: getValues
import git4idea.commands.GitCommand; //导入依赖的package包/类
/**
* Get configuration values for the repository. Note that the method executes a git command.
*
* @param project the context project
* @param root the git root
* @param keyMask the keys to be queried
* @param result the map to put results to
* @throws VcsException if there is a problem with running git
*/
public static void getValues(Project project, VirtualFile root, String keyMask, Map<String, String> result) throws VcsException {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.CONFIG);
h.setSilent(true);
h.addParameters("--null");
if (keyMask != null) {
h.addParameters("--get-regexp", keyMask);
} else {
h.addParameters("-l");
}
String output = h.run();
int start = 0;
int pos;
while ((pos = output.indexOf('\n', start)) != -1) {
String key = output.substring(start, pos);
start = pos + 1;
if ((pos = output.indexOf('\u0000', start)) == -1) {
break;
}
String value = output.substring(start, pos);
start = pos + 1;
result.put(key, value);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:GitConfigUtil.java
示例9: getAllValues
import git4idea.commands.GitCommand; //导入依赖的package包/类
/**
* Get configuration values for the repository. Note that the method executes a git command.
*
* @param project the context project
* @param root the git root
* @param key the keys to be queried
* @return list of pairs ({@link Pair#first} is the key, {@link Pair#second} is the value)
* @throws VcsException an exception
*/
public static List<Couple<String>> getAllValues(Project project, VirtualFile root, @NonNls String key) throws VcsException {
List<Couple<String>> result = new ArrayList<Couple<String>>();
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.CONFIG);
h.setSilent(true);
h.addParameters("--null", "--get-all", key);
String output = h.run();
int start = 0;
int pos;
while ((pos = output.indexOf('\u0000', start)) != -1) {
String value = output.substring(start, pos);
start = pos + 1;
result.add(Couple.of(key, value));
}
return result;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:GitConfigUtil.java
示例10: excludeIgnoredFiles
import git4idea.commands.GitCommand; //导入依赖的package包/类
@NotNull
private static List<String> excludeIgnoredFiles(@NotNull Project project, @NotNull VirtualFile root,
@NotNull List<String> paths) throws VcsException {
GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.LS_FILES);
handler.setSilent(true);
handler.addParameters("--ignored", "--others", "--exclude-standard");
handler.endOptions();
handler.addParameters(paths);
String output = handler.run();
List<String> nonIgnoredFiles = new ArrayList<String>(paths.size());
Set<String> ignoredPaths = new HashSet<String>(Arrays.asList(StringUtil.splitByLines(output)));
for (String pathToCheck : paths) {
if (!ignoredPaths.contains(pathToCheck)) {
nonIgnoredFiles.add(pathToCheck);
}
}
return nonIgnoredFiles;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GitFileUtils.java
示例11: commitExists
import git4idea.commands.GitCommand; //导入依赖的package包/类
@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;
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GitChangeUtils.java
示例12: commitExistsByComment
import git4idea.commands.GitCommand; //导入依赖的package包/类
@Nullable
public static List<AbstractHash> commitExistsByComment(final Project project, final VirtualFile root, final String anyReference) {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG);
h.setSilent(true);
String escaped = StringUtil.escapeQuotes(anyReference);
escaped = StringUtil.escapeSlashes(escaped);
final String grepParam = "--grep=" + escaped;
h.addParameters("--regexp-ignore-case", "--pretty=%h", "--all", "--encoding=UTF-8", grepParam, "--");
try {
final String output = h.run().trim();
if (StringUtil.isEmptyOrSpaces(output)) return null;
final String[] hashes = output.split("\n");
final List<AbstractHash> result = new ArrayList<AbstractHash>();
for (String hash : hashes) {
result.add(AbstractHash.create(hash));
}
return result;
}
catch (VcsException e) {
return null;
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:GitChangeUtils.java
示例13: getCurrentBranchFromGit
import git4idea.commands.GitCommand; //导入依赖的package包/类
@Nullable
private static GitLocalBranch getCurrentBranchFromGit(@NotNull Project project, @NotNull VirtualFile root) {
GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.REV_PARSE);
handler.addParameters("--abbrev-ref", "HEAD");
handler.setSilent(true);
try {
String name = handler.run();
if (!name.equals("HEAD")) {
return new GitLocalBranch(name, GitBranch.DUMMY_HASH);
}
else {
return null;
}
}
catch (VcsException e) {
LOG.info("git rev-parse --abbrev-ref HEAD", e);
return null;
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GitBranchUtil.java
示例14: setupGitRepositoryForProject
import git4idea.commands.GitCommand; //导入依赖的package包/类
private GitRepository setupGitRepositoryForProject(final Project project, final VirtualFile rootVirtualFile,
final ServerContext localContext, final ProgressIndicator indicator) {
//project is not in a local git repository, create one
indicator.setText(TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_GIT_INIT, project.getName()));
final GitLineHandler hInit = new GitLineHandler(project, rootVirtualFile, GitCommand.INIT);
GitHandlerUtil.runInCurrentThread(hInit, null, true, TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_GIT_INIT, project.getName()));
if (!hInit.errors().isEmpty()) {
//git init failed
final String error = hInit.errors().get(0).getMessage();
logger.error("setupGitRepositoryForProject: git init failed on project: {} at root: {} with error: {}",
project.getName(), rootVirtualFile.getUrl(), error);
notifyImportError(project,
TfPluginBundle.message(TfPluginBundle.KEY_IMPORT_GIT_INIT_ERROR, project.getName(), error),
ACTION_NAME, localContext);
return null;
}
GitInit.refreshAndConfigureVcsMappings(project, rootVirtualFile, rootVirtualFile.getPath());
final GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
return repositoryManager.getRepositoryForRoot(rootVirtualFile);
}
开发者ID:Microsoft,项目名称:vso-intellij,代码行数:21,代码来源:ImportPageModelImpl.java
示例15: successfulMerge
import git4idea.commands.GitCommand; //导入依赖的package包/类
@Test
public void successfulMerge(final @Mocked GitLineHandler mergeHandler) throws Exception {
new Expectations() {{
new GitLineHandler(project, root, GitCommand.MERGE); result = mergeHandler;
git.runCommand(mergeHandler); result = success;
}};
simpleMerger.mergeAbortIfFailed();
assertThat(simpleMerger.getMergeResult()).isSameAs(success);
assertThat(simpleMerger.getAbortResult()).isNull();
new Verifications() {{
mergeHandler.addParameters(remoteBranchName);
mergeHandler.addParameters("--abort"); times = 0;
}};
}
开发者ID:JChrist,项目名称:gitextender,代码行数:18,代码来源:SimpleMergerTest.java
示例16: successfulAbort
import git4idea.commands.GitCommand; //导入依赖的package包/类
@Test
public void successfulAbort(
final @Mocked GitLineHandler handler
) throws Exception {
new Expectations() {{
new GitLineHandler(project, root, GitCommand.MERGE); result = handler;
git.runCommand(handler); result = error; result = success;
}};
simpleMerger.mergeAbortIfFailed();
assertThat(simpleMerger.getMergeResult())
.as("unexpected merge result")
.isSameAs(error);
assertThat(simpleMerger.getAbortResult())
.as("unexpected abort result")
.isSameAs(success);
new VerificationsInOrder() {{
//new GitLineHandler(project, root, GitCommand.MERGE);
handler.addParameters(remoteBranchName);
//new GitLineHandler(project, root, GitCommand.MERGE);
handler.addParameters("--abort");
}};
}
开发者ID:JChrist,项目名称:gitextender,代码行数:26,代码来源:SimpleMergerTest.java
示例17: errorInAbort
import git4idea.commands.GitCommand; //导入依赖的package包/类
@Test
public void errorInAbort(
final @Mocked GitLineHandler handler
) throws Exception {
new Expectations() {{
new GitLineHandler(project, root, GitCommand.MERGE); result = handler;
git.runCommand(handler); result = error;
}};
simpleMerger.mergeAbortIfFailed();
assertThat(simpleMerger.getMergeResult())
.as("unexpected merge result")
.isSameAs(error);
assertThat(simpleMerger.getAbortResult())
.as("unexpected abort result")
.isSameAs(error);
new VerificationsInOrder() {{
//new GitLineHandler(project, root, GitCommand.MERGE);
handler.addParameters(remoteBranchName);
//new GitLineHandler(project, root, GitCommand.MERGE);
handler.addParameters("--abort");
}};
}
开发者ID:JChrist,项目名称:gitextender,代码行数:26,代码来源:SimpleMergerTest.java
示例18: generateDiff
import git4idea.commands.GitCommand; //导入依赖的package包/类
private String generateDiff(Project project, VirtualFile root, VirtualFile[] vFiles) {
try {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
FileDocumentManager.getInstance().saveAllDocuments();
}
});
GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.DIFF);
handler.addParameters("HEAD");
handler.setSilent(true);
handler.setStdoutSuppressed(true);
handler.addRelativeFiles(Arrays.asList(vFiles));
System.out.println(handler.printableCommandLine());
return handler.run();
} catch (Exception e) {
Messages.showWarningDialog("Svn is still in refresh. Please try again later.", "Alter");
}
return null;
}
开发者ID:kaneg,项目名称:reviewboard-plugin-for-idea,代码行数:20,代码来源:GitVCSBuilder.java
示例19: push
import git4idea.commands.GitCommand; //导入依赖的package包/类
private GtPushResult push(final TagsPushSpec pushSpec, final GitRepository repository,
final GitRemote remote, final String url) {
final GitLineHandlerListener progressListener = GitStandardProgressAnalyzer.createListener(progressIndicator);
final GitPushRejectedDetector rejectedDetector = new GitPushRejectedDetector();
GitCommandResult result = git.runCommand(() -> {
final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(),
GitCommand.PUSH);
h.setUrl(url);
h.setSilent(false);
h.setStdoutSuppressed(false);
h.addLineListener(progressListener);
h.addLineListener(rejectedDetector);
h.addProgressParameter();
h.addParameters(remote.getName());
h.addParameters(pushSpec.specs());
return h;
});
if (rejectedDetector.rejected()) {
return GtPushResult.reject(rejectedDetector.getRejectedBranches());
} else {
return translate(result);
}
}
开发者ID:zielu,项目名称:GitToolBox,代码行数:24,代码来源:GitTagsPusher.java
示例20: scanFiles
import git4idea.commands.GitCommand; //导入依赖的package包/类
/**
* Scan working tree and detect locally modified files
*
* @param project the project to scan
* @param root the root to scan
* @param files the collection with files
* @throws VcsException if there problem with running git or working tree is dirty in unsupported way
*/
private static void scanFiles(Project project, VirtualFile root, List<String> files) throws VcsException {
String rootPath = root.getPath();
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.DIFF);
h.addParameters("--name-status");
h.setSilent(true);
h.setStdoutSuppressed(true);
StringScanner s = new StringScanner(h.run());
while (s.hasMoreData()) {
if (s.isEol()) {
s.line();
continue;
}
if (s.tryConsume("M\t")) {
String path = rootPath + "/" + GitUtil.unescapePath(s.line());
files.add(path);
}
else {
throw new VcsException("Working tree is dirty in unsupported way: " + s.line());
}
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:30,代码来源:GitUpdateLocallyModifiedDialog.java
注:本文中的git4idea.commands.GitCommand类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论