Search in sources :

Example 1 with CreateTagDialog

use of org.eclipse.egit.ui.internal.dialogs.CreateTagDialog in project egit by eclipse.

the class CreateTagHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    List<RepositoryCommit> commits = getCommits(event);
    if (commits.size() == 1) {
        RepositoryCommit commit = commits.get(0);
        Repository repository = commit.getRepository();
        CreateTagDialog dialog = new CreateTagDialog(HandlerUtil.getActiveShellChecked(event), commit.getRevCommit().getId(), repository);
        if (dialog.open() != Window.OK)
            return null;
        final TagBuilder tag = new TagBuilder();
        PersonIdent personIdent = new PersonIdent(repository);
        String tagName = dialog.getTagName();
        tag.setTag(tagName);
        tag.setTagger(personIdent);
        tag.setMessage(dialog.getTagMessage());
        tag.setObjectId(commit.getRevCommit());
        try {
            new TagOperation(repository, tag, dialog.shouldOverWriteTag()).execute(new NullProgressMonitor());
        } catch (CoreException e) {
            throw new ExecutionException(e.getMessage(), e);
        }
        if (dialog.shouldStartPushWizard())
            PushTagsWizard.openWizardDialog(repository, tagName);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) CreateTagDialog(org.eclipse.egit.ui.internal.dialogs.CreateTagDialog) PersonIdent(org.eclipse.jgit.lib.PersonIdent) TagOperation(org.eclipse.egit.core.op.TagOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) TagBuilder(org.eclipse.jgit.lib.TagBuilder)

Example 2 with CreateTagDialog

use of org.eclipse.egit.ui.internal.dialogs.CreateTagDialog in project egit by eclipse.

the class CreateTagOnCommitHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ObjectId commitId = getSelectedCommitId(event);
    final Repository repo = getRepository(event);
    CreateTagDialog dialog = new CreateTagDialog(HandlerUtil.getActiveShellChecked(event), commitId, repo);
    if (dialog.open() != Window.OK)
        return null;
    final TagBuilder tag = new TagBuilder();
    PersonIdent personIdent = new PersonIdent(repo);
    String tagName = dialog.getTagName();
    tag.setTag(tagName);
    tag.setTagger(personIdent);
    tag.setMessage(dialog.getTagMessage());
    tag.setObjectId(commitId, Constants.OBJ_COMMIT);
    try {
        new TagOperation(repo, tag, dialog.shouldOverWriteTag()).execute(new NullProgressMonitor());
    } catch (CoreException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
    if (dialog.shouldStartPushWizard())
        PushTagsWizard.openWizardDialog(repo, tagName);
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) ObjectId(org.eclipse.jgit.lib.ObjectId) CreateTagDialog(org.eclipse.egit.ui.internal.dialogs.CreateTagDialog) PersonIdent(org.eclipse.jgit.lib.PersonIdent) TagOperation(org.eclipse.egit.core.op.TagOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) TagBuilder(org.eclipse.jgit.lib.TagBuilder)

Example 3 with CreateTagDialog

use of org.eclipse.egit.ui.internal.dialogs.CreateTagDialog in project egit by eclipse.

the class TagActionHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Repository repo = getRepository(true, event);
    if (repo == null)
        return null;
    if (!repo.getRepositoryState().canCheckout()) {
        MessageDialog.openError(getShell(event), UIText.TagAction_cannotCheckout, NLS.bind(UIText.TagAction_repositoryState, repo.getRepositoryState().getDescription()));
        return null;
    }
    String currentBranchName;
    try {
        currentBranchName = repo.getBranch();
    } catch (IOException e) {
        Activator.handleError(UIText.TagAction_cannotGetBranchName, e, true);
        return null;
    }
    CreateTagDialog dialog = new CreateTagDialog(getShell(event), currentBranchName, repo);
    if (dialog.open() != IDialogConstants.OK_ID)
        return null;
    final TagBuilder tag = new TagBuilder();
    PersonIdent personIdent = new PersonIdent(repo);
    final String tagName = dialog.getTagName();
    tag.setTag(tagName);
    tag.setTagger(personIdent);
    tag.setMessage(dialog.getTagMessage());
    RevObject tagTarget;
    try {
        tagTarget = getTagTarget(repo, dialog.getTagCommit());
    } catch (IOException e1) {
        Activator.handleError(UIText.TagAction_unableToResolveHeadObjectId, e1, true);
        return null;
    }
    tag.setObjectId(tagTarget);
    String tagJobName = NLS.bind(UIText.TagAction_creating, tagName);
    final boolean shouldMoveTag = dialog.shouldOverWriteTag();
    Job tagJob = new Job(tagJobName) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                new TagOperation(repo, tag, shouldMoveTag).execute(monitor);
            } catch (CoreException e) {
                return Activator.createErrorStatus(UIText.TagAction_taggingFailed, e);
            } finally {
                GitLightweightDecorator.refresh();
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.TAG.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    if (dialog.shouldStartPushWizard()) {
        tagJob.addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent jobChangeEvent) {
                if (jobChangeEvent.getResult().isOK())
                    PushTagsWizard.openWizardDialog(repo, tagName);
            }
        });
    }
    tagJob.setUser(true);
    tagJob.schedule();
    return null;
}
Also used : RevObject(org.eclipse.jgit.revwalk.RevObject) TagOperation(org.eclipse.egit.core.op.TagOperation) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IOException(java.io.IOException) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) CreateTagDialog(org.eclipse.egit.ui.internal.dialogs.CreateTagDialog) PersonIdent(org.eclipse.jgit.lib.PersonIdent) RevObject(org.eclipse.jgit.revwalk.RevObject) Job(org.eclipse.core.runtime.jobs.Job) TagBuilder(org.eclipse.jgit.lib.TagBuilder)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)3 TagOperation (org.eclipse.egit.core.op.TagOperation)3 CreateTagDialog (org.eclipse.egit.ui.internal.dialogs.CreateTagDialog)3 PersonIdent (org.eclipse.jgit.lib.PersonIdent)3 Repository (org.eclipse.jgit.lib.Repository)3 TagBuilder (org.eclipse.jgit.lib.TagBuilder)3 ExecutionException (org.eclipse.core.commands.ExecutionException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IOException (java.io.IOException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 RepositoryCommit (org.eclipse.egit.ui.internal.commit.RepositoryCommit)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 RevObject (org.eclipse.jgit.revwalk.RevObject)1