use of org.eclipse.egit.core.op.TagOperation in project egit by eclipse.
the class FetchGerritChangePage method createTag.
private void createTag(final RefSpec spec, final String textForTag, RevCommit commit, IProgressMonitor monitor) throws CoreException {
monitor.subTask(UIText.FetchGerritChangePage_CreatingTagTaskName);
final TagBuilder tag = new TagBuilder();
PersonIdent personIdent = new PersonIdent(repository);
tag.setTag(textForTag);
tag.setTagger(personIdent);
tag.setMessage(NLS.bind(UIText.FetchGerritChangePage_GeneratedTagMessage, spec.getSource()));
tag.setObjectId(commit);
new TagOperation(repository, tag, false).execute(monitor);
monitor.worked(1);
}
use of org.eclipse.egit.core.op.TagOperation in project egit by eclipse.
the class TagOperationTest method addTag.
@Test
public void addTag() throws Exception {
assertTrue("Tags should be empty", repository1.getRepository().getTags().isEmpty());
TagBuilder newTag = new TagBuilder();
newTag.setTag("TheNewTag");
newTag.setMessage("Well, I'm the tag");
newTag.setTagger(RawParseUtils.parsePersonIdent(TestUtils.AUTHOR));
newTag.setObjectId(repository1.getRepository().resolve("refs/heads/master"), Constants.OBJ_COMMIT);
TagOperation top = new TagOperation(repository1.getRepository(), newTag, false);
top.execute(new NullProgressMonitor());
assertFalse("Tags should not be empty", repository1.getRepository().getTags().isEmpty());
try {
top.execute(null);
fail("Expected Exception not thrown");
} catch (CoreException e) {
// expected
}
top = new TagOperation(repository1.getRepository(), newTag, true);
try {
top.execute(null);
fail("Expected Exception not thrown");
} catch (CoreException e) {
// expected
}
Ref tagRef = repository1.getRepository().getTags().get("TheNewTag");
try (RevWalk walk = new RevWalk(repository1.getRepository())) {
RevTag tag = walk.parseTag(repository1.getRepository().resolve(tagRef.getName()));
newTag.setMessage("Another message");
assertFalse("Messages should differ", tag.getFullMessage().equals(newTag.getMessage()));
top.execute(null);
tag = walk.parseTag(repository1.getRepository().resolve(tagRef.getName()));
assertTrue("Messages be same", tag.getFullMessage().equals(newTag.getMessage()));
walk.dispose();
}
}
use of org.eclipse.egit.core.op.TagOperation in project egit by eclipse.
the class AbstractVersionFinishOperation method createTag.
/**
* @param monitor
* @param head
* @param name
* @param message
* @throws CoreException
*/
protected void createTag(IProgressMonitor monitor, RevCommit head, String name, String message) throws CoreException {
TagBuilder tag = new TagBuilder();
tag.setTag(name);
tag.setTagger(new PersonIdent(repository.getRepository()));
tag.setMessage(message);
tag.setObjectId(head);
new TagOperation(repository.getRepository(), tag, false).execute(monitor);
}
use of org.eclipse.egit.core.op.TagOperation 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;
}
use of org.eclipse.egit.core.op.TagOperation 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;
}
Aggregations