Example usage for org.eclipse.jgit.api TagCommand setTagger

List of usage examples for org.eclipse.jgit.api TagCommand setTagger

Introduction

In this page you can find the example usage for org.eclipse.jgit.api TagCommand setTagger.

Prototype

public TagCommand setTagger(PersonIdent tagger) 

Source Link

Document

Sets the tagger of the tag.

Usage

From source file:com.gitblit.utils.JGitUtils.java

License:Apache License

/**
 * creates a tag in a repository// ww  w. j  av a  2s. c om
 *
 * @param repository
 * @param objectId, the ref the tag points towards
 * @param tagger, the person tagging the object
 * @param tag, the string label
 * @param message, the string message
 * @return boolean, true if operation was successful, otherwise false
 */
public static boolean createTag(Repository repository, String objectId, PersonIdent tagger, String tag,
        String message) {
    try {
        Git gitClient = Git.open(repository.getDirectory());
        TagCommand tagCommand = gitClient.tag();
        tagCommand.setTagger(tagger);
        tagCommand.setMessage(message);
        if (objectId != null) {
            RevObject revObj = getCommit(repository, objectId);
            tagCommand.setObjectId(revObj);
        }
        tagCommand.setName(tag);
        Ref call = tagCommand.call();
        return call != null ? true : false;
    } catch (Exception e) {
        error(e, repository, "Failed to create tag {1} in repository {0}", objectId, tag);
    }
    return false;
}

From source file:com.microsoft.gittf.core.util.TagUtil.java

License:Open Source License

/**
 * Creates a tag//from   w w w. j av a2 s. c  o m
 * 
 * @param repository
 *        the git repository
 * @param commitID
 *        the commit id to tag
 * @param tagName
 *        the tag name
 * @param tagOwner
 *        the tag owner
 * @return
 */
public static boolean createTag(final Repository repository, ObjectId commitID, String tagName,
        PersonIdent tagOwner) {
    final RevWalk walker = new RevWalk(repository);
    try {
        /* Look up the object to tag */
        RevObject objectToTag = walker.lookupCommit(commitID);

        /* Create a tag command */
        TagCommand tagCommand = new Git(repository).tag();
        tagCommand.setName(tagName);
        tagCommand.setObjectId(objectToTag);
        tagCommand.setForceUpdate(true);
        tagCommand.setTagger(tagOwner);

        /* Call the tag command */
        Ref tagRef = tagCommand.call();

        if (tagRef == null || tagRef == ObjectId.zeroId()) {
            log.warn("Failed to tag commit."); //$NON-NLS-1$

            return false;
        }

        return true;
    } catch (Exception e) {
        // this is not a critical failure so we can still continue with the
        // operation even if tagging failed.

        log.error(e);

        return false;
    } finally {
        if (walker != null) {
            walker.release();
        }
    }
}

From source file:org.ajoberstar.gradle.git.tasks.GitTag.java

License:Apache License

/**
 * Tags the HEAD./*  w  w  w.  j  a v  a2  s . c  o  m*/
 */
@TaskAction
public void tag() {
    TagCommand cmd = getGit().tag();
    cmd.setName(getTagName());
    cmd.setMessage(getMessage());
    cmd.setSigned(getSign());
    cmd.setForceUpdate(getForce());
    if (tagger != null) {
        cmd.setTagger(getTagger());
    }

    try {
        cmd.call();
    } catch (ConcurrentRefUpdateException e) {
        throw new GradleException("Another process is accessing or updating the ref.", e);
    } catch (InvalidTagNameException e) {
        throw new GradleException("Invalid tag name: " + getTagName(), e);
    } catch (NoHeadException e) {
        throw new GradleException("Cannot tag without a HEAD revision.", e);
    } catch (GitAPIException e) {
        throw new GradleException("Problem with tag.", e);
    }
}

From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java

License:Open Source License

@Override
public Tag tagCreate(TagCreateRequest request) throws GitException {
    String commit = request.getCommit();
    if (commit == null) {
        commit = Constants.HEAD;/*from   w w  w. j av  a2  s  .c om*/
    }

    try {
        RevWalk revWalk = new RevWalk(repository);
        RevObject revObject;
        try {
            revObject = revWalk.parseAny(repository.resolve(commit));
        } finally {
            revWalk.close();
        }

        TagCommand tagCommand = getGit().tag().setName(request.getName()).setObjectId(revObject)
                .setMessage(request.getMessage()).setForceUpdate(request.isForce());

        GitUser tagger = getUser();
        if (tagger != null) {
            tagCommand.setTagger(new PersonIdent(tagger.getName(), tagger.getEmail()));
        }

        Ref revTagRef = tagCommand.call();
        RevTag revTag = revWalk.parseTag(revTagRef.getLeaf().getObjectId());
        return newDto(Tag.class).withName(revTag.getTagName());
    } catch (IOException | GitAPIException exception) {
        throw new GitException(exception.getMessage(), exception);
    }
}