Search in sources :

Example 1 with GitStatus

use of com.oxygenxml.git.service.GitStatus in project oxygen-git-client-addon by oxygenxml.

the class ProjectMenuGitActionsProvider method getStagedAndUnstagedFiles.

/**
 * @return The staged and the unstaged files.
 */
private List<FileStatus> getStagedAndUnstagedFiles() {
    List<FileStatus> gitFiles = new ArrayList<>();
    GitStatus status = GitAccess.getInstance().getStatus();
    gitFiles.addAll(status.getUnstagedFiles());
    gitFiles.addAll(status.getStagedFiles());
    return gitFiles;
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList) GitStatus(com.oxygenxml.git.service.GitStatus)

Example 2 with GitStatus

use of com.oxygenxml.git.service.GitStatus in project oxygen-git-client-addon by oxygenxml.

the class CommitAndStatusPanel method toggleCommitButtonAndUpdateMessageArea.

/**
 * Checks if the commit button should be enabled.
 *
 * @param forceEnable <code>true</code> to make the button enable without any additional checks.
 */
void toggleCommitButtonAndUpdateMessageArea(boolean forceEnable) {
    if (forceEnable) {
        commitButton.setEnabled(true);
    } else {
        try {
            Repository repo = gitAccess.getRepository();
            final RepositoryState repositoryState = repo.getRepositoryState();
            final String mergeMessage = MessageFormat.format(translator.getTranslation(Tags.COMMIT_TO_MERGE), gitAccess.getBranchInfo().getBranchName(), repo.getConfig().getString("remote", "origin", "url"));
            // Possible time consuming operations.
            commitButtonAndMessageUpdateTask = new SwingWorker<Void, Void>() {

                boolean enable = false;

                String message = null;

                @Override
                protected Void doInBackground() throws Exception {
                    GitStatus status = gitAccess.getStatus();
                    if (repositoryState == RepositoryState.MERGING_RESOLVED && status.getStagedFiles().isEmpty() && status.getUnstagedFiles().isEmpty()) {
                        enable = true;
                        message = mergeMessage;
                    } else if (!status.getStagedFiles().isEmpty() || amendLastCommitToggle.isSelected()) {
                        enable = true;
                    }
                    return null;
                }

                @Override
                protected void done() {
                    if (message != null) {
                        commitMessageArea.setText(message);
                    }
                    commitButton.setEnabled(enable);
                }
            };
            commitButtonAndMessageUpdateTaskTimer.restart();
        } catch (NoRepositorySelected e) {
        // Remains disabled
        }
    }
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) Repository(org.eclipse.jgit.lib.Repository) RepositoryState(org.eclipse.jgit.lib.RepositoryState) RepoNotInitializedException(com.oxygenxml.git.service.RepoNotInitializedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) GitStatus(com.oxygenxml.git.service.GitStatus)

Example 3 with GitStatus

use of com.oxygenxml.git.service.GitStatus in project oxygen-git-client-addon by oxygenxml.

the class StagingPanel method treatPushPullFinished.

/**
 * Push/pull finished. Treat the event.
 *
 * @param pushPullEvent The event.
 */
private void treatPushPullFinished(PushPullEvent pushPullEvent) {
    SwingUtilities.invokeLater(() -> {
        commitPanel.setStatusMessage(pushPullEvent.getMessage());
        commitPanel.reset();
        commitPanel.toggleCommitButtonAndUpdateMessageArea(false);
        workingCopySelectionPanel.getBrowseButton().setEnabled(true);
        workingCopySelectionPanel.getWorkingCopyCombo().setEnabled(true);
        branchSelectionCombo.setEnabled(true);
    });
    // Update models.
    final GitStatus status = GitAccess.getInstance().getStatus();
    SwingUtilities.invokeLater(() -> {
        unstagedChangesPanel.update(status.getUnstagedFiles());
        stagedChangesPanel.update(status.getStagedFiles());
    });
    branchSelectionCombo.refresh();
    if (toolbarPanel != null) {
        toolbarPanel.updateButtonsStates();
    }
    gitActionsManager.refreshActionsStates();
}
Also used : GitStatus(com.oxygenxml.git.service.GitStatus)

Example 4 with GitStatus

use of com.oxygenxml.git.service.GitStatus in project oxygen-git-client-addon by oxygenxml.

the class RepoUtil method isNonConflictualRepoWithUncommittedChanges.

/**
 * Verify if the repo is non-conflictual and has uncommitted changes.
 *
 * @param repoState The repo state.
 *
 * @return <code>true</code> if the repository is not merging, not rebasing and with uncommitted changes.
 */
public static boolean isNonConflictualRepoWithUncommittedChanges(RepositoryState repoState) {
    GitStatus status = GitAccess.getInstance().getStatus();
    boolean repoHasUncommittedChanges = !status.getUnstagedFiles().isEmpty() || !status.getStagedFiles().isEmpty();
    return repoHasUncommittedChanges && !RepoUtil.isUnfinishedConflictState(repoState);
}
Also used : GitStatus(com.oxygenxml.git.service.GitStatus)

Aggregations

GitStatus (com.oxygenxml.git.service.GitStatus)4 NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)1 RepoNotInitializedException (com.oxygenxml.git.service.RepoNotInitializedException)1 FileStatus (com.oxygenxml.git.service.entities.FileStatus)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 Repository (org.eclipse.jgit.lib.Repository)1 RepositoryState (org.eclipse.jgit.lib.RepositoryState)1