Search in sources :

Example 1 with FileGitEventInfo

use of com.oxygenxml.git.view.event.FileGitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class StagingPanel method treatEditorSavedEvent.

/**
 * Treat editor saved event.
 *
 * @param editorLocation Editor URL.
 */
private void treatEditorSavedEvent(final URL editorLocation) {
    File locateFile = null;
    if ("file".equals(editorLocation.getProtocol())) {
        locateFile = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().locateFile(editorLocation);
        if (locateFile != null) {
            String fileInWorkPath = locateFile.toString();
            fileInWorkPath = FileUtil.rewriteSeparator(fileInWorkPath);
            try {
                String selectedRepositoryPath = GitAccess.getInstance().getWorkingCopy().getAbsolutePath();
                selectedRepositoryPath = FileUtil.rewriteSeparator(selectedRepositoryPath);
                if (fileInWorkPath.startsWith(selectedRepositoryPath)) {
                    if (gitActionsManager != null) {
                        gitActionsManager.refreshActionsStates();
                    }
                    updateToolbarsButtonsStates();
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Notify " + fileInWorkPath);
                        LOGGER.debug("WC " + selectedRepositoryPath);
                    }
                    Collection<String> affectedFiles = Collections.singletonList(fileInWorkPath.substring(selectedRepositoryPath.length() + 1));
                    FileGitEventInfo changeEvent = new FileGitEventInfo(GitOperation.UNSTAGE, affectedFiles);
                    SwingUtilities.invokeLater(() -> unstagedChangesPanel.fileStatesChanged(changeEvent));
                }
            } catch (NoRepositorySelected e) {
                LOGGER.debug(e.getMessage(), e);
            }
        }
    }
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) File(java.io.File)

Example 2 with FileGitEventInfo

use of com.oxygenxml.git.view.event.FileGitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method addAll.

/**
 * Adds multiple files to the staging area. Preparing the for commit
 *
 * @param files The files to be added.
 */
public void addAll(List<FileStatus> files) {
    Collection<String> filePaths = getFilePaths(files);
    try {
        fireOperationAboutToStart(new FileGitEventInfo(GitOperation.STAGE, filePaths));
        RmCommand removeCmd = null;
        AddCommand addCmd = null;
        for (FileStatus file : files) {
            if (file.getChangeType() == GitChangeType.MISSING) {
                if (removeCmd == null) {
                    removeCmd = git.rm().setCached(true);
                }
                removeCmd.addFilepattern(file.getFileLocation());
            } else {
                if (addCmd == null) {
                    addCmd = git.add();
                }
                addCmd.addFilepattern(file.getFileLocation());
            }
        }
        if (addCmd != null) {
            addCmd.call();
        }
        if (removeCmd != null) {
            removeCmd.call();
        }
        fireOperationSuccessfullyEnded(new FileGitEventInfo(GitOperation.STAGE, filePaths));
    } catch (GitAPIException e) {
        fireOperationFailed(new FileGitEventInfo(GitOperation.STAGE, filePaths), e);
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) FileStatus(com.oxygenxml.git.service.entities.FileStatus) RmCommand(org.eclipse.jgit.api.RmCommand) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) AddCommand(org.eclipse.jgit.api.AddCommand)

Example 3 with FileGitEventInfo

use of com.oxygenxml.git.view.event.FileGitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method abortMerge.

/**
 * Abort merge.
 */
public void abortMerge() {
    Set<String> conflictingFiles = getConflictingFiles();
    fireOperationAboutToStart(new FileGitEventInfo(GitOperation.ABORT_MERGE, conflictingFiles));
    GitOperationScheduler.getInstance().schedule(() -> {
        try {
            // Clear the merge state
            Repository repository = getRepository();
            repository.writeMergeCommitMsg(null);
            repository.writeMergeHeads(null);
            // Reset the index and work directory to HEAD
            git.reset().setMode(ResetType.HARD).call();
            fireOperationSuccessfullyEnded(new FileGitEventInfo(GitOperation.ABORT_MERGE, conflictingFiles));
        } catch (GitAPIException | IOException | NoRepositorySelected e) {
            fireOperationFailed(new FileGitEventInfo(GitOperation.ABORT_MERGE, conflictingFiles), e);
            LOGGER.error(e.getMessage(), e);
        }
    });
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Repository(org.eclipse.jgit.lib.Repository) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) IOException(java.io.IOException)

