use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class AddRemoteDialog method doOK.
/**
* Adds the remote as origin to the repository
*/
@Override
protected void doOK() {
super.doOK();
StoredConfig config;
try {
config = GitAccess.getInstance().getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
URIish uri = new URIish(remoteRepoTextField.getText());
remoteConfig.addURI(uri);
RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
remoteConfig.addFetchRefSpec(spec);
remoteConfig.update(config);
config.save();
String host = uri.getHost();
if (!AuthenticationInterceptor.isBound(host)) {
AuthenticationInterceptor.bind(host);
}
} catch (NoRepositorySelected | URISyntaxException | IOException e) {
LOGGER.error(e.getMessage(), e);
}
dispose();
}
use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class ShowTagsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
try {
final TagsDialog dialog = new TagsDialog();
dialog.setVisible(true);
} catch (GitAPIException | IOException | NoRepositorySelected ex) {
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(ex.getMessage(), ex);
}
}
use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class BlameManager method doBlame.
/**
* Start a blame.
*
* @param filePath The path of the file for which to compute the blame.
* @param historyController Interface to the history view.
*
* @throws IOException Unable to read from the given file.
* @throws GitAPIException Git related exceptions.
*/
public void doBlame(String filePath, HistoryController historyController) throws IOException, GitAPIException {
try {
File file = new File(GitAccess.getInstance().getWorkingCopy(), filePath);
URL url = file.toURI().toURL();
// Check if another blame is already active and dispose it.
dispose(url);
String ext = Files.getFileExtension(file.getName());
boolean isProjectExt = "xpr".equals(ext);
boolean open = PluginWorkspaceProvider.getPluginWorkspace().open(url, // Imposing the text page will open even a DITA Map inside the main editing area.
EditorPageConstants.PAGE_TEXT, // EXM-44423: open project as XML.
isProjectExt ? "text/xml" : null);
if (open) {
WSEditor editor = PluginWorkspaceProvider.getPluginWorkspace().getEditorAccess(url, PluginWorkspace.MAIN_EDITING_AREA);
if (editor != null) {
// Currently we only support text page highlights.
editor.changePage(EditorPageConstants.PAGE_TEXT);
BlamePerformer blamePerformer = new BlamePerformer();
blamePerformer.doit(GitAccess.getInstance().getRepository(), filePath, editor, historyController);
String key = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().correctURL(url.toExternalForm());
activeBlames.put(key, blamePerformer);
} else {
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("Failed to open editor: " + url);
LOGGER.error("Editor not found: " + url);
}
}
} catch (NoRepositorySelected e) {
LOGGER.error(e.getMessage(), e);
}
}
use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class RepoUtil method isFileFromRepository.
/**
* Checks if the file is from the currently loaded Git repository.
*
* @param editorLocation File location.
*
* @return <code>true</code> if the file is from the currently loaded Git repository.
* <code>false</code> otherwise.
*/
public static boolean isFileFromRepository(URL editorLocation) {
boolean toRet = false;
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);
toRet = fileInWorkPath.startsWith(selectedRepositoryPath);
} catch (NoRepositorySelected ex) {
// No repository loaded.
}
}
}
return toRet;
}
use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.
the class DiffPresenter method showConflictDiff.
/**
* Presents a 3-way diff.
*
* @param file The file for which to show the Diff.
* @param gitController Git controller.
*/
private static void showConflictDiff(FileStatus file, GitControllerBase gitController) {
try {
URL base = GitRevisionURLHandler.encodeURL(VersionIdentifier.BASE, file.getFileLocation());
URL left = null;
URL right = null;
// builds the URL for the files depending if we are in rebasing state or not
RepositoryState repositoryState = GitAccess.getInstance().getRepository().getRepositoryState();
boolean isRebase = repositoryState.equals(RepositoryState.REBASING) || repositoryState.equals(RepositoryState.REBASING_INTERACTIVE) || repositoryState.equals(RepositoryState.REBASING_MERGE) || repositoryState.equals(RepositoryState.REBASING_REBASING);
if (isRebase) {
// An unfinished rebased.
left = GitRevisionURLHandler.encodeURL(VersionIdentifier.MINE_RESOLVED, file.getFileLocation());
right = GitRevisionURLHandler.encodeURL(VersionIdentifier.MINE_ORIGINAL, file.getFileLocation());
} else {
left = GitRevisionURLHandler.encodeURL(VersionIdentifier.MINE, file.getFileLocation());
right = GitRevisionURLHandler.encodeURL(VersionIdentifier.THEIRS, file.getFileLocation());
}
String selectedRepository = OptionsManager.getInstance().getSelectedRepository();
final File localCopy = new File(selectedRepository, file.getFileLocation());
// time stamp used for detecting if the file was changed in the diff view
final long diffStartedTimeStamp = localCopy.lastModified();
Optional<JFrame> diffFrame = showDiffFrame(left, right, base, file.getFileLocation());
// checks if the file in conflict has been resolved or not after the diff
// view was closed
diffFrame.ifPresent(d -> d.addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(ComponentEvent e) {
long diffClosedTimeStamp = localCopy.lastModified();
if (diffClosedTimeStamp == diffStartedTimeStamp) {
String message = isRebase ? TRANSLATOR.getTranslation(Tags.KEEP_RESOLVED_VERSION_FOR_REBASE_CONFLICT) : TRANSLATOR.getTranslation(Tags.CHECK_IF_CONFLICT_RESOLVED);
int response = FileStatusDialog.showWarningMessageWithConfirmation(TRANSLATOR.getTranslation(Tags.CHECK_IF_CONFLICT_RESOLVED_TITLE), message, TRANSLATOR.getTranslation(Tags.RESOLVE_ANYWAY), TRANSLATOR.getTranslation(Tags.KEEP_CONFLICT));
if (response == OKCancelDialog.RESULT_OK) {
gitController.asyncResolveUsingMine(Collections.singletonList(file));
}
} else {
// Instead of requesting the file status again, we just mark it as modified.
file.setChangeType(GitChangeType.MODIFIED);
gitController.asyncAddToIndex(Collections.singletonList(file));
}
d.removeComponentListener(this);
}
}));
} catch (MalformedURLException | NoRepositorySelected e1) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(e1.getMessage(), e1);
}
}
}
Aggregations