Java Code Examples for org.eclipse.jgit.lib.ObjectId#isId()
The following examples show how to use
org.eclipse.jgit.lib.ObjectId#isId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RevisionPicker.java From onedev with MIT License | 5 votes |
@Override public IModel<?> getBody() { String iconClass; String label; if ("master".equals(revision)) { // default to use master branch when project is empty label = "master"; iconClass = "fa fa-code-fork"; } else if (revision != null) { ProjectAndRevision projectAndRevision = new ProjectAndRevision(projectModel.getObject(), revision); label = projectAndRevision.getBranch(); if (label != null) { iconClass = "fa fa-code-fork"; } else { label = projectAndRevision.getTag(); if (label != null) { iconClass = "fa fa-tag"; } else { label = revision; if (ObjectId.isId(label)) label = GitUtils.abbreviateSHA(label); iconClass = "fa fa-ext fa-commit"; } } label = HtmlEscape.escapeHtml5(label); } else { label = "Choose Revision"; iconClass = ""; } return Model.of(String.format("<i class='%s'></i> <span>%s</span> <i class='fa fa-caret-down'></i>", iconClass, label)); }
Example 2
Source File: CommitInput.java From onedev with MIT License | 5 votes |
public static Object convertToObject(List<String> strings) { if (strings.size() == 0) { return null; } else if (strings.size() == 1) { String value = strings.iterator().next(); if (ObjectId.isId(value)) return value; else throw new ValidationException("Invalid commit id"); } else { throw new ValidationException("Not eligible for multi-value"); } }
Example 3
Source File: CommitHashValidator.java From onedev with MIT License | 5 votes |
@Override public boolean isValid(String value, ConstraintValidatorContext constraintContext) { if (value == null || interpolative && !Interpolated.get() && !Interpolative.parse(value).getSegments(Segment.Type.VARIABLE).isEmpty()) return true; if (!ObjectId.isId(value)) { constraintContext.disableDefaultConstraintViolation(); constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation(); return false; } else { return true; } }
Example 4
Source File: GitRepository.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void checkoutToSelectedBranch(final Git git) throws IOException, GitAPIException { boolean createBranch = !ObjectId.isId(branch); if (createBranch) { Ref ref = git.getRepository().exactRef(R_HEADS + branch); if (ref != null) { createBranch = false; } } CheckoutCommand checkout = git.checkout().setCreateBranch(createBranch).setName(branch); checkout.call(); if (checkout.getResult().getStatus() == CheckoutResult.Status.ERROR) { throw ServerLogger.ROOT_LOGGER.failedToPullRepository(null, defaultRemoteRepository); } }
Example 5
Source File: GitProctorCore.java From proctor with Apache License 2.0 | 4 votes |
@Override @Nullable public <C> C getFileContents( final Class<C> c, final String[] path, @Nullable final C defaultValue, final String revision ) throws StoreException.ReadException, JsonProcessingException { try { if (!ObjectId.isId(revision)) { throw new StoreException.ReadException("Malformed id " + revision); } final ObjectId blobOrCommitId = ObjectId.fromString(revision); final ObjectLoader loader = git.getRepository().open(blobOrCommitId); if (loader.getType() == Constants.OBJ_COMMIT) { // look up the file at this revision final RevCommit commit = RevCommit.parse(loader.getCachedBytes()); final TreeWalk treeWalk2 = new TreeWalk(git.getRepository()); treeWalk2.addTree(commit.getTree()); treeWalk2.setRecursive(true); final String joinedPath = String.join("/", path); treeWalk2.setFilter(PathFilter.create(joinedPath)); if (!treeWalk2.next()) { // it did not find expected file `joinPath` so return default value return defaultValue; } final ObjectId blobId = treeWalk2.getObjectId(0); return getFileContents(c, blobId); } else if (loader.getType() == Constants.OBJ_BLOB) { return getFileContents(c, blobOrCommitId); } else { throw new StoreException.ReadException("Invalid Object Type " + loader.getType() + " for id " + revision); } } catch (final IOException e) { throw new StoreException.ReadException(e); } }