Search in sources :

Example 6 with DiscardAction

use of com.oxygenxml.git.view.staging.actions.DiscardAction in project oxygen-git-client-addon by oxygenxml.

the class FlatView3Test method testDiscard.

/**
 * Discard changes. THose files must not appear in either stage/un-stage area.
 *
 * @throws Exception If it fails.
 */
public void testDiscard() throws Exception {
    /**
     * Local repository location.
     */
    String localTestRepository = "target/test-resources/testDiscard_NewFile_local";
    /**
     * Remote repository location.
     */
    String remoteTestRepository = "target/test-resources/testDiscard_NewFile_remote";
    new File(localTestRepository).mkdirs();
    File file = new File(localTestRepository + "/test.txt");
    file.createNewFile();
    setFileContent(file, "remote");
    // Create repositories
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo = createRepository(localTestRepository);
    // Bind the local repository to the remote one.
    bindLocalToRemote(localRepo, remoteRepo);
    // Add it to the index.
    add(new FileStatus(GitChangeType.UNKNOWN, "test.txt"));
    assertTableModels("", "ADD, test.txt");
    GitAccess.getInstance().commit("First version.");
    assertTableModels("", "");
    // Change the file.
    setFileContent(file, "index content");
    assertTableModels("MODIFIED, test.txt", "");
    add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
    assertTableModels("", "CHANGED, test.txt");
    // Change the file.
    setFileContent(file, "modified content");
    // The file is present in  both areas.
    assertTableModels("MODIFIED, test.txt", "CHANGED, test.txt");
    // Discard.
    DiscardAction discardAction = new DiscardAction(new SelectedResourcesProvider() {

        @Override
        public List<FileStatus> getOnlySelectedLeaves() {
            return null;
        }

        @Override
        public List<FileStatus> getAllSelectedResources() {
            return Arrays.asList(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
        }
    }, stagingPanel.getGitController());
    discardAction.actionPerformed(null);
    waitForScheduler();
    assertTableModels("", "");
}
Also used : DiscardAction(com.oxygenxml.git.view.staging.actions.DiscardAction) Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) SelectedResourcesProvider(com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider) List(java.util.List) File(java.io.File)

Aggregations

DiscardAction (com.oxygenxml.git.view.staging.actions.DiscardAction)6 FileStatus (com.oxygenxml.git.service.entities.FileStatus)5 SelectedResourcesProvider (com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider)5 File (java.io.File)5 List (java.util.List)5 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)3 Repository (org.eclipse.jgit.lib.Repository)2 GitAccess (com.oxygenxml.git.service.GitAccess)1 SubmoduleAccess (com.oxygenxml.git.service.SubmoduleAccess)1 OpenAction (com.oxygenxml.git.view.staging.actions.OpenAction)1 ShowBlameForUnstagedResourceAction (com.oxygenxml.git.view.staging.actions.ShowBlameForUnstagedResourceAction)1 StageUnstageResourceAction (com.oxygenxml.git.view.staging.actions.StageUnstageResourceAction)1 ActionEvent (java.awt.event.ActionEvent)1 AbstractAction (javax.swing.AbstractAction)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1