Search in sources :

Example 1 with FileStatus

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

the class RevCommitUtil method addUntrackedFiles.

/**
 * Add the untracked files to files list.
 *
 * @param changedFiles    The container to add files.
 * @param repository      The Git repository.
 * @param revWalk         The RevWalk.
 * @param commit          The stash commit.
 *
 * @throws IOException
 */
private static void addUntrackedFiles(List<FileStatus> changedFiles, Repository repository, RevWalk revWalk, RevCommit commit) throws IOException {
    RevCommit oldC;
    oldC = revWalk.parseCommit(commit.getParent(PARENT_COMMIT_UNTRACKED));
    try (TreeWalk treeWalk = new TreeWalk(repository)) {
        treeWalk.addTree(commit.getTree());
        treeWalk.setRecursive(false);
        treeWalk.setFilter(null);
        treeWalk.reset(oldC.getTree().getId());
        while (treeWalk.next()) {
            if (treeWalk.isSubtree()) {
                treeWalk.enterSubtree();
            } else {
                String path = treeWalk.getPathString();
                changedFiles.add(new FileStatus(GitChangeType.UNTRACKED, path));
            }
        }
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with FileStatus

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

the class GitStatusCommand method getStagedFiles.

/**
 * Checks which files from the given subset are in the Index and returns their
 * state.
 *
 * @param status The current status.
 *
 * @return - a set containing the subset of files present in the INDEX.
 */
private List<FileStatus> getStagedFiles(Status status) {
    List<FileStatus> stagedFiles = new ArrayList<>();
    Set<String> submodules = getSubmoduleAccess().getSubmodules();
    for (String fileName : status.getChanged()) {
        // File from INDEX, modified from HEAD
        if (submodules.contains(fileName)) {
            stagedFiles.add(new FileStatus(GitChangeType.SUBMODULE, fileName));
        } else {
            stagedFiles.add(new FileStatus(GitChangeType.CHANGED, fileName));
        }
    }
    for (String fileName : status.getAdded()) {
        // Newly created files added in the INDEX
        if (submodules.contains(fileName)) {
            stagedFiles.add(new FileStatus(GitChangeType.SUBMODULE, fileName));
        } else {
            stagedFiles.add(new FileStatus(GitChangeType.ADD, fileName));
        }
    }
    for (String fileName : status.getRemoved()) {
        // A delete added in the INDEX, file is present in HEAD.
        if (submodules.contains(fileName)) {
            stagedFiles.add(new FileStatus(GitChangeType.SUBMODULE, fileName));
        } else {
            stagedFiles.add(new FileStatus(GitChangeType.REMOVED, fileName));
        }
    }
    return stagedFiles;
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList)

Example 3 with FileStatus

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

the class GitControllerBase method discard.

/**
 * Discard files.
 *
 * @param filesStatuses The resources to discard.
 */
private void discard(List<FileStatus> filesStatuses) {
    gitAccess.resetAll(filesStatuses);
    List<String> paths = new LinkedList<>();
    for (FileStatus file : filesStatuses) {
        if (file.getChangeType() != GitChangeType.SUBMODULE) {
            paths.add(file.getFileLocation());
        }
    }
    gitAccess.restoreLastCommitFile(paths);
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) LinkedList(java.util.LinkedList)

Example 4 with FileStatus

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

the class ChangesPanel method showContextualMenuForFlatView.

/**
 * Show contextual menu for flat view.
 *
 * @param x             The X coordinate where to show the menu.
 * @param y             The Y coordinate where to show the menu.
 * @param selectedRows  The selected rows.
 */
private void showContextualMenuForFlatView(int x, int y, int[] selectedRows) {
    final List<FileStatus> files = new ArrayList<>();
    for (int selectedRow : selectedRows) {
        int convertedSelectedRow = filesTable.convertRowIndexToModel(selectedRow);
        StagingResourcesTableModel model = (StagingResourcesTableModel) filesTable.getModel();
        FileStatus file = new FileStatus(model.getUnstageFile(convertedSelectedRow));
        files.add(file);
    }
    GitResourceContextualMenu contextualMenu = new GitResourceContextualMenu(new SelectedResourcesProvider() {

        @Override
        public List<FileStatus> getOnlySelectedLeaves() {
            // All resources are "leaves" in the table view.
            return getAllSelectedResources();
        }

        @Override
        public List<FileStatus> getAllSelectedResources() {
            return files;
        }
    }, gitController, historyController, forStagedResources, RepoUtil.getRepoState());
    contextualMenu.addPopupMenuListener(popupMenuListener);
    contextualMenu.show(filesTable, x, y);
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Point(java.awt.Point)

Example 5 with FileStatus

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

the class ChangesPanel method createTopPanelToolbarButtons.

/**
 * Create the buttons for the toolbar in the top panel.
 */
private void createTopPanelToolbarButtons() {
    // Change selected
    String changeSelectedTranslationTag = forStagedResources ? Tags.UNSTAGE_SELECTED_BUTTON_TEXT : Tags.STAGE_SELECTED_BUTTON_TEXT;
    String changeSelectedIconTag = forStagedResources ? Icons.UNSTAGE_SELECTED : Icons.STAGE_SELECTED;
    changeSelectedButton = OxygenUIComponentsFactory.createToolbarButton(new AbstractAction(TRANSLATOR.getTranslation(changeSelectedTranslationTag), Icons.getIcon(changeSelectedIconTag)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<FileStatus> fileStatuses = new ArrayList<>();
            if (currentViewMode == ResourcesViewMode.FLAT_VIEW) {
                int[] selectedRows = filesTable.getSelectedRows();
                StagingResourcesTableModel fileTableModel = (StagingResourcesTableModel) filesTable.getModel();
                for (int i = selectedRows.length - 1; i >= 0; i--) {
                    int convertedRow = filesTable.convertRowIndexToModel(selectedRows[i]);
                    FileStatus fileStatus = fileTableModel.getFileStatus(convertedRow);
                    fileStatuses.add(fileStatus);
                }
            } else {
                List<String> selectedFiles = TreeUtil.getStringComonAncestor(tree);
                StagingResourcesTreeModel fileTreeModel = (StagingResourcesTreeModel) tree.getModel();
                List<FileStatus> fileStatusesForPaths = fileTreeModel.getFilesByPaths(selectedFiles);
                fileStatuses.addAll(fileStatusesForPaths);
            }
            // "Stage"/"Unstage" actions
            AbstractAction stageUnstageAction = new StageUnstageResourceAction(fileStatuses, !forStagedResources, gitController);
            stageUnstageAction.actionPerformed(null);
            changeSelectedButton.setEnabled(false);
        }
    }, false);
    changeSelectedButton.setEnabled(false);
    // Change all
    String changeAllTranslationTag = forStagedResources ? Tags.UNSTAGE_ALL_BUTTON_TEXT : Tags.STAGE_ALL_BUTTON_TEXT;
    String changeAllIconTag = forStagedResources ? Icons.UNSTAGE_ALL : Icons.STAGE_ALL;
    changeAllButton = OxygenUIComponentsFactory.createToolbarButton(new AbstractAction(TRANSLATOR.getTranslation(changeAllTranslationTag), Icons.getIcon(changeAllIconTag)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (currentViewMode == ResourcesViewMode.FLAT_VIEW) {
                StagingResourcesTableModel fileTableModel = (StagingResourcesTableModel) filesTable.getModel();
                fileTableModel.switchAllFilesStageState();
            } else {
                StagingResourcesTreeModel treeModel = (StagingResourcesTreeModel) tree.getModel();
                treeModel.switchAllFilesStageState();
            }
        }
    }, false);
    changeAllButton.setEnabled(true);
    // Switch view mode
    String iconType = currentViewMode == ResourcesViewMode.FLAT_VIEW ? Icons.TREE_VIEW : Icons.LIST_VIEW;
    switchViewButton = OxygenUIComponentsFactory.createToolbarButton(new AbstractAction(null, Icons.getIcon(iconType)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            setResourcesViewMode(currentViewMode == ResourcesViewMode.FLAT_VIEW ? ResourcesViewMode.TREE_VIEW : ResourcesViewMode.FLAT_VIEW);
            isContextualMenuShowing = false;
        }
    }, false);
    switchViewButton.setToolTipText(TRANSLATOR.getTranslation(Tags.CHANGE_TREE_VIEW_BUTTON_TOOLTIP));
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) StageUnstageResourceAction(com.oxygenxml.git.view.staging.actions.StageUnstageResourceAction) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) AbstractAction(javax.swing.AbstractAction) Point(java.awt.Point)

Aggregations

FileStatus (com.oxygenxml.git.service.entities.FileStatus)210 File (java.io.File)136 Test (org.junit.Test)77 ArrayList (java.util.ArrayList)58 GitController (com.oxygenxml.git.view.event.GitController)53 List (java.util.List)50 Repository (org.eclipse.jgit.lib.Repository)49 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)38 GitTreeNode (com.oxygenxml.git.view.GitTreeNode)33 JButton (javax.swing.JButton)33 SelectedResourcesProvider (com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider)26 IOException (java.io.IOException)25 AbstractAction (javax.swing.AbstractAction)24 JDialog (javax.swing.JDialog)24 GitResourceContextualMenu (com.oxygenxml.git.view.staging.GitResourceContextualMenu)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 URL (java.net.URL)18 Action (javax.swing.Action)18 CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)16