use of git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector 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.GitUntrackedFilesOverwrittenByOperationDetector 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);
}
}
}
Aggregations