Search in sources :

Example 41 with RepositoryMapping

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);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IResource(org.eclipse.core.resources.IResource)

Example 42 with RepositoryMapping

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;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) GridLayout(org.eclipse.swt.layout.GridLayout) Repository(org.eclipse.jgit.lib.Repository) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 43 with RepositoryMapping

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);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) GitMergeEditorInput(org.eclipse.egit.ui.internal.merge.GitMergeEditorInput) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) AbortRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.AbortRebaseCommand) CompareEditorInput(org.eclipse.compare.CompareEditorInput) CoreException(org.eclipse.core.runtime.CoreException) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) MergeModeDialog(org.eclipse.egit.ui.internal.merge.MergeModeDialog) SkipRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.SkipRebaseCommand)

Example 44 with RepositoryMapping

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;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) ObjectId(org.eclipse.jgit.lib.ObjectId) Calendar(java.util.Calendar) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 45 with RepositoryMapping

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) Matchers.anyString(org.mockito.Matchers.anyString) GitProjectData(org.eclipse.egit.core.project.GitProjectData) GitProvider(org.eclipse.egit.core.GitProvider)

Aggregations

RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)87 Repository (org.eclipse.jgit.lib.Repository)40 IResource (org.eclipse.core.resources.IResource)31 IProject (org.eclipse.core.resources.IProject)23 IPath (org.eclipse.core.runtime.IPath)20 IOException (java.io.IOException)18 File (java.io.File)17 CoreException (org.eclipse.core.runtime.CoreException)15 IFile (org.eclipse.core.resources.IFile)12 Path (org.eclipse.core.runtime.Path)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 GitProjectData (org.eclipse.egit.core.project.GitProjectData)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 HashSet (java.util.HashSet)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 RevWalk (org.eclipse.jgit.revwalk.RevWalk)6 HashMap (java.util.HashMap)5