use of org.zmlx.hg4idea.execution.HgCommandResult in project intellij-community by JetBrains.
the class HgRegularUpdater method update.
private void update(@NotNull VirtualFile repo, ProgressIndicator indicator, UpdatedFiles updatedFiles, List<VcsException> warnings) throws VcsException {
indicator.setText2(HgVcsMessages.message("hg4idea.progress.updatingworkingdir"));
HgRevisionNumber parentBeforeUpdate = new HgWorkingCopyRevisionsCommand(project).firstParent(repo);
HgUpdateCommand hgUpdateCommand = new HgUpdateCommand(project, repo);
HgCommandResult updateResult = hgUpdateCommand.execute();
String warningMessages = ensureSuccess(updateResult).getRawError();
handlePossibleWarning(warnings, warningMessages);
HgRevisionNumber parentAfterUpdate = new HgWorkingCopyRevisionsCommand(project).firstParent(repo);
addUpdatedFiles(repo, updatedFiles, parentBeforeUpdate, parentAfterUpdate);
}
use of org.zmlx.hg4idea.execution.HgCommandResult in project intellij-community by JetBrains.
the class HgRegularUpdater method update.
public boolean update(final UpdatedFiles updatedFiles, ProgressIndicator indicator, List<VcsException> warnings) throws VcsException {
indicator.setText(HgVcsMessages.message("hg4idea.progress.updating", repoRoot.getPath()));
String defaultPath = HgUtil.getRepositoryDefaultPath(project, repoRoot);
if (StringUtil.isEmptyOrSpaces(defaultPath)) {
throw new VcsException(HgVcsMessages.message("hg4idea.warning.no-default-update-path", repoRoot.getPath()));
}
List<HgRevisionNumber> branchHeadsBeforePull = new HgHeadsCommand(project, repoRoot).executeInCurrentThread();
if (branchHeadsBeforePull.size() > 1) {
reportWarning(warnings, HgVcsMessages.message("hg4idea.update.warning.multipleHeadsBeforeUpdate", repoRoot.getPath()));
}
if (updateConfiguration.shouldPull()) {
HgCommandExitCode pullResult = pull(repoRoot, indicator);
if (pullResult == HgCommandExitCode.ERROR) {
return false;
}
}
List<HgRevisionNumber> parentsBeforeUpdate = new HgWorkingCopyRevisionsCommand(project).parents(repoRoot);
if (parentsBeforeUpdate.size() > 1) {
throw new VcsException(HgVcsMessages.message("hg4idea.update.error.uncommittedMerge", repoRoot.getPath()));
}
indicator.setText2(HgVcsMessages.message("hg4idea.progress.countingHeads"));
List<HgRevisionNumber> branchHeadsAfterPull = new HgHeadsCommand(project, repoRoot).executeInCurrentThread();
List<HgRevisionNumber> pulledBranchHeads = determinePulledBranchHeads(branchHeadsBeforePull, branchHeadsAfterPull);
List<HgRevisionNumber> remainingOriginalBranchHeads = determingRemainingOriginalBranchHeads(branchHeadsBeforePull, branchHeadsAfterPull);
HgUpdateType updateType = updateConfiguration.getUpdateType();
if (branchHeadsAfterPull.size() > 1 && updateType != ONLY_UPDATE) {
// merge strategy
if (updateType == MERGE) {
abortOnLocalChanges();
abortOnMultiplePulledHeads(pulledBranchHeads);
abortOnMultipleLocalHeads(remainingOriginalBranchHeads);
HgCommandResult mergeResult = doMerge(indicator);
if (updateConfiguration.shouldCommitAfterMerge()) {
commitOrWarnAboutConflicts(warnings, mergeResult);
}
} else //rebase strategy
{
//resolve conflicts processed during rebase
processRebase(indicator, updatedFiles);
return true;
}
} else //if pull complete successfully and there are only one head, we need just update working directory to the head
{
//in case of multiple heads the update will report the appropriate error
update(repoRoot, indicator, updatedFiles, warnings);
}
//any kind of update could have resulted in merges and merge conflicts, so run the resolver
resolvePossibleConflicts(updatedFiles);
return true;
}
use of org.zmlx.hg4idea.execution.HgCommandResult in project intellij-community by JetBrains.
the class HgOutgoingCommitsProvider method getOutgoingCommits.
@NotNull
@Override
public OutgoingResult getOutgoingCommits(@NotNull final HgRepository repository, @NotNull final PushSpec<HgPushSource, HgTarget> pushSpec, boolean initial) {
final Project project = repository.getProject();
HgVcs hgvcs = HgVcs.getInstance(project);
assert hgvcs != null;
final HgVersion version = hgvcs.getVersion();
String[] templates = HgBaseLogParser.constructFullTemplateArgument(true, version);
HgOutgoingCommand hgOutgoingCommand = new HgOutgoingCommand(project);
HgTarget hgTarget = pushSpec.getTarget();
List<VcsError> errors = new ArrayList<>();
if (StringUtil.isEmptyOrSpaces(hgTarget.myTarget)) {
errors.add(new VcsError("Hg push path could not be empty."));
return new OutgoingResult(Collections.<VcsFullCommitDetails>emptyList(), errors);
}
HgCommandResult result = hgOutgoingCommand.execute(repository.getRoot(), HgChangesetUtil.makeTemplate(templates), pushSpec.getSource().getPresentation(), hgTarget.myTarget, initial);
if (result == null) {
errors.add(new VcsError("Couldn't execute hg outgoing command for " + repository));
return new OutgoingResult(Collections.<VcsFullCommitDetails>emptyList(), errors);
}
List<String> resultErrors = result.getErrorLines();
if (resultErrors != null && !resultErrors.isEmpty() && result.getExitValue() != 0) {
for (String error : resultErrors) {
if (HgErrorUtil.isAbortLine(error)) {
if (HgErrorUtil.isAuthorizationError(error)) {
VcsError authorizationError = new VcsError(error + "<a href='authenticate'>" + LOGIN_AND_REFRESH_LINK + "</a>", new VcsErrorHandler() {
public void handleError(@NotNull CommitLoader commitLoader) {
commitLoader.reloadCommits();
}
});
errors.add(authorizationError);
} else {
errors.add(new VcsError(error));
}
}
}
LOG.warn(resultErrors.toString());
}
return new OutgoingResult(HgHistoryUtil.createFullCommitsFromResult(project, repository.getRoot(), result, version, true), errors);
}
use of org.zmlx.hg4idea.execution.HgCommandResult in project intellij-community by JetBrains.
the class HgPusher method pushSynchronously.
public static void pushSynchronously(@NotNull final Project project, @NotNull HgPushCommand command) {
final VirtualFile repo = command.getRepo();
HgCommandResult result = command.executeInCurrentThread();
if (result == null) {
return;
}
if (result.getExitValue() == PUSH_SUCCEEDED_EXIT_VALUE) {
int commitsNum = getNumberOfPushedCommits(result);
String successTitle = "Pushed successfully";
String successDescription = String.format("Pushed %d %s [%s]", commitsNum, StringUtil.pluralize("commit", commitsNum), repo.getPresentableName());
VcsNotifier.getInstance(project).notifySuccess(successTitle, successDescription);
} else if (result.getExitValue() == NOTHING_TO_PUSH_EXIT_VALUE) {
VcsNotifier.getInstance(project).notifySuccess("Nothing to push");
} else {
new HgCommandResultNotifier(project).notifyError(result, "Push failed", "Failed to push to [" + repo.getPresentableName() + "]");
}
}
use of org.zmlx.hg4idea.execution.HgCommandResult in project intellij-community by JetBrains.
the class HgRepositoryImpl method update.
@Override
public void update() {
HgRepoInfo currentInfo = readRepoInfo();
// update only if something changed!!! if update every time - new log will be refreshed every time, too.
// Then blinking and do not work properly;
final Project project = getProject();
if (!project.isDisposed() && !currentInfo.equals(myInfo)) {
myInfo = currentInfo;
HgCommandResult branchCommandResult = new HgBranchesCommand(project, getRoot()).collectBranches();
if (branchCommandResult == null || branchCommandResult.getExitValue() != 0) {
// hg executable is not valid
LOG.warn("Could not collect hg opened branches.");
myOpenedBranches = myInfo.getBranches().keySet();
} else {
myOpenedBranches = HgBranchesCommand.collectNames(branchCommandResult);
}
HgUtil.executeOnPooledThread(new Runnable() {
public void run() {
if (!project.isDisposed()) {
project.getMessageBus().syncPublisher(HgVcs.STATUS_TOPIC).update(project, getRoot());
}
}
}, project);
}
}
Aggregations