Search in sources :

Example 1 with GitSimpleEventDetector

use of git4idea.commands.GitSimpleEventDetector 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();
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) GitSimpleEventDetector(git4idea.commands.GitSimpleEventDetector) GitCommandResult(git4idea.commands.GitCommandResult)

Example 2 with GitSimpleEventDetector

use of git4idea.commands.GitSimpleEventDetector 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;
}
Also used : GitSimpleEventDetector(git4idea.commands.GitSimpleEventDetector) GitUntrackedFilesOverwrittenByOperationDetector(git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector) GitCommandResult(git4idea.commands.GitCommandResult) VcsFullCommitDetails(com.intellij.vcs.log.VcsFullCommitDetails)

Example 3 with GitSimpleEventDetector

use of git4idea.commands.GitSimpleEventDetector in project intellij-community by JetBrains.

the class GitStashChangesSaver method loadRoot.

/**
   * Returns true if the root was loaded with conflict.
   * False is returned in all other cases: in the case of success and in case of some other error.
   */
private boolean loadRoot(final VirtualFile root) {
    LOG.info("loadRoot " + root);
    myProgressIndicator.setText(GitHandlerUtil.formatOperationName("Unstashing changes to", root));
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.error("Repository is null for root " + root);
        return false;
    }
    GitSimpleEventDetector conflictDetector = new GitSimpleEventDetector(GitSimpleEventDetector.Event.MERGE_CONFLICT_ON_UNSTASH);
    GitCommandResult result = myGit.stashPop(repository, conflictDetector);
    VfsUtil.markDirtyAndRefresh(false, true, false, root);
    if (result.success()) {
        return false;
    } else if (conflictDetector.hasHappened()) {
        return true;
    } else {
        LOG.info("unstash failed " + result.getErrorOutputAsJoinedString());
        GitUIUtil.notifyImportantError(myProject, "Couldn't unstash", "<br/>" + result.getErrorOutputAsHtmlString());
        return false;
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) GitSimpleEventDetector(git4idea.commands.GitSimpleEventDetector) GitCommandResult(git4idea.commands.GitCommandResult)

Aggregations

GitCommandResult (git4idea.commands.GitCommandResult)3 GitSimpleEventDetector (git4idea.commands.GitSimpleEventDetector)3 GitRepository (git4idea.repo.GitRepository)2 VcsFullCommitDetails (com.intellij.vcs.log.VcsFullCommitDetails)1 GitUntrackedFilesOverwrittenByOperationDetector (git4idea.commands.GitUntrackedFilesOverwrittenByOperationDetector)1