Example 4 with FileGitEventInfo

use of com.oxygenxml.git.view.event.FileGitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method resetAll.

/**
 * Reset all the specified files from the staging area.
 *
 * @param files The list of file to be removed
 */
public void resetAll(List<FileStatus> files) {
    Collection<String> filePaths = getFilePaths(files);
    try {
        fireOperationAboutToStart(new FileGitEventInfo(GitOperation.UNSTAGE, filePaths));
        if (!files.isEmpty()) {
            ResetCommand reset = git.reset();
            for (FileStatus file : files) {
                reset.addPath(file.getFileLocation());
            }
            reset.call();
        }
        fireOperationSuccessfullyEnded(new FileGitEventInfo(GitOperation.UNSTAGE, filePaths));
    } catch (GitAPIException e) {
        fireOperationFailed(new FileGitEventInfo(GitOperation.UNSTAGE, filePaths), e);
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) FileStatus(com.oxygenxml.git.service.entities.FileStatus) ResetCommand(org.eclipse.jgit.api.ResetCommand) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo)

Example 5 with FileGitEventInfo

use of com.oxygenxml.git.view.event.FileGitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class StagingResourcesTreeModel method fileStatesChanged.

/**
 * File states changed.
 *
 * @param eventInfo Event information.
 */
public void fileStatesChanged(GitEventInfo eventInfo) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Tree model for index: " + inIndex + " event " + eventInfo);
    }
    GitAccess gitAccess = GitAccess.getInstance();
    switch(eventInfo.getGitOperation()) {
        case STAGE:
            if (inIndex) {
                insertNodes(gitAccess.getStagedFile(((FileGitEventInfo) eventInfo).getAffectedFilePaths()));
            } else {
                deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
            }
            break;
        case UNSTAGE:
            if (inIndex) {
                deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
            } else {
                // Things were taken out of the index / "staged" area.
                // The same resource might be present in the Unstaged and Staged. Remove old states.
                deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
                insertNodes(gitAccess.getUnstagedFiles(((FileGitEventInfo) eventInfo).getAffectedFilePaths()));
            }
            break;
        case COMMIT:
            if (inIndex) {
                clearModel();
            }
            break;
        case DISCARD:
            deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
            break;
        case MERGE_RESTART:
            clearModel();
            List<FileStatus> fileStatuses = inIndex ? gitAccess.getStagedFiles() : gitAccess.getUnstagedFiles();
            insertNodes(fileStatuses);
            break;
        case ABORT_REBASE:
        case CONTINUE_REBASE:
            clearModel();
            break;
        case ABORT_MERGE:
            deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
            break;
        default:
            // Nothing
            break;
    }
    fireTreeStructureChanged(this, null, null, null);
}
Also used : GitAccess(com.oxygenxml.git.service.GitAccess) FileStatus(com.oxygenxml.git.service.entities.FileStatus) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo)

Aggregations

FileGitEventInfo (com.oxygenxml.git.view.event.FileGitEventInfo)8 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 FileStatus (com.oxygenxml.git.service.entities.FileStatus)4 GitAccess (com.oxygenxml.git.service.GitAccess)1 NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)1 File (java.io.File)1 IOException (java.io.IOException)1 AddCommand (org.eclipse.jgit.api.AddCommand)1 CheckoutCommand (org.eclipse.jgit.api.CheckoutCommand)1 ResetCommand (org.eclipse.jgit.api.ResetCommand)1 RmCommand (org.eclipse.jgit.api.RmCommand)1 Repository (org.eclipse.jgit.lib.Repository)1