Search in sources :

Example 91 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitBranchWorker method createNewTag.

public void createNewTag(@NotNull final String name, @NotNull final String reference, @NotNull final List<GitRepository> repositories) {
    for (GitRepository repository : repositories) {
        myGit.createNewTag(repository, name, null, reference);
        repository.getRepositoryFiles().refresh(false);
    }
}
Also used : GitRepository(git4idea.repo.GitRepository)

Example 92 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitBranchWorker method checkoutNewBranch.

public void checkoutNewBranch(@NotNull final String name, @NotNull List<GitRepository> repositories) {
    updateInfo(repositories);
    repositories = ContainerUtil.filter(repositories, new Condition<GitRepository>() {

        @Override
        public boolean value(GitRepository repository) {
            GitLocalBranch currentBranch = repository.getCurrentBranch();
            return currentBranch == null || !currentBranch.getName().equals(name);
        }
    });
    if (!repositories.isEmpty()) {
        new GitCheckoutNewBranchOperation(myProject, myGit, myUiHandler, repositories, name).execute();
    } else {
        LOG.error("Creating new branch the same as current in all repositories: " + name);
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) GitRepository(git4idea.repo.GitRepository) GitLocalBranch(git4idea.GitLocalBranch)

Example 93 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitCheckoutOperation method smartCheckoutOrNotify.

private boolean smartCheckoutOrNotify(@NotNull GitRepository repository, @NotNull GitMessageWithFilesDetector localChangesOverwrittenByCheckout) {
    Pair<List<GitRepository>, List<Change>> conflictingRepositoriesAndAffectedChanges = getConflictingRepositoriesAndAffectedChanges(repository, localChangesOverwrittenByCheckout, myCurrentHeads.get(repository), myStartPointReference);
    List<GitRepository> allConflictingRepositories = conflictingRepositoriesAndAffectedChanges.getFirst();
    List<Change> affectedChanges = conflictingRepositoriesAndAffectedChanges.getSecond();
    Collection<String> absolutePaths = GitUtil.toAbsolute(repository.getRoot(), localChangesOverwrittenByCheckout.getRelativeFilePaths());
    int smartCheckoutDecision = myUiHandler.showSmartOperationDialog(myProject, affectedChanges, absolutePaths, "checkout", "&Force Checkout");
    if (smartCheckoutDecision == GitSmartOperationDialog.SMART_EXIT_CODE) {
        boolean smartCheckedOutSuccessfully = smartCheckout(allConflictingRepositories, myStartPointReference, myNewBranch, getIndicator());
        if (smartCheckedOutSuccessfully) {
            for (GitRepository conflictingRepository : allConflictingRepositories) {
                markSuccessful(conflictingRepository);
                refresh(conflictingRepository);
            }
            return true;
        } else {
            // notification is handled in smartCheckout()
            return false;
        }
    } else if (smartCheckoutDecision == GitSmartOperationDialog.FORCE_EXIT_CODE) {
        boolean forceCheckoutSucceeded = checkoutOrNotify(allConflictingRepositories, myStartPointReference, myNewBranch, true);
        if (forceCheckoutSucceeded) {
            markSuccessful(ArrayUtil.toObjectArray(allConflictingRepositories, GitRepository.class));
            refresh(ArrayUtil.toObjectArray(allConflictingRepositories, GitRepository.class));
        }
        return forceCheckoutSucceeded;
    } else {
        fatalLocalChangesError(myStartPointReference);
        return false;
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) List(java.util.List) Change(com.intellij.openapi.vcs.changes.Change)

Example 94 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitCheckoutOperation method execute.

@Override
protected void execute() {
    saveAllDocuments();
    boolean fatalErrorHappened = false;
    AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject);
    try {
        while (hasMoreRepositories() && !fatalErrorHappened) {
            final GitRepository repository = next();
            VirtualFile root = repository.getRoot();
            GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, GitLocalChangesWouldBeOverwrittenDetector.Operation.CHECKOUT);
            GitSimpleEventDetector unmergedFiles = new GitSimpleEventDetector(GitSimpleEventDetector.Event.UNMERGED_PREVENTING_CHECKOUT);
            GitSimpleEventDetector unknownPathspec = new GitSimpleEventDetector(GitSimpleEventDetector.Event.INVALID_REFERENCE);
            GitUntrackedFilesOverwrittenByOperationDetector untrackedOverwrittenByCheckout = new GitUntrackedFilesOverwrittenByOperationDetector(root);
            GitCommandResult result = myGit.checkout(repository, myStartPointReference, myNewBranch, false, myDetach, localChangesDetector, unmergedFiles, unknownPathspec, untrackedOverwrittenByCheckout);
            if (result.success()) {
                refresh(repository);
                markSuccessful(repository);
            } else if (unmergedFiles.hasHappened()) {
                fatalUnmergedFilesError();
                fatalErrorHappened = true;
            } else if (localChangesDetector.wasMessageDetected()) {
                boolean smartCheckoutSucceeded = smartCheckoutOrNotify(repository, localChangesDetector);
                if (!smartCheckoutSucceeded) {
                    fatalErrorHappened = true;
                }
            } else if (untrackedOverwrittenByCheckout.wasMessageDetected()) {
                fatalUntrackedFilesError(repository.getRoot(), untrackedOverwrittenByCheckout.getRelativeFilePaths());
                fatalErrorHappened = true;
            } else if (!myRefShouldBeValid && unknownPathspec.hasHappened()) {
                markSkip(repository);
            } else {
                fatalError(getCommonErrorTitle(), result.getErrorOutputAsJoinedString());
                fatalErrorHappened = true;
            }
        }
    } finally {
        token.finish();
    }
    if (!fatalErrorHappened) {
        if (wereSuccessful()) {
            if (!wereSkipped()) {
                notifySuccess();
                updateRecentBranch();
            } else {
                String mentionSuccess = getSuccessMessage() + GitUtil.mention(getSuccessfulRepositories(), 4);
                String mentionSkipped = wereSkipped() ? "<br>Revision not found" + GitUtil.mention(getSkippedRepositories(), 4) : "";
                VcsNotifier.getInstance(myProject).notifySuccess("", mentionSuccess + mentionSkipped + "<br><a href='rollback'>Rollback</a>", new RollbackOperationNotificationListener());
                updateRecentBranch();
            }
        } else {
            LOG.assertTrue(!myRefShouldBeValid);
            notifyError("Couldn't checkout " + myStartPointReference, "Revision not found" + GitUtil.mention(getSkippedRepositories(), 4));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) AccessToken(com.intellij.openapi.application.AccessToken)

Example 95 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitAbstractRebaseAction method actionPerformed.

@Override
public final void actionPerformed(AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    ProgressManager progressManager = ProgressManager.getInstance();
    String progressTitle = getProgressTitle();
    if (getRepositoryManager(project).hasOngoingRebase()) {
        progressManager.run(new Task.Backgroundable(project, progressTitle) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                performActionForProject(project, indicator);
            }
        });
    } else {
        final GitRepository repositoryToOperate = chooseRepository(project, GitRebaseUtils.getRebasingRepositories(project));
        if (repositoryToOperate != null) {
            progressManager.run(new Task.Backgroundable(project, progressTitle) {

                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    performActionForRepository(project, repositoryToOperate, indicator);
                }
            });
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) Task(com.intellij.openapi.progress.Task) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Aggregations

GitRepository (git4idea.repo.GitRepository)123 VirtualFile (com.intellij.openapi.vfs.VirtualFile)46 NotNull (org.jetbrains.annotations.NotNull)33 Nullable (org.jetbrains.annotations.Nullable)19 Project (com.intellij.openapi.project.Project)18 GitCommandResult (git4idea.commands.GitCommandResult)14 GitRepositoryManager (git4idea.repo.GitRepositoryManager)12 VcsException (com.intellij.openapi.vcs.VcsException)11 AccessToken (com.intellij.openapi.application.AccessToken)9 File (java.io.File)8 Map (java.util.Map)8 GitRemote (git4idea.repo.GitRemote)7 FilePath (com.intellij.openapi.vcs.FilePath)6 Change (com.intellij.openapi.vcs.changes.Change)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Task (com.intellij.openapi.progress.Task)5 ArrayList (java.util.ArrayList)5 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)4 MultiMap (com.intellij.util.containers.MultiMap)4 GitBranch (git4idea.GitBranch)4