in maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/tag/JGitTagCommand.java [59:111]
public ScmResult executeTagCommand(
ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters)
throws ScmException {
if (tag == null || tag.trim().isEmpty()) {
throw new ScmException("tag name must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException("This provider doesn't support tagging subsets of a directory");
}
String escapedTagName = tag.trim().replace(' ', '_');
Git git = null;
try {
git = JGitUtils.openRepo(fileSet.getBasedir());
// tag the revision
String tagMessage = scmTagParameters.getMessage();
Ref tagRef = git.tag()
.setName(escapedTagName)
.setMessage(tagMessage)
.setForceUpdate(false)
.call();
if (repo.isPushChanges()) {
logger.info("push tag [" + escapedTagName + "] to remote...");
JGitUtils.push(git, (GitScmProviderRepository) repo, new RefSpec(Constants.R_TAGS + escapedTagName));
}
// search for the tagged files
RevWalk revWalk = new RevWalk(git.getRepository());
RevCommit commit = revWalk.parseCommit(tagRef.getObjectId());
revWalk.close();
final TreeWalk walk = new TreeWalk(git.getRepository());
walk.reset(); // drop the first empty tree, which we do not need here
walk.setRecursive(true);
walk.addTree(commit.getTree());
List<ScmFile> taggedFiles = new ArrayList<>();
while (walk.next()) {
taggedFiles.add(new ScmFile(walk.getPathString(), ScmFileStatus.CHECKED_OUT));
}
walk.close();
return new TagScmResult("JGit tag", taggedFiles);
} catch (Exception e) {
throw new ScmException("JGit tag failure!", e);
} finally {
JGitUtils.closeRepo(git);
}
}