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

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

Introduction

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

Prototype

public TagCommand setForceUpdate(boolean forceUpdate) 

Source Link

Document

If set to true the Tag command may replace an existing tag object.

Usage

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

License:Open Source License

/**
 * Creates a tag//from w ww  . j a  v  a 2  s .c om
 * 
 * @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  ava 2  s. co  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.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   w ww . j av  a2  s  .  c om
    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();
}