use of com.oxygenxml.git.view.staging.actions.DiscardAction in project oxygen-git-client-addon by oxygenxml.
the class TreeView2Test 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";
// Create repositories
Repository remoteRepo = createRepository(remoteTestRepository);
Repository localRepo = createRepository(localTestRepository);
// Bind the local repository to the remote one.
bindLocalToRemote(localRepo, remoteRepo);
File file = createNewFile(localTestRepository, "test.txt", "remote");
// Add it to the index.
add(new FileStatus(GitChangeType.UNKNOWN, "test.txt"));
assertTreeModels("", "ADD, test.txt");
GitAccess.getInstance().commit("First version.");
assertTreeModels("", "");
// Change the file.
setFileContent(file, "index content");
assertTreeModels("MODIFIED, test.txt", "");
add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
assertTreeModels("", "CHANGED, test.txt");
// Change the file.
setFileContent(file, "modified content");
// The file is present in both areas.
assertTreeModels("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();
assertTreeModels("", "");
}
use of com.oxygenxml.git.view.staging.actions.DiscardAction in project oxygen-git-client-addon by oxygenxml.
the class GitResourceContextualMenu method createAllActions.
/**
* Creates actions for contextual menu.
* @param allSelectedResources A list with all selected resources.
* @param selectedLeaves A list of FileStatus with selected leaves.
* @param selResProvider Provides the resources that will be processed by the menu's actions.
* @param forStagedRes <code>true</code> if the contextual menu is created for staged files.
*/
private void createAllActions(final List<FileStatus> allSelectedResources, final List<FileStatus> selectedLeaves, final SelectedResourcesProvider selResProvider, final boolean forStagedRes) {
// "Open in compare editor" action
showDiffAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.OPEN_IN_COMPARE)) {
@Override
public void actionPerformed(ActionEvent e) {
DiffPresenter.showDiff(selectedLeaves.get(0), gitCtrl);
}
};
// "Open" action
openAction = new OpenAction(selResProvider);
// "Stage"/"Unstage" actions
stageUnstageAction = new StageUnstageResourceAction(allSelectedResources, // then the action should be unstage.
!forStagedRes, gitCtrl);
// Resolve using "mine"
resolveUsingMineAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.RESOLVE_USING_MINE)) {
@Override
public void actionPerformed(ActionEvent e) {
gitCtrl.asyncResolveUsingMine(allSelectedResources);
}
};
// Resolve using "theirs"
resolveUsingTheirsAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.RESOLVE_USING_THEIRS)) {
@Override
public void actionPerformed(ActionEvent e) {
gitCtrl.asyncResolveUsingTheirs(allSelectedResources);
}
};
// "Mark resolved" action
markResolvedAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.MARK_RESOLVED)) {
@Override
public void actionPerformed(ActionEvent e) {
try {
if (FileUtil.containsConflictMarkers(allSelectedResources, GIT_ACCESS.getWorkingCopy())) {
int answer = FileStatusDialog.showWarningMessageWithConfirmation(TRANSLATOR.getTranslation(Tags.MARK_RESOLVED), TRANSLATOR.getTranslation(Tags.CONFLICT_MARKERS_MESSAGE), TRANSLATOR.getTranslation(Tags.RESOLVE_ANYWAY), TRANSLATOR.getTranslation(Tags.CANCEL));
if (answer == FileStatusDialog.RESULT_OK) {
gitCtrl.asyncAddToIndex(allSelectedResources);
}
} else {
gitCtrl.asyncAddToIndex(allSelectedResources);
}
} catch (Exception err) {
LOGGER.error(err.getMessage(), err);
}
}
};
// "Restart Merge" action
restartMergeAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.RESTART_MERGE)) {
@Override
public void actionPerformed(ActionEvent e) {
String[] options = new String[] { " " + TRANSLATOR.getTranslation(Tags.YES) + " ", " " + TRANSLATOR.getTranslation(Tags.NO) + " " };
int[] optionIds = new int[] { 0, 1 };
int result = GitResourceContextualMenu.PLUGIN_WS.showConfirmDialog(TRANSLATOR.getTranslation(Tags.RESTART_MERGE), TRANSLATOR.getTranslation(Tags.RESTART_MERGE_CONFIRMATION), options, optionIds);
if (result == optionIds[0]) {
GIT_ACCESS.restartMerge();
}
}
};
// "Discard" action
discardAction = new DiscardAction(selResProvider, gitCtrl);
if (!forStagedRes) {
// Show history
historyAction = new AbstractAction(TRANSLATOR.getTranslation(Tags.SHOW_HISTORY)) {
@Override
public void actionPerformed(ActionEvent e) {
if (!allSelectedResources.isEmpty()) {
historyController.showResourceHistory(allSelectedResources.get(0).getFileLocation());
}
}
};
// "Blame" action
blameAction = new ShowBlameForUnstagedResourceAction(historyController, selResProvider);
}
}
use of com.oxygenxml.git.view.staging.actions.DiscardAction in project oxygen-git-client-addon by oxygenxml.
the class RefreshProjectTest method testRefreshProjectOnDiscard_2.
/**
* Refresh on discard. Multiple "untracked" resources discarded
*
* @throws Exception
*/
public void testRefreshProjectOnDiscard_2() throws Exception {
File repoDir = new File(localTestRepoPath);
repoDir.mkdirs();
File file = new File(localTestRepoPath, "test.txt");
file.createNewFile();
file.deleteOnExit();
new File(localTestRepoPath + "/subFolder").mkdir();
File file2 = new File(localTestRepoPath, "subFolder/test2.txt");
file2.createNewFile();
file2.deleteOnExit();
try {
DiscardAction discardAction = new DiscardAction(new SelectedResourcesProvider() {
@Override
public List<FileStatus> getOnlySelectedLeaves() {
return null;
}
@Override
public List<FileStatus> getAllSelectedResources() {
return Arrays.asList(new FileStatus(GitChangeType.UNTRACKED, "test.txt"), new FileStatus(GitChangeType.UNTRACKED, "subFolder/test2.txt"));
}
}, // A mock that does nothing.
Mockito.mock(GitControllerBase.class));
discardAction.actionPerformed(null);
assertEquals(repoDir.getCanonicalFile().getAbsolutePath(), refreshedFolder.getAbsolutePath());
} finally {
FileUtils.deleteDirectory(repoDir);
}
}
use of com.oxygenxml.git.view.staging.actions.DiscardAction in project oxygen-git-client-addon by oxygenxml.
the class RefreshProjectTest method testRefreshProjectOnDiscard_3.
/**
* Refresh on submodule discard.
*
* @throws Exception
*/
@PrepareForTest({ GitAccess.class })
public void testRefreshProjectOnDiscard_3() throws Exception {
File repoDir = new File(localTestRepoPath);
repoDir.mkdirs();
File subModule = new File(localTestRepoPath, "subModule");
subModule.mkdir();
try {
GitAccess gitAccessMock = PowerMockito.mock(GitAccess.class);
Whitebox.setInternalState(GitAccess.class, "instance", gitAccessMock);
SubmoduleAccess submoduleAccess = Mockito.mock(SubmoduleAccess.class);
Mockito.doNothing().when(submoduleAccess).discardSubmodule();
PowerMockito.when(gitAccessMock.getSubmoduleAccess()).thenReturn(submoduleAccess);
DiscardAction discardAction = new DiscardAction(new SelectedResourcesProvider() {
@Override
public List<FileStatus> getOnlySelectedLeaves() {
return null;
}
@Override
public List<FileStatus> getAllSelectedResources() {
return Arrays.asList(new FileStatus(GitChangeType.SUBMODULE, "subModule"));
}
}, // A mock that does nothing.
Mockito.mock(GitControllerBase.class));
discardAction.actionPerformed(null);
assertEquals(subModule.getCanonicalFile().getAbsolutePath(), refreshedFolder.getAbsolutePath());
} finally {
FileUtils.deleteDirectory(repoDir);
}
}
use of com.oxygenxml.git.view.staging.actions.DiscardAction in project oxygen-git-client-addon by oxygenxml.
the class RefreshProjectTest method testRefreshProjectOnDiscard_1.
/**
* Refresh on discard. Only one "added" resource discarded.
*
* @throws Exception
*/
public void testRefreshProjectOnDiscard_1() throws Exception {
File repoDir = new File(localTestRepoPath);
repoDir.mkdirs();
File file = new File(localTestRepoPath, "test.txt");
file.createNewFile();
file.deleteOnExit();
try {
DiscardAction discardAction = new DiscardAction(new SelectedResourcesProvider() {
@Override
public List<FileStatus> getOnlySelectedLeaves() {
return null;
}
@Override
public List<FileStatus> getAllSelectedResources() {
return Arrays.asList(new FileStatus(GitChangeType.ADD, "test.txt"));
}
}, // A mock that does nothing.
Mockito.mock(GitControllerBase.class));
discardAction.actionPerformed(null);
assertEquals(repoDir.getCanonicalFile().getAbsolutePath(), refreshedFolder.getAbsolutePath());
} finally {
FileUtils.deleteDirectory(repoDir);
}
}
Aggregations