org.eclipse.jgit.api.Git.tag()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中org.eclipse.jgit.api.Git.tag()方法的一些代码示例,展示了Git.tag()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.tag()方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:tag

Git.tag介绍

[英]Return a command object to execute a Tag command
[中]返回命令对象以执行标记命令

代码示例

代码示例来源:origin: FlowCI/flow-platform

.call();
git.tag()
  .setName(plugin.getTag())
  .setMessage("add " + plugin.getTag())

代码示例来源:origin: centic9/jgit-cookbook

Ref tag = git.tag().setName("tag_for_testing").call();
System.out.println("Created/moved tag " + tag + " to repository at " + repository.getDirectory());
try (RevWalk walk = new RevWalk(repository)) {
  RevCommit commit = walk.parseCommit(id);
  tag = git.tag().setObjectId(commit).setName("tag_for_testing").call();
  System.out.println("Created/moved tag " + tag + " to repository at " + repository.getDirectory());
  tag = git.tag().setName("tag_for_testing").setAnnotated(true).call();
  System.out.println("Created/moved tag " + tag + " to repository at " + repository.getDirectory());

代码示例来源:origin: com.meltmedia.cadmium/cadmium-core

public boolean tag(String tagname, String comment) throws Exception {
 try{
  git.fetch().setTagOpt(TagOpt.FETCH_TAGS).call();
 } catch(Exception e) {
  log.debug("Fetch from origin failed.", e);
 }
 List<RevTag> tags = git.tagList().call();
 if(tags != null && tags.size() > 0) {
  for(RevTag tag : tags) {
   if(tag.getTagName().equals(tagname)) {
    throw new Exception("Tag already exists.");
   }
  }
 }
 boolean success = git.tag().setMessage(comment).setName(tagname).call() != null;
 try{
  git.push().setPushTags().call();
 } catch(Exception e){
  log.debug("Failed to push changes.", e);
 }
 return success;
}

代码示例来源:origin: org.wildfly.core/wildfly-server

@Override
public String snapshot(String name, String comment) throws ConfigurationPersistenceException {
  boolean noComment = (comment ==null || comment.isEmpty());
  String message = noComment ? SNAPSHOT_PREFIX + FORMATTER.format(LocalDateTime.now()) : comment;
  String tagName = (name ==null || name.isEmpty()) ? SNAPSHOT_PREFIX + FORMATTER.format(LocalDateTime.now()) : name;
  try (Git git = gitRepository.getGit()) {
    Status status = git.status().call();
    List<Ref> tags = git.tagList().call();
    String refTagName = R_TAGS + tagName;
    for(Ref tag : tags) {
      if(refTagName.equals(tag.getName())) {
        throw MGMT_OP_LOGGER.snapshotAlreadyExistError(tagName);
      }
    }
    //if comment is not null
    if(status.hasUncommittedChanges() || !noComment) {
      git.commit().setMessage(message).setAll(true).setNoVerify(true).call();
    }
    git.tag().setName(tagName).setMessage(message).call();
  } catch (GitAPIException ex) {
    throw MGMT_OP_LOGGER.failedToPersistConfiguration(ex, message, ex.getMessage());
  }
  return message;
}

代码示例来源:origin: org.arquillian.algeron/arquillian-algeron-git

/**
 * Creates a tag.
 *
 * @param git
 *     instance.
 * @param name
 *     of the tag.
 *
 * @return Ref created to tag.
 */
public Ref createTag(Git git, String name) {
  try {
    return git.tag()
      .setName(name)
      .call();
  } catch (GitAPIException e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: centic9/jgit-cookbook

Ref tag = git.tag().setName("tag_for_testing").call();
System.out.println("Created/moved tag " + tag + " to repository at " + repository.getDirectory());
try (RevWalk walk = new RevWalk(repository)) {
  RevCommit commit = walk.parseCommit(id);
  tag = git.tag().setObjectId(commit).setName("tag_for_testing").call();
  System.out.println("Created/moved tag " + tag + " to repository at " + repository.getDirectory());
  tag = git.tag().setName("tag_for_testing").setAnnotated(true).call();
  System.out.println("Created/moved tag " + tag + " to repository at " + repository.getDirectory());

代码示例来源:origin: wildfly/wildfly-core

@Override
public String snapshot(String name, String comment) throws ConfigurationPersistenceException {
  boolean noComment = (comment ==null || comment.isEmpty());
  String message = noComment ? SNAPSHOT_PREFIX + FORMATTER.format(LocalDateTime.now()) : comment;
  String tagName = (name ==null || name.isEmpty()) ? SNAPSHOT_PREFIX + FORMATTER.format(LocalDateTime.now()) : name;
  try (Git git = gitRepository.getGit()) {
    Status status = git.status().call();
    List<Ref> tags = git.tagList().call();
    String refTagName = R_TAGS + tagName;
    for(Ref tag : tags) {
      if(refTagName.equals(tag.getName())) {
        throw MGMT_OP_LOGGER.snapshotAlreadyExistError(tagName);
      }
    }
    //if comment is not null
    if(status.hasUncommittedChanges() || !noComment) {
      git.commit().setMessage(message).setAll(true).setNoVerify(true).call();
    }
    git.tag().setName(tagName).setMessage(message).call();
  } catch (GitAPIException ex) {
    throw MGMT_OP_LOGGER.failedToPersistConfiguration(ex, message, ex.getMessage());
  }
  return message;
}

代码示例来源:origin: org.apache.camel/camel-git

protected void doCreateTag(Exchange exchange, String operation) throws Exception {
  if (ObjectHelper.isEmpty(endpoint.getTagName())) {
    throw new IllegalArgumentException("Tag Name must be specified to execute " + operation);
  }
  try {
    git.tag().setName(endpoint.getTagName()).call();
  } catch (Exception e) {
    LOG.error("There was an error in Git {} operation", operation);
    throw e;
  }
}

代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control

/**
 * Method will tag the current HEAD commit has being the latest published.
 */
@SneakyThrows
public void setPublished() {
  if (!isUndefined()) {
    git.tagDelete().setTags("published").call();
    git.tag().setName("published").call();
  }
}

代码示例来源:origin: com.madgag/org.eclipse.jgit.pgm

@Override
  protected void run() throws Exception {
    Git git = new Git(db);
    if (tagName != null) {
      TagCommand command = git.tag().setForceUpdate(force)
          .setMessage(message).setName(tagName);

      if (object != null) {
        RevWalk walk = new RevWalk(db);
        command.setObjectId(walk.parseAny(object));
      }
      try {
        command.call();
      } catch (RefAlreadyExistsException e) {
        throw die(MessageFormat.format(CLIText.get().tagAlreadyExists,
            tagName));
      }
    } else {
      ListTagCommand command = git.tagList();
      List<Ref> list = command.call();
      for (Ref ref : list) {
        outw.println(Repository.shortenRefName(ref.getName()));
      }
    }
  }
}

代码示例来源:origin: danielflower/multi-module-maven-release-plugin

public Ref saveAtHEAD(Git git) throws GitAPIException {
  String json = message.toJSONString();
  ref = git.tag().setName(name()).setAnnotated(true).setMessage(json).call();
  return ref;
}

代码示例来源:origin: openl-tablets/openl-tablets

private void addTagToCommit(RevCommit commit) throws GitAPIException {
  pull();
  if (!tagPrefix.isEmpty()) {
    String tagName = tagPrefix + getNextTagId();
    git.tag().setObjectId(commit).setName(tagName).call();
  }
}

代码示例来源:origin: org.openengsb.connector/org.openengsb.connector.git

@Override
public TagRef tagRepo(String tagName) {
  try {
    if (repository == null) {
      initRepository();
    }
    TagCommand tag = new Git(repository).tag();
    LOGGER.debug("Tagging HEAD with name '{}'", tagName);
    return new GitTagRef(tag.setName(tagName).call());
  } catch (Exception e) {
    throw new ScmException(e);
  }
}

代码示例来源:origin: theonedev/onedev

public void tag(String tagName, String tagRevision, PersonIdent taggerIdent, @Nullable String tagMessage) {
  try {
    TagCommand tag = git().tag();
    tag.setName(tagName);
    if (tagMessage != null)
      tag.setMessage(tagMessage);
    tag.setTagger(taggerIdent);
    tag.setObjectId(getRevCommit(tagRevision));
    tag.call();
    cacheObjectId(GitUtils.tag2ref(tagName), tag.getObjectId());
  } catch (GitAPIException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: jenkinsci/git-client-plugin

/** {@inheritDoc} */
@Override
public void tag(String name, String message) throws GitException {
  try (Repository repo = getRepository()) {
    git(repo).tag().setName(name).setMessage(message).setForceUpdate(true).call();
  } catch (GitAPIException e) {
    throw new GitException(e);
  }
}

代码示例来源:origin: org.openengsb.connector/org.openengsb.connector.git

@Override
public TagRef tagRepo(String tagName, CommitRef ref) {
  try {
    if (repository == null) {
      initRepository();
    }
    AnyObjectId commitRef = repository.resolve(ref.getStringRepresentation());
    if (commitRef == null) {
      LOGGER.debug("Couldnt resolve reference {} in repository", ref.getStringRepresentation());
      return null;
    }
    RevWalk walk = new RevWalk(repository);
    RevCommit revCommit = walk.parseCommit(commitRef);
    TagCommand tag = new Git(repository).tag();
    tag.setName(tagName).setObjectId(revCommit);
    LOGGER.debug("Tagging revision {} with name '{}'", ref.getStringRepresentation(), tagName);
    return new GitTagRef(tag.call());
  } catch (Exception e) {
    throw new ScmException(e);
  }
}

代码示例来源:origin: stackoverflow.com

@Rule
public final TemporaryFolder tempFolder = new TemporaryFolder();

@Test
public void testRevWalkDoesNotLeakResources() throws Exception {
 Git git = Git.init().setDirectory( tempFolder.getRoot() ).call();
 git.commit().setMessage( "First commit" ).call();
 git.tag().setName( "First-Tag" ).call();
 Ref tagRef = git.getRepository().getRef( "refs/tags/First-Tag" );
 RevWalk revWalk = new RevWalk( git.getRepository() );
 RevTag tag = revWalk.parseTag( tagRef.getObjectId() );
 revWalk.release();
 git.getRepository().close();

 tempFolder.delete();

 assertNotNull( tag );
 assertFalse( tempFolder.getRoot().exists() );
}

代码示例来源:origin: airlift/airship

public Bundle createNewVersion(Bundle bundle)
    throws NoHeadException, ConcurrentRefUpdateException, InvalidTagNameException, IOException
{
  Preconditions.checkNotNull(bundle, "bundle is null");
  Preconditions.checkArgument(bundle.isSnapshot(), "can't release a non-snapshot version");
  Bundle current = getBundle(bundle.getName());
  Preconditions.checkArgument(bundle.equals(current), "Bundle specifier (%s:%s) is stale. Latest version is %s:%s", bundle.getName(), bundle.getVersion(), bundle.getName(), current.getVersion());
  int version = bundle.getVersion();
  RevCommit commit = GitUtils.getCommit(git.getRepository(), getBranch(git.getRepository(), bundle.getName()));
  git.tag().setObjectId(commit)
      .setName(bundle.getName() + "-" + version)
      .call();
  return new Bundle(bundle.getName(), version, false);
}

代码示例来源:origin: io.ultreia.java4all.jgitflow/jgitflow-core

protected void doTag(String branchToTag, String tagMessage, MergeResult resultToLog, BranchMergingExtension extension) throws GitAPIException, JGitFlowGitAPIException, JGitFlowExtensionException
{
  runExtensionCommands(extension.beforeTag());
  git.checkout().setName(branchToTag).call();
  String tagName = gfConfig.getPrefixValue(JGitFlowConstants.PREFIXES.VERSIONTAG.configKey()) + getBranchName();
  if (!GitHelper.tagExists(git, tagName))
  {
    reporter.infoText(
        getCommandName(),
        String.format(
            "tagging with name: <%s>. merge status (%s)",
            tagName,
            resultToLog.getMergeStatus()
        )
    );
    git.tag().setName(tagName).setMessage(getScmMessagePrefix() + tagMessage + getScmMessageSuffix()).call();
  }
  runExtensionCommands(extension.afterTag());
}

代码示例来源:origin: external.atlassian.jgitflow/jgit-flow-core

protected void doTag(String branchToTag, String tagMessage, MergeResult resultToLog, BranchMergingExtension extension) throws GitAPIException, JGitFlowGitAPIException, JGitFlowExtensionException
{
  runExtensionCommands(extension.beforeTag());
  git.checkout().setName(branchToTag).call();
  String tagName = gfConfig.getPrefixValue(JGitFlowConstants.PREFIXES.VERSIONTAG.configKey()) + getBranchName();
  if (!GitHelper.tagExists(git, tagName))
  {
    reporter.infoText(
        getCommandName(),
        String.format(
            "tagging with name: <%s>. merge status (%s)",
            tagName,
            resultToLog.getMergeStatus()
        )
    );
    git.tag().setName(tagName).setMessage(getScmMessagePrefix() + tagMessage + getScmMessageSuffix()).call();
  }
  runExtensionCommands(extension.afterTag());
}

相关文章