Search in sources :

Example 1 with RepositoryUtil

use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.

the class CommitOperation method setAuthorAndCommitter.

private void setAuthorAndCommitter(CommitCommand commitCommand) throws TeamException {
    final Date commitDate = new Date();
    final TimeZone timeZone = TimeZone.getDefault();
    final PersonIdent enteredAuthor = RawParseUtils.parsePersonIdent(author);
    final PersonIdent enteredCommitter = RawParseUtils.parsePersonIdent(committer);
    if (enteredAuthor == null)
        throw new TeamException(NLS.bind(CoreText.CommitOperation_errorParsingPersonIdent, author));
    if (enteredCommitter == null)
        throw new TeamException(NLS.bind(CoreText.CommitOperation_errorParsingPersonIdent, committer));
    PersonIdent authorIdent;
    if (repo.getRepositoryState().equals(RepositoryState.CHERRY_PICKING_RESOLVED)) {
        try (RevWalk rw = new RevWalk(repo)) {
            ObjectId cherryPickHead = repo.readCherryPickHead();
            authorIdent = rw.parseCommit(cherryPickHead).getAuthorIdent();
        } catch (IOException e) {
            Activator.logError(CoreText.CommitOperation_ParseCherryPickCommitFailed, e);
            throw new IllegalStateException(e);
        }
    } else {
        authorIdent = new PersonIdent(enteredAuthor, commitDate, timeZone);
    }
    final PersonIdent committerIdent = new PersonIdent(enteredCommitter, commitDate, timeZone);
    if (amending) {
        RepositoryUtil repoUtil = Activator.getDefault().getRepositoryUtil();
        RevCommit headCommit = repoUtil.parseHeadCommit(repo);
        if (headCommit != null) {
            final PersonIdent headAuthor = headCommit.getAuthorIdent();
            authorIdent = new PersonIdent(enteredAuthor, headAuthor.getWhen(), headAuthor.getTimeZone());
        }
    }
    commitCommand.setAuthor(authorIdent);
    commitCommand.setCommitter(committerIdent);
}
Also used : TeamException(org.eclipse.team.core.TeamException) TimeZone(java.util.TimeZone) PersonIdent(org.eclipse.jgit.lib.PersonIdent) ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Date(java.util.Date) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with RepositoryUtil

use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.

the class CommitBlobStorage method getFullPath.

@Override
public IPath getFullPath() {
    final RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
    IPath repoPath = new Path(repositoryUtil.getRepositoryName(db));
    String pathString = // $NON-NLS-1$
    super.getFullPath().toPortableString() + " " + Utils.getShortObjectId(commit.getId());
    return repoPath.append(Path.fromPortableString(pathString));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil)

Example 3 with RepositoryUtil

use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.

the class IndexBlobStorage method getFullPath.

@Override
public IPath getFullPath() {
    final RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
    IPath repoPath = new Path(repositoryUtil.getRepositoryName(db));
    // $NON-NLS-1$
    String pathString = super.getFullPath().toPortableString() + " index";
    return repoPath.append(Path.fromPortableString(pathString));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil)

Example 4 with RepositoryUtil

use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.

the class GitRepositoriesViewBranchHandlingTest method setUp.

@Before
public void setUp() throws Exception {
    clearView();
    setVerboseBranchMode(false);
    repositoryFile = createProjectAndCommitToRepository();
    remoteRepositoryFile = createRemoteRepository(repositoryFile);
    // now let's clone the remote repository
    final URIish uri = new URIish(remoteRepositoryFile.getPath());
    final File workdir = new File(getTestDirectory(), "Cloned");
    CloneOperation op = new CloneOperation(uri, true, null, workdir, "refs/heads/master", "origin", 0);
    op.run(null);
    clonedRepositoryFile = new File(workdir, Constants.DOT_GIT);
    RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
    repositoryUtil.addConfiguredRepository(repositoryFile);
    repositoryUtil.addConfiguredRepository(remoteRepositoryFile);
    repositoryUtil.addConfiguredRepository(clonedRepositoryFile);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) File(java.io.File) CloneOperation(org.eclipse.egit.core.op.CloneOperation) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) Before(org.junit.Before)

Example 5 with RepositoryUtil

use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.

the class ExistingOrNewPage method createControl.

