Example usage for org.eclipse.jgit.lib Repository getRepositoryState

List of usage examples for org.eclipse.jgit.lib Repository getRepositoryState

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository getRepositoryState.

Prototype

@NonNull
public RepositoryState getRepositoryState() 

Source Link

Document

Get the repository state

Usage

From source file:org.eclipse.egit.ui.internal.actions.StashCreateHandler.java

License:Open Source License

static boolean isEnabled(Repository repository) {
    if (repository == null)
        return false;

    if (!repository.getRepositoryState().canCommit())
        return false;

    IndexDiffCacheEntry entry = Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
    if (entry == null)
        return false;

    IndexDiffData diff = entry.getIndexDiff();
    if (diff == null)
        return false;

    if (diff.getAdded().isEmpty() && diff.getChanged().isEmpty() && diff.getRemoved().isEmpty()
            && diff.getUntracked().isEmpty() && diff.getModified().isEmpty() && diff.getMissing().isEmpty())
        return false;

    return true;//from w ww  .j a v a 2s .  co  m
}

From source file:org.eclipse.egit.ui.internal.commands.shared.RebaseCurrentRefCommand.java

License:Open Source License

@Override
public void setEnabled(Object evaluationContext) {
    if (evaluationContext instanceof IEvaluationContext) {
        IEvaluationContext ctx = (IEvaluationContext) evaluationContext;
        Object selection = getSelection(ctx);
        if (selection instanceof ISelection) {
            Repository repo = getRepository((ISelection) selection, getActiveEditorInput(ctx));
            if (repo != null) {
                boolean enabled = isEnabledForState(repo, repo.getRepositoryState());
                setBaseEnabled(enabled);
            } else
                setBaseEnabled(false);/*from   w  ww  . j a  v a 2s . c  o m*/
            return;
        }
    }
    setBaseEnabled(true);
}

From source file:org.eclipse.egit.ui.internal.commit.CommitHelper.java

License:Open Source License

/**
 * @param repository/*from   w  w w . jav  a2s . com*/
 *            to check
 * @return true if an empty commit without files is allowed in the
 *         current state
 */
public static boolean isCommitWithoutFilesAllowed(Repository repository) {
    RepositoryState state = repository.getRepositoryState();
    return state == RepositoryState.MERGING_RESOLVED;
}

From source file:org.eclipse.egit.ui.internal.decorators.DecoratableResourceHelper.java

License:Open Source License

static String getRepositoryName(Repository repository) {
    String repoName = Activator.getDefault().getRepositoryUtil().getRepositoryName(repository);
    RepositoryState state = repository.getRepositoryState();
    if (state != RepositoryState.SAFE)
        return repoName + '|' + state.getDescription();
    else/*from www.  j av  a 2 s  . c  o  m*/
        return repoName;
}

From source file:org.eclipse.egit.ui.internal.GitLabelProvider.java

License:Open Source License

/**
 * @param repository/*from   www  . j  a v a2  s  .  co m*/
 * @return a styled string for the repository
 * @throws IOException
 */
protected StyledString getStyledTextFor(Repository repository) throws IOException {
    File directory = repository.getDirectory();
    StyledString string = new StyledString();
    if (!repository.isBare())
        string.append(directory.getParentFile().getName());
    else
        string.append(directory.getName());

    String branch = Activator.getDefault().getRepositoryUtil().getShortBranch(repository);
    if (branch != null) {
        string.append(' ');
        string.append('[', StyledString.DECORATIONS_STYLER);
        string.append(branch, StyledString.DECORATIONS_STYLER);

        RepositoryState repositoryState = repository.getRepositoryState();
        if (repositoryState != RepositoryState.SAFE) {
            string.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
            string.append(repositoryState.getDescription(), StyledString.DECORATIONS_STYLER);
        }

        BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branch);
        if (trackingStatus != null
                && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) {
            String formattedTrackingStatus = formatBranchTrackingStatus(trackingStatus);
            string.append(' ');
            string.append(formattedTrackingStatus, StyledString.DECORATIONS_STYLER);
        }
        string.append(']', StyledString.DECORATIONS_STYLER);
    }

    string.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
    string.append(directory.getAbsolutePath(), StyledString.QUALIFIER_STYLER);

    return string;
}

