use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitCheckoutProvider method doClone.
public static boolean doClone(@NotNull Project project, @NotNull Git git, @NotNull String directoryName, @NotNull String parentDirectory, @NotNull String sourceRepositoryURL) {
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
indicator.setIndeterminate(false);
GitLineHandlerListener progressListener = GitStandardProgressAnalyzer.createListener(indicator);
GitCommandResult result = git.clone(project, new File(parentDirectory), sourceRepositoryURL, directoryName, progressListener);
if (result.success()) {
return true;
}
VcsNotifier.getInstance(project).notifyError("Clone failed", result.getErrorOutputAsHtmlString());
return false;
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitCherryPicker method cherryPick.
// return true to continue with other roots, false to break execution
private boolean cherryPick(@NotNull GitRepository repository, @NotNull List<VcsFullCommitDetails> commits, @NotNull List<GitCommitWrapper> successfulCommits, @NotNull List<GitCommitWrapper> alreadyPicked) {
for (VcsFullCommitDetails commit : commits) {
GitSimpleEventDetector conflictDetector = new GitSimpleEventDetector(CHERRY_PICK_CONFLICT);
GitSimpleEventDetector localChangesOverwrittenDetector = new GitSimpleEventDetector(LOCAL_CHANGES_OVERWRITTEN_BY_CHERRY_PICK);
GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(repository.getRoot());
boolean autoCommit = isAutoCommit();
GitCommandResult result = myGit.cherryPick(repository, commit.getId().asString(), autoCommit, conflictDetector, localChangesOverwrittenDetector, untrackedFilesDetector);
GitCommitWrapper commitWrapper = new GitCommitWrapper(commit);
if (result.success()) {
if (autoCommit) {
successfulCommits.add(commitWrapper);
} else {
boolean committed = updateChangeListManagerShowCommitDialogAndRemoveChangeListOnSuccess(repository, commitWrapper, successfulCommits, alreadyPicked);
if (!committed) {
notifyCommitCancelled(commitWrapper, successfulCommits);
return false;
}
}
} else if (conflictDetector.hasHappened()) {
boolean mergeCompleted = new CherryPickConflictResolver(myProject, myGit, repository.getRoot(), commit.getId().asString(), VcsUserUtil.getShortPresentation(commit.getAuthor()), commit.getSubject()).merge();
if (mergeCompleted) {
boolean committed = updateChangeListManagerShowCommitDialogAndRemoveChangeListOnSuccess(repository, commitWrapper, successfulCommits, alreadyPicked);
if (!committed) {
notifyCommitCancelled(commitWrapper, successfulCommits);
return false;
}
} else {
updateChangeListManager(commit);
notifyConflictWarning(repository, commitWrapper, successfulCommits);
return false;
}
} else if (untrackedFilesDetector.wasMessageDetected()) {
String description = commitDetails(commitWrapper) + "<br/>Some untracked working tree files would be overwritten by cherry-pick.<br/>" + "Please move, remove or add them before you can cherry-pick. <a href='view'>View them</a>";
description += getSuccessfulCommitDetailsIfAny(successfulCommits);
GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(myProject, repository.getRoot(), untrackedFilesDetector.getRelativeFilePaths(), "cherry-pick", description);
return false;
} else if (localChangesOverwrittenDetector.hasHappened()) {
notifyError("Your local changes would be overwritten by cherry-pick.<br/>Commit your changes or stash them to proceed.", commitWrapper, successfulCommits);
return false;
} else if (isNothingToCommitMessage(result)) {
alreadyPicked.add(commitWrapper);
} else {
notifyError(result.getErrorOutputAsHtmlString(), commitWrapper, successfulCommits);
return false;
}
}
return true;
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitRebaseProcess method rebaseSingleRoot.
@NotNull
private GitRebaseStatus rebaseSingleRoot(@NotNull GitRepository repository, @Nullable GitRebaseResumeMode customMode, @NotNull Map<GitRepository, GitSuccessfulRebase> alreadyRebased) {
VirtualFile root = repository.getRoot();
String repoName = getShortRepositoryName(repository);
LOG.info("Rebasing root " + repoName + ", mode: " + notNull(customMode, "standard"));
Collection<GitRebaseUtils.CommitInfo> skippedCommits = newArrayList();
MultiMap<GitRepository, GitRebaseUtils.CommitInfo> allSkippedCommits = getSkippedCommits(alreadyRebased);
boolean retryWhenDirty = false;
while (true) {
GitRebaseProblemDetector rebaseDetector = new GitRebaseProblemDetector();
GitUntrackedFilesOverwrittenByOperationDetector untrackedDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root);
GitRebaseLineListener progressListener = new GitRebaseLineListener();
GitCommandResult result = callRebase(repository, customMode, rebaseDetector, untrackedDetector, progressListener);
boolean somethingRebased = customMode != null || progressListener.getResult().current > 1;
if (result.success()) {
if (rebaseDetector.hasStoppedForEditing()) {
showStoppedForEditingMessage(repository);
return new GitRebaseStatus(GitRebaseStatus.Type.SUSPENDED, skippedCommits);
}
LOG.debug("Successfully rebased " + repoName);
return GitSuccessfulRebase.parseFromOutput(result.getOutput(), skippedCommits);
} else if (result.cancelled()) {
LOG.info("Rebase was cancelled");
throw new ProcessCanceledException();
} else if (rebaseDetector.isDirtyTree() && customMode == null && !retryWhenDirty) {
// if the initial dirty tree check doesn't find all local changes, we are still ready to stash-on-demand,
// but only once per repository (if the error happens again, that means that the previous stash attempt failed for some reason),
// and not in the case of --continue (where all local changes are expected to be committed) or --skip.
LOG.debug("Dirty tree detected in " + repoName);
String saveError = saveLocalChanges(singleton(repository.getRoot()));
if (saveError == null) {
// try same repository again
retryWhenDirty = true;
} else {
LOG.warn("Couldn't " + mySaver.getOperationName() + " root " + repository.getRoot() + ": " + saveError);
showFatalError(saveError, repository, somethingRebased, alreadyRebased.keySet(), allSkippedCommits);
GitRebaseStatus.Type type = somethingRebased ? GitRebaseStatus.Type.SUSPENDED : GitRebaseStatus.Type.ERROR;
return new GitRebaseStatus(type, skippedCommits);
}
} else if (untrackedDetector.wasMessageDetected()) {
LOG.info("Untracked files detected in " + repoName);
showUntrackedFilesError(untrackedDetector.getRelativeFilePaths(), repository, somethingRebased, alreadyRebased.keySet(), allSkippedCommits);
GitRebaseStatus.Type type = somethingRebased ? GitRebaseStatus.Type.SUSPENDED : GitRebaseStatus.Type.ERROR;
return new GitRebaseStatus(type, skippedCommits);
} else if (rebaseDetector.isNoChangeError()) {
LOG.info("'No changes' situation detected in " + repoName);
GitRebaseUtils.CommitInfo currentRebaseCommit = GitRebaseUtils.getCurrentRebaseCommit(myProject, root);
if (currentRebaseCommit != null)
skippedCommits.add(currentRebaseCommit);
customMode = GitRebaseResumeMode.SKIP;
} else if (rebaseDetector.isMergeConflict()) {
LOG.info("Merge conflict in " + repoName);
ResolveConflictResult resolveResult = showConflictResolver(repository, false);
if (resolveResult == ResolveConflictResult.ALL_RESOLVED) {
customMode = GitRebaseResumeMode.CONTINUE;
} else if (resolveResult == ResolveConflictResult.NOTHING_TO_MERGE) {
// the output is the same for the cases:
// (1) "unresolved conflicts"
// (2) "manual editing of a file not followed by `git add`
// => we check if there are any unresolved conflicts, and if not, then it is the case #2 which we are not handling
LOG.info("Unmerged changes while rebasing root " + repoName + ": " + result.getErrorOutputAsJoinedString());
showFatalError(result.getErrorOutputAsHtmlString(), repository, somethingRebased, alreadyRebased.keySet(), allSkippedCommits);
GitRebaseStatus.Type type = somethingRebased ? GitRebaseStatus.Type.SUSPENDED : GitRebaseStatus.Type.ERROR;
return new GitRebaseStatus(type, skippedCommits);
} else {
notifyNotAllConflictsResolved(repository, allSkippedCommits);
return new GitRebaseStatus(GitRebaseStatus.Type.SUSPENDED, skippedCommits);
}
} else {
LOG.info("Error rebasing root " + repoName + ": " + result.getErrorOutputAsJoinedString());
showFatalError(result.getErrorOutputAsHtmlString(), repository, somethingRebased, alreadyRebased.keySet(), allSkippedCommits);
GitRebaseStatus.Type type = somethingRebased ? GitRebaseStatus.Type.SUSPENDED : GitRebaseStatus.Type.ERROR;
return new GitRebaseStatus(type, skippedCommits);
}
}
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitRebaseUpdater method fastForwardMerge.
/**
* Tries to execute {@code git merge --ff-only}.
* @return true, if everything is successful; false for any error (to let a usual "fair" update deal with it).
*/
public boolean fastForwardMerge() {
LOG.info("Trying fast-forward merge for " + myRoot);
GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(myRoot);
if (repository == null) {
LOG.error("Repository is null for " + myRoot);
return false;
}
try {
markStart(myRoot);
} catch (VcsException e) {
LOG.info("Couldn't mark start for repository " + myRoot, e);
return false;
}
GitCommandResult result = myGit.merge(repository, getRemoteBranchToMerge(), singletonList("--ff-only"));
try {
markEnd(myRoot);
} catch (VcsException e) {
// this is not critical, and update has already happened,
// so we just notify the user about problems with collecting the updated changes.
LOG.info("Couldn't mark end for repository " + myRoot, e);
VcsNotifier.getInstance(myProject).notifyMinorWarning("Couldn't collect the updated files info", String.format("Update of %s was successful, but we couldn't collect the updated changes because of an error", myRoot), null);
}
return result.success();
}
use of git4idea.commands.GitCommandResult in project intellij-community by JetBrains.
the class GitIntegrationEnabler method initOrNotifyError.
protected boolean initOrNotifyError(@NotNull final VirtualFile projectDir) {
VcsNotifier vcsNotifier = VcsNotifier.getInstance(myProject);
GitCommandResult result = myGit.init(myProject, projectDir);
if (result.success()) {
refreshVcsDir(projectDir, GitUtil.DOT_GIT);
vcsNotifier.notifySuccess("Created Git repository in " + projectDir.getPresentableUrl());
return true;
} else {
if (myVcs.getExecutableValidator().checkExecutableAndNotifyIfNeeded()) {
vcsNotifier.notifyError("Couldn't git init " + projectDir.getPresentableUrl(), result.getErrorOutputAsHtmlString());
LOG.info(result.getErrorOutputAsHtmlString());
}
return false;
}
}
Aggregations