@Override
public void createControl(Composite parent) {
    final RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
    Composite main = new Composite(parent, SWT.NONE);
    // use zero spacing to save some real estate here
    GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(main);
    final Button internalModeButton = new Button(main, SWT.CHECK);
    internalModeButton.setText(UIText.ExistingOrNewPage_InternalModeCheckbox);
    internalModeButton.setToolTipText(UIText.ExistingOrNewPage_CreationInWorkspaceWarningTooltip);
    internalModeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            internalMode = internalModeButton.getSelection();
            updateControls();
        }
    });
    externalComposite = new Composite(main, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(externalComposite);
    externalComposite.setLayout(new GridLayout(3, false));
    new Label(externalComposite, SWT.NONE).setText(UIText.ExistingOrNewPage_ExistingRepositoryLabel);
    final Combo existingRepoCombo = new Combo(externalComposite, SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(existingRepoCombo);
    final ComboViewer v = new ComboViewer(existingRepoCombo);
    v.setContentProvider(new RepoComboContentProvider());
    v.setLabelProvider(new RepoComboLabelProvider());
    v.setInput(new Object());
    // the default ViewerSorter seems to do the right thing
    // i.e. sort as String
    v.setComparator(new ViewerComparator());
    existingRepoCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedRepository = null;
            IStructuredSelection sel = (IStructuredSelection) v.getSelection();
            setRepository((Repository) sel.getFirstElement());
            updateControls();
        }
    });
    Button createRepoWizard = new Button(externalComposite, SWT.PUSH);
    createRepoWizard.setText(UIText.ExistingOrNewPage_CreateRepositoryButton);
    createRepoWizard.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            NewRepositoryWizard wiz = new NewRepositoryWizard(true);
            if (new WizardDialog(getShell(), wiz).open() == Window.OK) {
                v.refresh();
                selectedRepository = wiz.getCreatedRepository();
                v.setSelection(new StructuredSelection(selectedRepository));
                updateControls();
            }
        }
    });
    new Label(externalComposite, SWT.NONE).setText(UIText.ExistingOrNewPage_WorkingDirectoryLabel);
    workDir = new Text(externalComposite, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(workDir);
    GridDataFactory.fillDefaults().applyTo(workDir);
    // leave the space between the "Create" and "Browse" buttons empty (i.e.
    // do not fill to the right border
    new Label(externalComposite, SWT.NONE);
    new Label(externalComposite, SWT.NONE).setText(UIText.ExistingOrNewPage_RelativePathLabel);
    relPath = new Text(externalComposite, SWT.BORDER);
    relPath.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            updateControls();
        }
    });
    GridDataFactory.fillDefaults().grab(true, false).applyTo(relPath);
    browseRepository = new Button(externalComposite, SWT.PUSH);
    browseRepository.setEnabled(false);
    browseRepository.setText(UIText.ExistingOrNewPage_BrowseRepositoryButton);
    browseRepository.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dlg = new DirectoryDialog(getShell());
            dlg.setMessage(UIText.ExistingOrNewPage_title);
            dlg.setFilterPath(selectedRepository.getWorkTree().getPath());
            String directory = dlg.open();
            if (directory != null) {
                setRelativePath(directory);
                updateControls();
            }
        }
    });
    Table projectMoveTable = new Table(externalComposite, SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK | SWT.BORDER);
    projectMoveViewer = new CheckboxTableViewer(projectMoveTable);
    GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(projectMoveTable);
    TableColumn tc;
    tc = new TableColumn(projectMoveTable, SWT.NONE);
    tc.setText(UIText.ExistingOrNewPage_ProjectNameColumnHeader);
    tc.setWidth(100);
    tc = new TableColumn(projectMoveTable, SWT.NONE);
    tc.setText(UIText.ExistingOrNewPage_CurrentLocationColumnHeader);
    tc.setWidth(250);
    tc = new TableColumn(projectMoveTable, SWT.NONE);
    tc.setText(UIText.ExistingOrNewPage_NewLocationTargetHeader);
    tc.setWidth(350);
    projectMoveTable.setHeaderVisible(true);
    projectMoveViewer.setContentProvider(ArrayContentProvider.getInstance());
    projectMoveViewer.setLabelProvider(moveProjectsLabelProvider);
    projectMoveViewer.setInput(myWizard.projects);
    projectMoveViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            updateControls();
        }
    });
    TableItem[] children = projectMoveViewer.getTable().getItems();
    for (int i = 0; i < children.length; i++) {
        TableItem item = children[i];
        IProject data = (IProject) item.getData();
        RepositoryFinder repositoryFinder = new RepositoryFinder(data);
        repositoryFinder.setFindInChildren(false);
        try {
            Collection<RepositoryMapping> find = repositoryFinder.find(new NullProgressMonitor());
            if (find.size() != 1)
                item.setChecked(true);
        } catch (CoreException e1) {
            item.setText(2, e1.getMessage());
        }
    }
    parentRepoComposite = new Composite(main, SWT.NONE);
    parentRepoComposite.setLayout(new GridLayout(3, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(parentRepoComposite);
    tree = new Tree(parentRepoComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
    viewer = new CheckboxTreeViewer(tree);
    tree.setHeaderVisible(true);
    tree.setLayout(new GridLayout());
    tree.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(3, 1).create());
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked()) {
                ProjectAndRepo checkable = (ProjectAndRepo) event.getElement();
                for (TreeItem ti : tree.getItems()) {
                    if (ti.getItemCount() > 0 || ((ProjectAndRepo) ti.getData()).getRepo().equals(// $NON-NLS-1$
                    ""))
                        ti.setChecked(false);
                    for (TreeItem subTi : ti.getItems()) {
                        IProject project = ((ProjectAndRepo) subTi.getData()).getProject();
                        if (checkable.getProject() != null && !subTi.getData().equals(checkable) && checkable.getProject().equals(project))
                            subTi.setChecked(false);
                    }
                }
            }
        }
    });
    TreeColumn c1 = new TreeColumn(tree, SWT.NONE);
    c1.setText(UIText.ExistingOrNewPage_HeaderProject);
    c1.setWidth(100);
    TreeColumn c2 = new TreeColumn(tree, SWT.NONE);
    c2.setText(UIText.ExistingOrNewPage_HeaderLocation);
    c2.setWidth(400);
    TreeColumn c3 = new TreeColumn(tree, SWT.NONE);
    c3.setText(UIText.ExistingOrNewPage_HeaderRepository);
    c3.setWidth(200);
    boolean allProjectsInExistingRepos = true;
    for (IProject project : myWizard.projects) {
        RepositoryFinder repositoryFinder = new RepositoryFinder(project);
        repositoryFinder.setFindInChildren(false);
        try {
            Collection<RepositoryMapping> mappings;
            mappings = repositoryFinder.find(new NullProgressMonitor());
            Iterator<RepositoryMapping> mi = mappings.iterator();
            RepositoryMapping m = mi.hasNext() ? mi.next() : null;
            if (m == null) {
                // no mapping found, enable repository creation
                TreeItem treeItem = new TreeItem(tree, SWT.NONE);
                updateProjectTreeItem(treeItem, project);
                treeItem.setText(1, project.getLocation().toOSString());
                // $NON-NLS-1$
                treeItem.setText(2, "");
                // $NON-NLS-1$
                treeItem.setData(new ProjectAndRepo(project, ""));
                allProjectsInExistingRepos = false;
            } else if (!mi.hasNext()) {
                // exactly one mapping found
                IPath path = m.getGitDirAbsolutePath();
                if (path != null) {
                    TreeItem treeItem = new TreeItem(tree, SWT.NONE);
                    updateProjectTreeItem(treeItem, project);
                    treeItem.setText(1, project.getLocation().toOSString());
                    fillTreeItemWithGitDirectory(m, treeItem, path, false);
                    treeItem.setData(new ProjectAndRepo(project, path.toOSString()));
                    treeItem.setChecked(true);
                }
            } else {
                IPath path = m.getGitDirAbsolutePath();
                if (path != null) {
                    TreeItem treeItem = new TreeItem(tree, SWT.NONE);
                    updateProjectTreeItem(treeItem, project);
                    treeItem.setText(1, project.getLocation().toOSString());
                    // $NON-NLS-1$
                    treeItem.setData(new ProjectAndRepo(project, ""));
                    TreeItem treeItem2 = new TreeItem(treeItem, SWT.NONE);
                    updateProjectTreeItem(treeItem2, project);
                    fillTreeItemWithGitDirectory(m, treeItem2, path, true);
                    treeItem2.setData(new ProjectAndRepo(project, path.toOSString()));
                    while (mi.hasNext()) {
                        // fill in additional mappings
                        m = mi.next();
                        path = m.getGitDirAbsolutePath();
                        if (path != null) {
                            treeItem2 = new TreeItem(treeItem, SWT.NONE);
                            updateProjectTreeItem(treeItem2, project);
                            fillTreeItemWithGitDirectory(m, treeItem2, path, true);
                            treeItem2.setData(new ProjectAndRepo(m.getContainer().getProject(), path.toOSString()));
                        }
                    }
                    treeItem.setExpanded(true);
                }
                allProjectsInExistingRepos = false;
            }
        } catch (CoreException e) {
            TreeItem treeItem2 = new TreeItem(tree, SWT.BOLD | SWT.ITALIC);
            treeItem2.setText(e.getMessage());
        }
    }
    createRepo = new Button(parentRepoComposite, SWT.PUSH);
    createRepo.setLayoutData(GridDataFactory.fillDefaults().create());
    createRepo.setText(UIText.ExistingOrNewPage_CreateButton);
    createRepo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            File gitDir = new File(repositoryToCreate.getText(), Constants.DOT_GIT);
            try {
                Repository repository = FileRepositoryBuilder.create(gitDir);
                repository.create();
                for (IProject project : getProjects(false).keySet()) {
                    // 
                    if (// $NON-NLS-1$
                    !gitDir.toString().contains(".."))
                        project.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
                }
                util.addConfiguredRepository(gitDir);
            } catch (IOException e1) {
                String msg = NLS.bind(UIText.ExistingOrNewPage_ErrorFailedToCreateRepository, gitDir.toString());
                org.eclipse.egit.ui.Activator.handleError(msg, e1, true);
            } catch (CoreException e2) {
                String msg = NLS.bind(UIText.ExistingOrNewPage_ErrorFailedToRefreshRepository, gitDir);
                org.eclipse.egit.ui.Activator.handleError(msg, e2, true);
            }
            for (TreeItem ti : tree.getSelection()) {
                IPath projectPath = new Path(ti.getText(1));
                IPath gitPath = new Path(gitDir.toString());
                IPath relative = gitPath.makeRelativeTo(projectPath);
                ti.setText(2, relative.toOSString());
                ((ProjectAndRepo) ti.getData()).repo = gitDir.toString();
                ti.setChecked(true);
            }
            updateControls();
        }
    });
    repositoryToCreate = new Text(parentRepoComposite, SWT.SINGLE | SWT.BORDER);
    repositoryToCreate.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(1, 1).create());
    repositoryToCreate.addListener(SWT.Modify, new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (repositoryToCreate.getText().equals("")) {
                // $NON-NLS-1$
                createRepo.setEnabled(false);
                return;
            }
            IPath fromOSString = Path.fromOSString(repositoryToCreate.getText());
            createRepo.setEnabled(minumumPath.matchingFirstSegments(fromOSString) == fromOSString.segmentCount());
        }
    });
    dotGitSegment = new Label(parentRepoComposite, SWT.NONE);
    dotGitSegment.setEnabled(false);
    dotGitSegment.setText(File.separatorChar + Constants.DOT_GIT);
    dotGitSegment.setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).create());
    tree.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tree.select((TreeItem) e.item);
            updateControls();
        }
    });
    Dialog.applyDialogFont(main);
    setControl(main);
    if (allProjectsInExistingRepos) {
        internalMode = true;
        internalModeButton.setSelection(true);
        updateControls();
    }
}
Also used : CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) TreeItem(org.eclipse.swt.widgets.TreeItem) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) RepositoryFinder(org.eclipse.egit.core.project.RepositoryFinder) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Combo(org.eclipse.swt.widgets.Combo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) RevTree(org.eclipse.jgit.revwalk.RevTree) Tree(org.eclipse.swt.widgets.Tree) IPath(org.eclipse.core.runtime.IPath) TableColumn(org.eclipse.swt.widgets.TableColumn) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CoreException(org.eclipse.core.runtime.CoreException) ComboViewer(org.eclipse.jface.viewers.ComboViewer) File(java.io.File) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) GridLayout(org.eclipse.swt.layout.GridLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) NewRepositoryWizard(org.eclipse.egit.ui.internal.repository.NewRepositoryWizard) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) Repository(org.eclipse.jgit.lib.Repository) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

RepositoryUtil (org.eclipse.egit.core.RepositoryUtil)16 File (java.io.File)8 IOException (java.io.IOException)6 IPath (org.eclipse.core.runtime.IPath)6 Path (org.eclipse.core.runtime.Path)5 Repository (org.eclipse.jgit.lib.Repository)4 IProject (org.eclipse.core.resources.IProject)3 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 URIish (org.eclipse.jgit.transport.URIish)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 CloneOperation (org.eclipse.egit.core.op.CloneOperation)2 RepositoryNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryNode)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1