use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class RebaseInteractiveView method newInput.
private void newInput(Object o, boolean force) {
if (o == null)
return;
if (isViewInputDerivableFromSelection(o)) {
o = ((StructuredSelection) o).getFirstElement();
}
Repository repo = null;
if (o instanceof RepositoryTreeNode<?>) {
repo = ((RepositoryTreeNode) o).getRepository();
} else if (o instanceof Repository) {
repo = (Repository) o;
} else {
IResource resource = AdapterUtils.adaptToAnyResource(o);
if (resource != null) {
RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
if (mapping == null) {
return;
}
repo = mapping.getRepository();
}
}
if (repo == null) {
repo = AdapterUtils.adapt(o, Repository.class);
}
if (repo == null && !force) {
return;
}
currentRepository = repo;
showRepository(repo);
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitProjectPropertyPage method createContents.
@Override
protected Control createContents(Composite parent) {
// this page just shows read-only information to the user, no
// default/apply buttons needed
noDefaultAndApplyButton();
final Composite composite = new Composite(parent, SWT.NULL);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
gitDir = createLabeledReadOnlyText(composite, UIText.GitProjectPropertyPage_LabelGitDir);
workDir = createLabeledReadOnlyText(composite, UIText.GitProjectPropertyPage_LabelWorkdir);
branch = createLabeledReadOnlyText(composite, UIText.GitProjectPropertyPage_LabelBranch);
state = createLabeledReadOnlyText(composite, UIText.GitProjectPropertyPage_LabelState);
// Get the project that is the source of this property page
IProject project = null;
final IAdaptable element = getElement();
if (element instanceof IResource) {
project = ((IResource) element).getProject();
} else {
IResource adapter = AdapterUtils.adapt(element, IResource.class);
if (adapter != null) {
project = adapter.getProject();
}
}
RepositoryMapping mapping = RepositoryMapping.getMapping(project);
if (mapping != null) {
Repository repository = mapping.getRepository();
if (repository != null) {
try {
createHeadLink(repository, composite);
fillValues(repository);
} catch (IOException e) {
if (GitTraceLocation.UI.isActive())
GitTraceLocation.getTrace().trace(GitTraceLocation.UI.getLocation(), e.getMessage(), e);
}
}
}
return composite;
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class RebaseResultDialog method buttonPressed.
@Override
protected void buttonPressed(int buttonId) {
// store the preference to hide these dialogs
if (toggleButton != null)
Activator.getDefault().getPreferenceStore().setValue(UIPreferences.SHOW_REBASE_CONFIRM, !toggleButton.getSelection());
if (buttonId == IDialogConstants.OK_ID) {
if (result.getStatus() != Status.STOPPED) {
super.buttonPressed(buttonId);
return;
}
if (startMergeButton.getSelection()) {
super.buttonPressed(buttonId);
// open the merge tool
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : projects) {
RepositoryMapping mapping = RepositoryMapping.getMapping(project);
if (mapping != null && mapping.getRepository().equals(repo)) {
try {
// make sure to refresh before opening the merge
// tool
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
Activator.handleError(e.getMessage(), e, false);
}
}
}
List<IPath> locationList = new ArrayList<>();
IPath repoWorkdirPath = new Path(repo.getWorkTree().getPath());
for (String repoPath : conflictPaths) {
IPath location = repoWorkdirPath.append(repoPath);
locationList.add(location);
}
IPath[] locations = locationList.toArray(new IPath[locationList.size()]);
int mergeMode = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.MERGE_MODE);
CompareEditorInput input;
if (mergeMode == 0) {
MergeModeDialog dlg = new MergeModeDialog(getParentShell());
if (dlg.open() != Window.OK)
return;
input = new GitMergeEditorInput(dlg.useWorkspace(), locations);
} else {
boolean useWorkspace = mergeMode == 1;
input = new GitMergeEditorInput(useWorkspace, locations);
}
CompareUI.openCompareEditor(input);
return;
} else if (skipCommitButton.getSelection()) {
// skip the rebase
SkipRebaseCommand skipCommand = new SkipRebaseCommand();
execute(skipCommand);
} else if (abortRebaseButton.getSelection()) {
// abort the rebase
AbortRebaseCommand abortCommand = new AbortRebaseCommand();
execute(abortCommand);
} else if (doNothingButton.getSelection()) {
// nothing
}
}
super.buttonPressed(buttonId);
}
use of org.eclipse.egit.core.project.RepositoryMapping in project eclipse.platform.releng by eclipse.
the class GitCopyrightAdapter method getLastModifiedYear.
@Override
public int getLastModifiedYear(IFile file, IProgressMonitor monitor) throws CoreException {
try {
// $NON-NLS-1$
monitor.beginTask("Fetching logs from Git", 100);
final RepositoryMapping mapping = RepositoryMapping.getMapping(file);
if (mapping != null) {
final Repository repo = mapping.getRepository();
if (repo != null) {
RevWalk walk = null;
try {
final ObjectId start = repo.resolve(Constants.HEAD);
walk = new RevWalk(repo);
walk.setTreeFilter(AndTreeFilter.create(PathFilter.create(mapping.getRepoRelativePath(file)), TreeFilter.ANY_DIFF));
walk.markStart(walk.lookupCommit(start));
final RevCommit commit = walk.next();
if (commit != null) {
if (filterString != null && commit.getFullMessage().toLowerCase().indexOf(filterString) != -1) {
// the last update was a copyright check in - ignore
return 0;
}
// $NON-NLS-1$
boolean isSWT = file.getProject().getName().startsWith("org.eclipse.swt");
String logComment = commit.getFullMessage();
if (isSWT && (logComment.indexOf("restore HEAD after accidental deletion") != -1 || logComment.indexOf("fix permission of files") != -1)) {
// ignore commits with above comments
return 0;
}
// $NON-NLS-1$
boolean isPlatform = file.getProject().getName().equals("eclipse.platform");
if (isPlatform && (logComment.indexOf("Merge in ant and update from origin/master") != -1 || logComment.indexOf("Fixed bug 381684: Remove update from repository and map files") != -1)) {
// ignore commits with above comments
return 0;
}
final Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(0);
calendar.add(Calendar.SECOND, commit.getCommitTime());
return calendar.get(Calendar.YEAR);
}
} catch (final IOException e) {
throw new CoreException(new Status(IStatus.ERROR, RelEngPlugin.ID, 0, NLS.bind("An error occured when processing {0}", file.getName()), e));
} finally {
if (walk != null)
walk.close();
}
}
}
} finally {
monitor.done();
}
return -1;
}
use of org.eclipse.egit.core.project.RepositoryMapping in project jbosstools-openshift by jbosstools.
the class ResourceMocks method createGitSharedProject.
public static org.eclipse.core.resources.IProject createGitSharedProject(String name, String gitRemoteUri) throws CoreException {
org.eclipse.core.resources.IProject project = createEclipseProject(name);
when(project.getPersistentProperty(TeamPlugin.PROVIDER_PROP_KEY)).thenReturn(GitProvider.ID);
when(project.getWorkingLocation(any())).thenReturn(new Path(ResourcesPlugin.getWorkspace().getRoot().getFullPath().toString()));
StoredConfig config = mock(StoredConfig.class);
when(config.getSubsections("remote")).thenReturn(new HashSet<String>(Arrays.asList("origin")));
when(config.getStringList(any(), any(), any())).thenReturn(new String[] { gitRemoteUri });
when(config.getStringList("remote", "origin", "url")).thenReturn(new String[] { gitRemoteUri });
Repository repository = mock(Repository.class);
when(repository.getConfig()).thenReturn(config);
RepositoryMapping mapping = mock(RepositoryMapping.class);
when(mapping.getRepository()).thenReturn(repository);
GitProjectData data = mock(GitProjectData.class);
when(data.getRepositoryMapping(project)).thenReturn(mapping);
GitProvider repositoryProvider = mock(GitProvider.class);
when(repositoryProvider.getID()).thenReturn(GitProvider.ID);
when(repositoryProvider.getData()).thenReturn(data);
when(project.getSessionProperty(TeamPlugin.PROVIDER_PROP_KEY)).thenReturn(repositoryProvider);
return project;
}
Aggregations