use of git4idea.commands.GitCommandResult 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));
}
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitResetOperation method proposeSmartReset.
private GitCommandResult proposeSmartReset(@NotNull GitLocalChangesWouldBeOverwrittenDetector detector, @NotNull final GitRepository repository, @NotNull final String target) {
Collection<String> absolutePaths = GitUtil.toAbsolute(repository.getRoot(), detector.getRelativeFilePaths());
List<Change> affectedChanges = GitUtil.findLocalChangesForPaths(myProject, repository.getRoot(), absolutePaths, false);
int choice = myUiHandler.showSmartOperationDialog(myProject, affectedChanges, absolutePaths, "reset", "&Hard Reset");
if (choice == GitSmartOperationDialog.SMART_EXIT_CODE) {
final Ref<GitCommandResult> result = Ref.create();
new GitPreservingProcess(myProject, myGit, Collections.singleton(repository.getRoot()), "reset", target, GitVcsSettings.UpdateChangesPolicy.STASH, myIndicator, new Runnable() {
@Override
public void run() {
result.set(myGit.reset(repository, myMode, target));
}
}).execute();
return result.get();
}
if (choice == GitSmartOperationDialog.FORCE_EXIT_CODE) {
return myGit.reset(repository, GitResetMode.HARD, target);
}
return null;
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitResetOperation method execute.
public void execute() {
saveAllDocuments();
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
Map<GitRepository, GitCommandResult> results = ContainerUtil.newHashMap();
try {
for (Map.Entry<GitRepository, Hash> entry : myCommits.entrySet()) {
GitRepository repository = entry.getKey();
VirtualFile root = repository.getRoot();
String target = entry.getValue().asString();
GitLocalChangesWouldBeOverwrittenDetector detector = new GitLocalChangesWouldBeOverwrittenDetector(root, RESET);
GitCommandResult result = myGit.reset(repository, myMode, target, detector);
if (!result.success() && detector.wasMessageDetected()) {
GitCommandResult smartResult = proposeSmartReset(detector, repository, target);
if (smartResult != null) {
result = smartResult;
}
}
results.put(repository, result);
repository.update();
VfsUtil.markDirtyAndRefresh(false, true, false, root);
VcsDirtyScopeManager.getInstance(myProject).dirDirtyRecursively(root);
}
} finally {
token.finish();
}
notifyResult(results);
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitResetOperation method notifyResult.
private void notifyResult(@NotNull Map<GitRepository, GitCommandResult> results) {
Map<GitRepository, GitCommandResult> successes = ContainerUtil.newHashMap();
Map<GitRepository, GitCommandResult> errors = ContainerUtil.newHashMap();
for (Map.Entry<GitRepository, GitCommandResult> entry : results.entrySet()) {
GitCommandResult result = entry.getValue();
GitRepository repository = entry.getKey();
if (result.success()) {
successes.put(repository, result);
} else {
errors.put(repository, result);
}
}
if (errors.isEmpty()) {
myNotifier.notifySuccess("", "Reset successful");
} else if (!successes.isEmpty()) {
myNotifier.notifyImportantWarning("Reset partially failed", "Reset was successful for " + joinRepos(successes.keySet()) + "<br/>but failed for " + joinRepos(errors.keySet()) + ": <br/>" + formErrorReport(errors));
} else {
myNotifier.notifyError("Reset Failed", formErrorReport(errors));
}
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitAbortRebaseProcess method doAbort.
private void doAbort(final boolean rollback) {
new GitFreezingProcess(myProject, "rebase", new Runnable() {
public void run() {
AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
List<GitRepository> repositoriesToRefresh = ContainerUtil.newArrayList();
try {
if (myRepositoryToAbort != null) {
myIndicator.setText2("git rebase --abort" + GitUtil.mention(myRepositoryToAbort));
GitCommandResult result = myGit.rebaseAbort(myRepositoryToAbort);
repositoriesToRefresh.add(myRepositoryToAbort);
if (!result.success()) {
myNotifier.notifyError("Rebase Abort Failed", result.getErrorOutputAsHtmlString() + mentionLocalChangesRemainingInStash(mySaver));
return;
}
}
if (rollback) {
for (GitRepository repo : myRepositoriesToRollback.keySet()) {
myIndicator.setText2("git reset --keep" + GitUtil.mention(repo));
GitCommandResult res = myGit.reset(repo, GitResetMode.KEEP, myRepositoriesToRollback.get(repo));
repositoriesToRefresh.add(repo);
if (res.success()) {
String initialBranchPosition = myInitialCurrentBranches.get(repo);
if (initialBranchPosition != null && !initialBranchPosition.equals(repo.getCurrentBranchName())) {
myIndicator.setText2("git checkout " + initialBranchPosition + GitUtil.mention(repo));
res = myGit.checkout(repo, initialBranchPosition, null, true, false);
}
}
if (!res.success()) {
String description = myRepositoryToAbort != null ? "Rebase abort was successful" + GitUtil.mention(myRepositoryToAbort) + ", but rollback failed" : "Rollback failed";
description += GitUtil.mention(repo) + ":" + res.getErrorOutputAsHtmlString() + mentionLocalChangesRemainingInStash(mySaver);
myNotifier.notifyImportantWarning("Rebase Rollback Failed", description);
return;
}
}
}
if (mySaver != null) {
mySaver.load();
}
myNotifier.notifySuccess("Rebase abort succeeded");
} finally {
refresh(repositoriesToRefresh);
token.finish();
}
}
}).execute();
}
Aggregations