use of com.oxygenxml.git.service.entities.FileStatus 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);
}
}
use of com.oxygenxml.git.service.entities.FileStatus 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;
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class ProjectMenuGitActionsProvider method doGitDiff.
/**
* Do Git Diff.
*/
private void doGitDiff() {
try {
UIUtil.setBusyCursor(true, Arrays.asList(prjViewInfo));
File selFile = pluginWS.getProjectManager().getSelectedFiles()[0];
String repository = RepoUtil.getRepositoryForFile(selFile);
if (repository != null) {
try {
RepoUtil.updateCurrentRepository(repository);
List<FileStatus> gitFiles = getStagedAndUnstagedFiles();
boolean wasDiffShown = false;
if (!gitFiles.isEmpty()) {
String selectedFilePath = FileUtil.rewriteSeparator(selFile.getAbsolutePath());
for (FileStatus fileStatus : gitFiles) {
if (selectedFilePath.endsWith(fileStatus.getFileLocation())) {
SwingUtilities.invokeLater(() -> DiffPresenter.showDiff(fileStatus, gitCtrl));
wasDiffShown = true;
break;
}
}
}
if (!wasDiffShown) {
SwingUtilities.invokeLater(() -> pluginWS.showInformationMessage(translator.getTranslation(Tags.NO_CHANGES)));
}
} catch (Exception e1) {
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("Repository opening failed due to: " + e1.getMessage());
LOGGER.error(e1.getMessage(), e1);
}
}
} finally {
UIUtil.setBusyCursor(false, Arrays.asList(prjViewInfo));
}
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class ProjectMenuGitActionsProvider method doPrepareCommit.
/**
* Prepare commit.
*/
private void doPrepareCommit() {
try {
UIUtil.setBusyCursor(true, Arrays.asList(prjViewInfo));
File[] selectedFiles = pluginWS.getProjectManager().getSelectedFiles();
String repository = RepoUtil.getRepositoryForFile(selectedFiles[0]);
if (repository != null) {
try {
RepoUtil.updateCurrentRepository(repository);
List<FileStatus> gitFiles = getStagedAndUnstagedFiles();
boolean canCommit = false;
for (File selFile : selectedFiles) {
String selectedFilePath = FileUtil.rewriteSeparator(selFile.getAbsolutePath());
for (FileStatus fileStatus : gitFiles) {
if (selectedFilePath.endsWith(fileStatus.getFileLocation())) {
canCommit = true;
break;
}
}
}
if (canCommit) {
SwingUtilities.invokeLater(() -> pluginWS.showView(OxygenGitPluginExtension.GIT_STAGING_VIEW, true));
stageFiles(repository);
} else {
SwingUtilities.invokeLater(() -> pluginWS.showInformationMessage(translator.getTranslation(Tags.NOTHING_TO_COMMIT)));
}
} catch (IOException e1) {
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("Repository opening failed due to: " + e1.getMessage());
LOGGER.error(e1.getMessage(), e1);
}
}
} finally {
UIUtil.setBusyCursor(false, Arrays.asList(prjViewInfo));
}
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class BranchSelectionComboTest method testKeepCurrentBranchSelectedWhenSwitchFails.
/**
* <p><b>Description:</b> when trying to switch to another branch from the branches menu
* and the checkout fails, keep the previous branch selected.</p>
* <p><b>Bug ID:</b> EXM-46826</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
public void testKeepCurrentBranchSelectedWhenSwitchFails() throws Exception {
File testDir = new File(String.format("target/test-resources/ToolbarPanelTest/%s", this.getName()));
String local = String.format("target/test-resources/ToolbarPanelTest/%s/localRepository", this.getName());
String remote = String.format("target/test-resources/ToolbarPanelTest/%s/remoteRepository", this.getName());
String LOCAL_BRANCH = "LocalBranch";
// Creates the remote repository.
createRepo(remote, local);
// Make the first commit for the local repository
File file = new File(local, "local.txt");
file.createNewFile();
setFileContent(file, "local content");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First local commit.");
// Make the first commit for the remote repository and create a branch for it.
gitAccess.setRepositorySynchronously(remote);
file = new File(remote, "remote1.txt");
file.createNewFile();
setFileContent(file, "remote content");
gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
gitAccess.commit("First remote commit.");
// Switch back to local repo and create local branch
gitAccess.setRepositorySynchronously(local);
gitAccess.createBranch(LOCAL_BRANCH);
gitAccess.fetch();
JFrame frame = new JFrame();
try {
// Init UI
GitController gitCtrl = new GitController();
GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
JComboBox<String> wcCombo = stagingPanel.getWorkingCopySelectionPanel().getWorkingCopyCombo();
String wcPath = new File(local).getAbsolutePath();
wcCombo.addItem(wcPath);
wcCombo.setSelectedItem(wcPath);
frame.getContentPane().add(stagingPanel);
frame.pack();
frame.setVisible(true);
refreshSupport.call();
flushAWT();
// Commit a change
file = new File(local, "local.txt");
setFileContent(file, "new 2");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First remote commit.");
flushAWT();
// Create local change
setFileContent(file, "new 3");
refreshSupport.call();
flushAWT();
// Try to switch to another branch
BranchSelectionCombo branchesCombo = stagingPanel.getBranchesCombo();
branchesCombo.refresh();
String currentBranch = (String) branchesCombo.getSelectedItem();
assertEquals("main", currentBranch);
// select the "Local Branch" (aka the broken one)
branchesCombo.setSelectedIndex(0);
// wait for swith dialog to appear
JDialog switchBranchDialog = TestUtil.waitForDialog(translator.getTranslation(Tags.SWITCH_BRANCH), this);
JButton yesButton = TestUtil.findButton(switchBranchDialog, translator.getTranslation(Tags.MOVE_CHANGES));
yesButton.doClick();
flushAWT();
String currentBranchAfterSwitchFailed = (String) branchesCombo.getSelectedItem();
assertEquals("main", currentBranchAfterSwitchFailed);
} finally {
frame.setVisible(false);
frame.dispose();
FileSystemUtil.deleteRecursivelly(testDir);
}
}
Aggregations