/** * Executes the tag creation operation. * * @return the created tag * */ @Override protected RevTag _call() throws RuntimeException { checkState(name != null, "tag name was not provided"); final String tagRefPath = Ref.TAGS_PREFIX + name; checkArgument(!command(RefParse.class).setName(tagRefPath).call().isPresent(), "A tag named '" + name + "' already exists."); command(CheckRefFormat.class).setThrowsException(true).setRef(tagRefPath).call(); if (commitId == null) { final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call(); Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't create tag"); commitId = currHead.get().getObjectId(); } RevPerson tagger = resolveTagger(); message = message == null ? "" : message; RevTag tag = RevTagBuilder.build(name, commitId, message, tagger); objectDatabase().put(tag); Optional<Ref> branchRef = command(UpdateRef.class).setName(tagRefPath) .setNewValue(tag.getId()).call(); checkState(branchRef.isPresent()); return tag; }
/** * Executes the tag creation operation. * * @return the created tag * */ @Override protected RevTag _call() throws RuntimeException { checkState(name != null, "tag name was not provided"); final String tagRefPath = Ref.TAGS_PREFIX + name; checkArgument(!command(RefParse.class).setName(tagRefPath).call().isPresent(), "A tag named '" + name + "' already exists."); command(CheckRefFormat.class).setThrowsException(true).setRef(tagRefPath).call(); if (commitId == null) { final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call(); Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't create tag"); commitId = currHead.get().getObjectId(); } RevPerson tagger = resolveTagger(); message = message == null ? "" : message; final RevTag tag = RevTag.builder().name(name).commitId(commitId).message(message) .tagger(tagger).build(); objectDatabase().put(tag); Optional<Ref> branchRef = command(UpdateRef.class).setName(tagRefPath) .setNewValue(tag.getId()).call(); checkState(branchRef.isPresent()); return tag; }