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

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

Introduction

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

Prototype

public TagCommand setObjectId(RevObject id) 

Source Link

Document

Sets the object id of the tag.

Usage

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

License:Apache License

/**
 * creates a tag in a repository//from   w  ww.  j  a v a  2  s .  co  m
 *
 * @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 . ja va2s. 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.moxie.utils.JGitUtils.java

License:Apache License

public static String commitFiles(File dir, List<String> files, String message, String tagName,
        String tagMessage) throws IOException, GitAPIException {
    Git git = Git.open(dir);//from ww  w .  ja  v a2s . co m
    AddCommand add = git.add();
    for (String file : files) {
        add.addFilepattern(file);
    }
    add.call();

    // execute the commit
    CommitCommand commit = git.commit();
    commit.setMessage(message);
    RevCommit revCommit = commit.call();

    if (!StringUtils.isEmpty(tagName) && !StringUtils.isEmpty(tagMessage)) {
        // tag the commit
        TagCommand tagCommand = git.tag();
        tagCommand.setName(tagName);
        tagCommand.setMessage(tagMessage);
        tagCommand.setForceUpdate(true);
        tagCommand.setObjectId(revCommit);
        tagCommand.call();
    }
    git.getRepository().close();
    return revCommit.getId().getName();
}

From source file:org.webcat.core.git.GitRepository.java

License:Open Source License

public GitRef createTagForObject(String name, ObjectId objectId) {
    TagCommand tag = new Git(repository).tag();
    tag.setName(name);//from  w ww .  j  av  a  2s  .com

    if (objectId == null) {
        tag.setObjectId(null);
    } else {
        RevWalk revWalk = new RevWalk(repository);

        try {
            RevCommit commit = revWalk.parseCommit(objectId);
            tag.setObjectId(commit);
        } catch (Exception e) {
            return null;
        } finally {
            revWalk.release();
        }
    }

    try {
        tag.call();
        return refWithName(Constants.R_TAGS + name);
    } catch (Exception e) {
        return null;
    }
}