protected ScmResult executeUntagCommand()

in maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/untag/JGitUntagCommand.java [44:86]


    protected ScmResult executeUntagCommand(
            ScmProviderRepository repository, ScmFileSet fileSet, ScmUntagParameters scmUntagParameters)
            throws ScmException {
        String tagName = scmUntagParameters.getTag();
        if (tagName == null || StringUtils.isEmpty(tagName.trim())) {
            throw new ScmException("tag name must be specified");
        }
        String escapedTagName = tagName.trim().replace(' ', '_');

        Git git = null;
        try {
            git = JGitUtils.openRepo(fileSet.getBasedir());

            // delete the tag
            if (git.tagDelete().setTags(escapedTagName).call().isEmpty()) {
                return new UntagScmResult("JGit tagDelete", "Failed to delete tag", "", false);
            }

            if (repository.isPushChanges()) {
                // From https://stackoverflow.com/q/11892766/696632
                RefSpec refSpec = new RefSpec().setSource(null).setDestination(Constants.R_TAGS + escapedTagName);

                logger.info("push delete tag [" + escapedTagName + "] to remote...");

                Iterable<PushResult> pushResultList =
                        JGitUtils.push(git, (GitScmProviderRepository) repository, refSpec);
                if (logger.isInfoEnabled()) {
                    for (PushResult pushResult : pushResultList) {
                        Collection<RemoteRefUpdate> ru = pushResult.getRemoteUpdates();
                        for (RemoteRefUpdate remoteRefUpdate : ru) {
                            logger.info(remoteRefUpdate.getStatus() + " - " + remoteRefUpdate);
                        }
                    }
                }
            }

            return new UntagScmResult("JGit tagDelete");
        } catch (Exception e) {
            throw new ScmException("JGit tagDelete failure!", e);
        } finally {
            JGitUtils.closeRepo(git);
        }
    }