List of usage examples for org.eclipse.jgit.api TagCommand setMessage
public TagCommand setMessage(String message)
message
. From source file:com.gitblit.utils.JGitUtils.java
License:Apache License
/** * creates a tag in a repository/*from w ww . j a va2 s .c o 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.google.gerrit.server.project.CreateTag.java
License:Apache License
@Override public TagInfo apply(ProjectResource resource, TagInput input) throws RestApiException, IOException { if (input == null) { input = new TagInput(); }/* w w w . j a va 2 s . c o m*/ if (input.ref != null && !ref.equals(input.ref)) { throw new BadRequestException("ref must match URL"); } if (input.revision == null) { input.revision = Constants.HEAD; } while (ref.startsWith("/")) { ref = ref.substring(1); } if (ref.startsWith(R_REFS) && !ref.startsWith(R_TAGS)) { throw new BadRequestException("invalid tag name \"" + ref + "\""); } if (!ref.startsWith(R_TAGS)) { ref = R_TAGS + ref; } if (!Repository.isValidRefName(ref)) { throw new BadRequestException("invalid tag name \"" + ref + "\""); } RefControl refControl = resource.getControl().controlForRef(ref); try (Repository repo = repoManager.openRepository(resource.getNameKey())) { ObjectId revid = RefUtil.parseBaseRevision(repo, resource.getNameKey(), input.revision); RevWalk rw = RefUtil.verifyConnected(repo, revid); RevObject object = rw.parseAny(revid); rw.reset(); boolean isAnnotated = Strings.emptyToNull(input.message) != null; boolean isSigned = isAnnotated && input.message.contains("-----BEGIN PGP SIGNATURE-----\n"); if (isSigned) { throw new MethodNotAllowedException("Cannot create signed tag \"" + ref + "\""); } else if (isAnnotated && !refControl.canPerform(Permission.PUSH_TAG)) { throw new AuthException("Cannot create annotated tag \"" + ref + "\""); } else if (!refControl.canPerform(Permission.CREATE)) { throw new AuthException("Cannot create tag \"" + ref + "\""); } if (repo.getRefDatabase().exactRef(ref) != null) { throw new ResourceConflictException("tag \"" + ref + "\" already exists"); } try (Git git = new Git(repo)) { TagCommand tag = git.tag().setObjectId(object).setName(ref.substring(R_TAGS.length())) .setAnnotated(isAnnotated).setSigned(isSigned); if (isAnnotated) { tag.setMessage(input.message).setTagger( identifiedUser.get().newCommitterIdent(TimeUtil.nowTs(), TimeZone.getDefault())); } Ref result = tag.call(); tagCache.updateFastForward(resource.getNameKey(), ref, ObjectId.zeroId(), result.getObjectId()); referenceUpdated.fire(resource.getNameKey(), ref, ObjectId.zeroId(), result.getObjectId(), identifiedUser.get().getAccount()); try (RevWalk w = new RevWalk(repo)) { return ListTags.createTagInfo(result, w); } } } catch (InvalidRevisionException e) { throw new BadRequestException("Invalid base revision"); } catch (GitAPIException e) { log.error("Cannot create tag \"" + ref + "\"", e); throw new IOException(e); } }
From source file:com.worldline.easycukes.scm.utils.GitHelper.java
License:Open Source License
/** * Create a new tag in the local git repository * (git checkout tagname) and finally pushes new branch on the remote repository (git push) * * @param directory the directory in which the local git repository is located * @param username the username to be used while pushing * @param password the password matching with the provided username to be used * for authentication//from ww w . ja v a2 s . c om * @param message the commit message to be used */ public static void createTag(@NonNull File directory, String tagName, String username, String password, String message) { try { final Git git = Git.open(directory); final UsernamePasswordCredentialsProvider userCredential = new UsernamePasswordCredentialsProvider( username, password); TagCommand tagCommand = git.tag(); tagCommand.setName(tagName); tagCommand.setMessage(message); tagCommand.call(); log.info("Tag created"); // and then commit final PersonIdent author = new PersonIdent(username, ""); git.commit().setCommitter(author).setMessage(message).setAuthor(author).call(); log.info(message); git.push().setCredentialsProvider(userCredential).call(); log.info("Pushed the changes in remote Git repository..."); } catch (final GitAPIException | IOException e) { log.error(e.getMessage(), e); } }
From source file:org.ajoberstar.gradle.git.tasks.GitTag.java
License:Apache License
/** * Tags the HEAD.// w w w . ja va 2 s. com */ @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);/* ww w .j a v a 2s .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(); }