From source file:org.eclipse.egit.ui.internal.GitLabels.java

License:Open Source License

/**
 * Computes detailed repository label that consists of repository name,
 * state, checked-out branch and it's status (returned by
 * {@linkplain #formatBranchTrackingStatus(BranchTrackingStatus)})
 *
 * @param repository/*  w  w  w  .  j a  va2 s . com*/
 * @return a styled string for the repository
 * @throws IOException
 */
public static @NonNull StyledString getStyledLabel(@NonNull Repository repository) throws IOException {
    RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();

    StyledString string = getChangedPrefix(repository);

    string.append(repositoryUtil.getRepositoryName(repository));

    String branch = repositoryUtil.getShortBranch(repository);
    if (branch != null) {
        string.append(' ');
        string.append('[', StyledString.DECORATIONS_STYLER);
        string.append(branch, StyledString.DECORATIONS_STYLER);

        BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branch);
        if (trackingStatus != null
                && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) {
            String formattedTrackingStatus = GitLabels.formatBranchTrackingStatus(trackingStatus);
            string.append(' ');
            string.append(formattedTrackingStatus, StyledString.DECORATIONS_STYLER);
        }

        RepositoryState repositoryState = repository.getRepositoryState();
        if (repositoryState != RepositoryState.SAFE) {
            string.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
            string.append(repositoryState.getDescription(), StyledString.DECORATIONS_STYLER);
        }
        string.append(']', StyledString.DECORATIONS_STYLER);
    }

    return string;
}

From source file:org.eclipse.egit.ui.internal.history.command.AbstractRebaseHistoryCommandHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    final Repository repository = getRepository(getPage());
    if (repository == null)
        return false;
    return repository.getRepositoryState().equals(RepositoryState.SAFE);
}

From source file:org.eclipse.egit.ui.internal.history.command.EditHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    GitHistoryPage page = getPage();/*from w  w  w. jav a2 s  . c  o m*/
    if (page == null)
        return false;
    IStructuredSelection selection = getSelection(page);
    if (selection.size() != 1)
        return false;
    Repository repository = getRepository(page);
    if (repository.getRepositoryState() != RepositoryState.SAFE)
        return false;
    RevCommit commit = (RevCommit) selection.getFirstElement();
    return (commit.getParentCount() == 1);
}

From source file:org.eclipse.egit.ui.internal.history.command.MergeHandler.java

License:Open Source License

private boolean canMerge(final Repository repository) {
    String message = null;/*from w  ww.ja va 2s . c o  m*/
    Exception ex = null;
    try {
        Ref head = repository.getRef(Constants.HEAD);
        if (head == null || !head.isSymbolic())
            message = UIText.MergeAction_HeadIsNoBranch;
        else if (!repository.getRepositoryState().equals(RepositoryState.SAFE))
            message = NLS.bind(UIText.MergeAction_WrongRepositoryState, repository.getRepositoryState());
    } catch (IOException e) {
        message = e.getMessage();
        ex = e;
    }

    if (message != null)
        Activator.handleError(UIText.MergeAction_CannotMerge, ex, true);
    return (message == null);
}

From source file:org.eclipse.egit.ui.internal.history.command.SquashHandler.java

License:Open Source License

@Override
public boolean isEnabled() {
    GitHistoryPage page = getPage();/* w  w  w  .jav  a  2s. com*/
    if (page == null)
        return false;
    IStructuredSelection selection = getSelection(page);
    if (selection.isEmpty())
        return false;

    Repository repository = getRepository(page);
    if (repository.getRepositoryState() != RepositoryState.SAFE)
        return false;

    List elements = selection.toList();
    int parentsNotSelected = 0;
    for (Object element : elements) {
        RevCommit commit = (RevCommit) element;

        // disable action if a selected commit does not have exactly
        // one parent (this includes the root commit)
        if (commit.getParentCount() != 1)
            return false;

        RevCommit parentCommit = commit.getParent(0);
        if (!elements.contains(parentCommit))
            parentsNotSelected++;

        // disable action if there is more than one selected commit
        // whose parent has not been selected, this ensures a
        // contiguous selection of commits
        if (parentsNotSelected > 1)
            return false;
    }

    // disable action if there is not exactly one commit whose parent
    // has not been selected
    if (parentsNotSelected != 1)
        return false;

    return true;
}