Example usage for org.eclipse.jgit.lib TagBuilder setObjectId

List of usage examples for org.eclipse.jgit.lib TagBuilder setObjectId

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib TagBuilder setObjectId.

Prototype

public void setObjectId(AnyObjectId obj, int objType) 

Source Link

Document

Set the object this tag refers to, and its type.

Usage

From source file:org.commonjava.gitwrap.BareGitRepository.java

License:Open Source License

public BareGitRepository createTag(final String tagSource, final String tagName, final String message,
        final boolean force) throws GitWrapException {
    try {// www.j  a va2 s  .co m
        final ObjectId src = repository.resolve(tagSource);
        if (src == null) {
            throw new GitWrapException("Cannot resolve tag-source: %s", tagSource);
        }

        if (!force && repository.resolve(tagName) != null) {
            throw new GitWrapException("Tag: %s already exists!", tagName);
        }

        String dest = tagName;
        if (!dest.startsWith(Constants.R_TAGS)) {
            dest = Constants.R_TAGS + tagName;
        }

        final String tagShort = dest.substring(Constants.R_TAGS.length());

        final ObjectLoader sourceLoader = repository.open(src);
        final ObjectInserter inserter = repository.newObjectInserter();

        final TagBuilder tag = new TagBuilder();
        tag.setTag(tagShort);
        tag.setTagger(new PersonIdent(repository));
        tag.setObjectId(src, sourceLoader.getType());
        tag.setMessage(message);

        final ObjectId tagId = inserter.insert(tag);
        tag.setTagId(tagId);

        final String refName = Constants.R_TAGS + tag.getTag();

        final RefUpdate tagRef = repository.updateRef(refName);
        tagRef.setNewObjectId(tag.getTagId());
        tagRef.setForceUpdate(force);
        tagRef.setRefLogMessage("Tagging source: " + src.name() + " as " + tagName, false);

        final Result updateResult = tagRef.update();

        switch (updateResult) {
        case NEW:
        case FAST_FORWARD:
        case FORCED: {
            break;
        }
        case REJECTED: {
            throw new GitWrapException("Tag already exists: %s", tagName);
        }
        default: {
            throw new GitWrapException("Cannot lock tag: %s", tagName);
        }
        }
    } catch (final IOException e) {
        throw new GitWrapException("Failed to add tag: %s", e, e.getMessage());
    }

    return this;
}

From source file:org.eclipse.egit.core.test.op.TagOperationTest.java

License:Open Source License

@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 {/*from  www .  ja va  2s .  c om*/
        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");
    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()));
}

From source file:org.eclipse.egit.ui.test.team.actions.BranchAndResetActionTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);//  ww w  .  ja  v  a2s .com
    touchAndSubmit(null);

    RepositoriesViewLabelProvider provider = new RepositoriesViewLabelProvider();
    LOCAL_BRANCHES = provider.getText(new LocalNode(new RepositoryNode(null, repo), repo));
    TAGS = provider.getText(new TagsNode(new RepositoryNode(null, repo), repo));
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.CommitActionTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    // TODO delete the second project for the time being (.gitignore is
    // currently not hiding the .project file from commit)
    ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2).delete(false, null);

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);//from www.  j  a  v a 2s. com
    touchAndSubmit(null);

    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.CompareActionsTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    commitOfTag = tag.getObjectId();//from   ww w  .  j  a va  2 s . co m
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);
    touchAndSubmit(null);

    RepositoriesViewLabelProvider provider = GitRepositoriesViewTestUtils.createLabelProvider();
    // LOCAL_BRANCHES = provider.getText(new LocalNode(new RepositoryNode(
    // null, repo), repo));
    TAGS = provider.getText(new TagsNode(new RepositoryNode(null, repo), repo));
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.CreatePatchActionTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
    File gitDir = createProjectAndCommitToRepository();
    repo = new FileRepository(gitDir);

    IFile[] commitables = getAllFiles();
    ArrayList<IFile> untracked = new ArrayList<IFile>();
    untracked.addAll(Arrays.asList(commitables));
    CommitOperation cop = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR,
            TestUtil.TESTCOMMITTER, "Initial commit");
    cop.setAmending(true);/*w ww.  j  av  a2  s .c om*/
    cop.execute(null);

    TagBuilder tag = new TagBuilder();
    tag.setTag(TAG_NAME);
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm a savepoint");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);

    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.ReplaceActionsTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    commitOfTag = tag.getObjectId();/*from w  w  w.  j  av  a2s  . c  om*/
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);
    touchAndSubmit(null);
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.TagActionTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);//from www  .  ja v a 2 s.c  o m
    touchAndSubmit(null);
    waitInUI();
}