List of usage examples for org.eclipse.jgit.lib ObjectId name
public final String name()
name.
From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java
License:Eclipse Distribution License
private void markLocalRefsComplete(final Set<ObjectId> have) throws TransportException { for (final Ref r : local.getAllRefs().values()) { try {/*from ww w. j a va2s. c om*/ markLocalObjComplete(revWalk.parseAny(r.getObjectId())); } catch (IOException readError) { throw new TransportException( MessageFormat.format(JGitText.get().localRefIsMissingObjects, r.getName()), readError); } } for (final ObjectId id : have) { try { markLocalObjComplete(revWalk.parseAny(id)); } catch (IOException readError) { throw new TransportException( MessageFormat.format(JGitText.get().transportExceptionMissingAssumed, id.name()), readError); } } }
From source file:jbyoshi.gitupdate.processor.Push.java
License:Apache License
private static void process(Repository repo, Git git, String remote, Collection<String> branches, Report report) throws Exception { // Figure out if anything needs to be pushed. Map<String, ObjectId> oldIds = new HashMap<>(); boolean canPush = false; for (String branch : branches) { BranchConfig config = new BranchConfig(repo.getConfig(), branch); ObjectId target = repo.getRef(branch).getObjectId(); Ref remoteRef = repo.getRef(config.getRemoteTrackingBranch()); if (remoteRef == null || !target.equals(remoteRef.getObjectId())) { canPush = true;/*from w w w . j a v a 2 s . com*/ } oldIds.put(branch, remoteRef == null ? ObjectId.zeroId() : remoteRef.getObjectId()); } if (!canPush) { return; } PushCommand push = git.push().setCredentialsProvider(Prompts.INSTANCE).setTimeout(5).setRemote(remote); for (String branch : branches) { push.add(Constants.R_HEADS + branch); } for (PushResult result : push.call()) { for (RemoteRefUpdate update : result.getRemoteUpdates()) { if (update.getStatus() == RemoteRefUpdate.Status.OK) { String branchName = Utils.getShortBranch(update.getSrcRef()); ObjectId oldId = oldIds.get(branchName); String old = oldId.equals(ObjectId.zeroId()) ? "new branch" : oldId.name(); report.newChild(branchName + ": " + old + " -> " + update.getNewObjectId().name()).modified(); } } } }
From source file:jenkins.plugins.git.MergeWithGitSCMExtension.java
License:Open Source License
@Override public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev) throws IOException, InterruptedException, GitException { ObjectId baseObjectId; if (StringUtils.isBlank(baseHash)) { try {/* w ww. jav a2 s. co m*/ baseObjectId = git.revParse(Constants.R_REFS + baseName); } catch (GitException e) { listener.getLogger().printf("Unable to determine head revision of %s prior to merge with PR%n", baseName); throw e; } } else { baseObjectId = ObjectId.fromString(baseHash); } listener.getLogger().printf("Merging %s commit %s into PR head commit %s%n", baseName, baseObjectId.name(), rev.getSha1String()); checkout(scm, build, git, listener, rev); try { /* could parse out of JenkinsLocationConfiguration.get().getAdminAddress() but seems overkill */ git.setAuthor("Jenkins", "nobody@nowhere"); git.setCommitter("Jenkins", "nobody@nowhere"); MergeCommand cmd = git.merge().setRevisionToMerge(baseObjectId); for (GitSCMExtension ext : scm.getExtensions()) { // By default we do a regular merge, allowing it to fast-forward. ext.decorateMergeCommand(scm, build, git, listener, cmd); } cmd.execute(); } catch (GitException x) { // TODO clarify these TODO comments copied from GitHub Branch Source // Try to revert merge conflict markers. // TODO IGitAPI offers a reset(hard) method yet GitClient does not. Why? checkout(scm, build, git, listener, rev); // TODO would be nicer to throw an AbortException with just the message, but this is actually worse // until git-client 1.19.7+ throw x; } build.addAction(new MergeRecord(baseName, baseObjectId.getName())); // does not seem to be used, but just in case ObjectId mergeRev = git.revParse(Constants.HEAD); listener.getLogger().println("Merge succeeded, producing " + mergeRev.name()); return new Revision(mergeRev, rev.getBranches()); // note that this ensures Build.revision != Build.marked }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.CommitLoaderImpl.java
License:Apache License
@NotNull public RevCommit getCommit(@NotNull Repository repository, @NotNull ObjectId commitId) throws IOException { final long start = System.currentTimeMillis(); RevWalk walk = new RevWalk(repository); try {/*ww w . java 2 s . co m*/ return walk.parseCommit(commitId); } finally { walk.release(); final long finish = System.currentTimeMillis(); if (PERFORMANCE_LOG.isDebugEnabled()) { PERFORMANCE_LOG .debug("[RevWalk.parseCommit] repository=" + repository.getDirectory().getAbsolutePath() + ", commit=" + commitId.name() + ", took: " + (finish - start) + "ms"); } } }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.patch.BuildPatchLogger.java
License:Apache License
public void cannotLoadFile(@Nullable String path, @NotNull ObjectId objectId) { myDelegate.error("Unable to load file: " + path + "(" + objectId.name() + ") from: " + myRepoDebugInfo); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.submodules.SubmoduleFetchException.java
License:Apache License
public SubmoduleFetchException(@NotNull String mainRepositoryUrl, @NotNull String submodulePath, @NotNull String submoduleUrl, @NotNull ObjectId mainRepositoryCommit, @NotNull Throwable cause) { super("Cannot fetch the '" + submoduleUrl + "' repository used as a submodule at the '" + submodulePath + "' path in the '" + mainRepositoryUrl + "' repository in the " + mainRepositoryCommit.name() + " commit" + ", cause: " + cause.getClass().getName() + ": " + cause.getMessage()); initCause(cause);/*from w w w. j ava 2s. c o m*/ }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.submodules.SubmoduleResolverImpl.java
License:Apache License
/** * Resolve the commit for submodule/*from w w w. jav a 2 s. c om*/ * * @param parentRepositoryUrl url of the parent repository * @param path the within repository path * @param commit the commit identifier * @return the the resoled commit in other repository * @throws VcsAuthenticationException if there are authentication problems * @throws URISyntaxException if there are errors in submodule repository URI */ @NotNull public RevCommit getSubmoduleCommit(@NotNull String parentRepositoryUrl, @NotNull String path, @NotNull ObjectId commit) throws CorruptObjectException, VcsException, URISyntaxException { ensureConfigLoaded(); if (myConfig == null) throw new MissingSubmoduleConfigException(parentRepositoryUrl, myCommit.name(), path); final Submodule submodule = myConfig.findSubmodule(path); if (submodule == null) throw new MissingSubmoduleEntryException(parentRepositoryUrl, myCommit.name(), path); Repository r = resolveRepository(submodule.getUrl()); String submoduleUrl = myContext.getConfig(r).getString("teamcity", null, "remote"); if (!isCommitExist(r, commit)) { try { fetch(r, path, submodule.getUrl()); } catch (Exception e) { throw new SubmoduleFetchException(parentRepositoryUrl, path, submoduleUrl, myCommit, e); } } try { return myCommitLoader.getCommit(r, commit); } catch (Exception e) { throw new MissingSubmoduleCommitException(parentRepositoryUrl, myCommit.name(), path, submodule.getUrl(), commit.name()); } }
From source file:net.mobid.codetraq.runnables.GitChecker.java
License:Open Source License
private String safeAbbreviate(ObjectReader reader, ObjectId id) { try {/*w ww .j a va2 s .c o m*/ return reader.abbreviate(id).name(); } catch (IOException cannotAbbreviate) { return id.name(); } }
From source file:net.tietema.versioning.GitJavaVersioning.java
License:Apache License
public String getRevision(File projectDir) throws MojoExecutionException { // XXX we use our own findGitDir because they JGit one doesn't find the git dir in a multi project build File gitDir = findGitDir(projectDir); String revision = "Unknown"; if (gitDir == null) return revision; FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = null;// ww w .java 2 s.c om try { repository = builder.setGitDir(gitDir).readEnvironment() // scan environment GIT_* variables .findGitDir(projectDir) // scan up the file system tree .build(); log.info("Git dir: " + gitDir.toString()); RepositoryState state = repository.getRepositoryState(); log.info(state.getDescription()); String branch = repository.getBranch(); log.info("Branch is: " + branch); Git git = new Git(repository); String fullBranch = repository.getFullBranch(); log.info("Full branch is: " + fullBranch); ObjectId id = repository.resolve(fullBranch); log.info("Branch " + repository.getBranch() + " points to " + id.name()); Status status = git.status().call(); boolean strictClean = status.isClean(); // no untracked files boolean loseClean = status.getAdded().isEmpty() && status.getChanged().isEmpty() && status.getConflicting().isEmpty() && status.getMissing().isEmpty() && status.getModified().isEmpty() && status.getRemoved().isEmpty(); StringWriter buffer = new StringWriter(); JavaWriter writer = new JavaWriter(buffer); writer.emitPackage(packageName) .beginType(packageName + "." + className, "class", Modifier.PUBLIC | Modifier.FINAL) .emitField("String", "BRANCH", Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC, String.format(Locale.US, "\"%s\"", branch)) .emitField("String", "REVISION", Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC, String.format(Locale.US, "\"%s\"", id.name())) .emitField("String", "REVISION_SHORT", Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC, String.format(Locale.US, "\"%s\"", id.name().substring(0, 8))) .emitJavadoc("Strict Clean means no changes, not even untracked files") .emitField("boolean", "STRICT_CLEAN", Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC, (strictClean ? "true" : "false")) .emitJavadoc("Lose Clean means no changes except untracked files.") .emitField("boolean", "LOSE_CLEAN", Modifier.PUBLIC | Modifier.FINAL | Modifier.STATIC, (loseClean ? "true" : "false")) .endType(); revision = buffer.toString(); return revision; } catch (IOException e) { log.error(e); throw new MojoExecutionException(e.getMessage()); } catch (GitAPIException e) { log.error(e); throw new MojoExecutionException(e.getMessage()); } finally { if (repository != null) repository.close(); } }
From source file:org.apache.maven.scm.provider.git.jgit.command.info.JGitInfoCommand.java
License:Apache License
@Override protected ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException { Git git = null;/*from ww w . j a v a2 s .co m*/ try { File basedir = fileSet.getBasedir(); git = Git.open(basedir); ObjectId objectId = git.getRepository().resolve("HEAD"); InfoItem infoItem = new InfoItem(); infoItem.setRevision(StringUtils.trim(objectId.name())); infoItem.setURL(basedir.getPath()); return new InfoScmResult(Collections.singletonList(infoItem), new ScmResult("JGit.resolve(HEAD)", "", objectId.toString(), true)); } catch (Exception e) { throw new ScmException("JGit resolve failure!", e); } finally { JGitUtils.closeRepo(git); } }