use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitCheckoutNewBranchOperation method execute.
@Override
protected void execute() {
boolean fatalErrorHappened = false;
while (hasMoreRepositories() && !fatalErrorHappened) {
final GitRepository repository = next();
GitSimpleEventDetector unmergedDetector = new GitSimpleEventDetector(GitSimpleEventDetector.Event.UNMERGED_PREVENTING_CHECKOUT);
GitCommandResult result = myGit.checkoutNewBranch(repository, myNewBranchName, unmergedDetector);
if (result.success()) {
refresh(repository);
markSuccessful(repository);
} else if (unmergedDetector.hasHappened()) {
fatalUnmergedFilesError();
fatalErrorHappened = true;
} else {
fatalError("Couldn't create new branch " + myNewBranchName, result.getErrorOutputAsJoinedString());
fatalErrorHappened = true;
}
}
if (!fatalErrorHappened) {
notifySuccess();
updateRecentBranch();
}
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitCheckoutNewBranchOperation method rollback.
@Override
protected void rollback() {
GitCompoundResult checkoutResult = new GitCompoundResult(myProject);
GitCompoundResult deleteResult = new GitCompoundResult(myProject);
Collection<GitRepository> repositories = getSuccessfulRepositories();
for (GitRepository repository : repositories) {
GitCommandResult result = myGit.checkout(repository, myCurrentHeads.get(repository), null, true, false);
checkoutResult.append(repository, result);
if (result.success()) {
deleteResult.append(repository, myGit.branchDelete(repository, myNewBranchName, false));
}
refresh(repository);
}
if (checkoutResult.totalSuccess() && deleteResult.totalSuccess()) {
VcsNotifier.getInstance(myProject).notifySuccess("Rollback successful", String.format("Checked out %s and deleted %s on %s %s", stringifyBranchesByRepos(myCurrentHeads), code(myNewBranchName), StringUtil.pluralize("root", repositories.size()), successfulRepositoriesJoined()));
} else {
StringBuilder message = new StringBuilder();
if (!checkoutResult.totalSuccess()) {
message.append("Errors during checkout: ");
message.append(checkoutResult.getErrorOutputWithReposIndication());
}
if (!deleteResult.totalSuccess()) {
message.append("Errors during deleting ").append(code(myNewBranchName));
message.append(deleteResult.getErrorOutputWithReposIndication());
}
VcsNotifier.getInstance(myProject).notifyError("Error during rollback", message.toString());
}
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitDeleteRemoteBranchOperation method doDeleteRemote.
private boolean doDeleteRemote(@NotNull String branchName, @NotNull Collection<GitRepository> repositories) {
Couple<String> pair = splitNameOfRemoteBranch(branchName);
String remoteName = pair.getFirst();
String branch = pair.getSecond();
GitCompoundResult result = new GitCompoundResult(myProject);
for (GitRepository repository : repositories) {
GitCommandResult res;
GitRemote remote = getRemoteByName(repository, remoteName);
if (remote == null) {
String error = "Couldn't find remote by name: " + remoteName;
LOG.error(error);
res = GitCommandResult.error(error);
} else {
res = pushDeletion(repository, remote, branch);
if (!res.success() && isAlreadyDeletedError(res.getErrorOutputAsJoinedString())) {
res = myGit.remotePrune(repository, remote);
}
}
result.append(repository, res);
repository.update();
}
if (!result.totalSuccess()) {
VcsNotifier.getInstance(myProject).notifyError("Failed to delete remote branch " + branchName, result.getErrorOutputWithReposIndication());
}
return result.totalSuccess();
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitCrlfProblemsDetector method findFilesWithoutAttrs.
@NotNull
private Collection<VirtualFile> findFilesWithoutAttrs(@NotNull VirtualFile root, @NotNull Collection<VirtualFile> files) {
GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
if (repository == null) {
LOG.warn("Repository is null for " + root);
return Collections.emptyList();
}
Collection<String> interestingAttributes = Arrays.asList(GitAttribute.TEXT.getName(), GitAttribute.CRLF.getName());
GitCommandResult result = myGit.checkAttr(repository, interestingAttributes, files);
if (!result.success()) {
LOG.warn(String.format("Couldn't git check-attr. Attributes: %s, files: %s", interestingAttributes, files));
return Collections.emptyList();
}
GitCheckAttrParser parser = GitCheckAttrParser.parse(result.getOutput());
Map<String, Collection<GitAttribute>> attributes = parser.getAttributes();
Collection<VirtualFile> filesWithoutAttrs = new ArrayList<>();
for (VirtualFile file : files) {
ProgressIndicatorProvider.checkCanceled();
String relativePath = FileUtil.getRelativePath(root.getPath(), file.getPath(), '/');
Collection<GitAttribute> attrs = attributes.get(relativePath);
if (attrs == null || !attrs.contains(GitAttribute.TEXT) && !attrs.contains(GitAttribute.CRLF)) {
filesWithoutAttrs.add(file);
}
}
return filesWithoutAttrs;
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitCrlfProblemsDetector method isAutoCrlfSetRight.
private boolean isAutoCrlfSetRight(@NotNull VirtualFile root) {
GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
if (repository == null) {
LOG.warn("Repository is null for " + root);
return true;
}
GitCommandResult result = myGit.config(repository, GitConfigUtil.CORE_AUTOCRLF);
String value = result.getOutputAsJoinedString();
return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("input");
}
Aggregations