/** {@inheritDoc} */ public ObjectId revParse(String revName) throws GitException, InterruptedException { return proxy.revParse(revName); }
/** {@inheritDoc} */ public ObjectId revParse(String revName) throws GitException, InterruptedException { return Git.USE_CLI ? super.revParse(revName) : jgit.revParse(revName); }
private Map<String, BlameResult> loadBlameResultsForFiles(final Map<String, BlameRequest> linesOfConflictingFiles) throws InterruptedException, IOException { try { ObjectId headCommit = git.revParse(gitCommit); return git.withRepository(new BlameCallback(this, headCommit, linesOfConflictingFiles.values())); } catch (GitException exception) { log("Can't determine head commit using 'git rev-parse'. Skipping blame. %n%s%n", exception.getMessage()); return Collections.emptyMap(); } }
@Override public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException { String hash; try { hash = client.revParse(revision).name(); } catch (GitException x) { // Try prepending remote name in case it was a branch. try { hash = client.revParse(context.remoteName() + "/" + revision).name(); } catch (GitException x2) { listener.getLogger().println(x.getMessage()); listener.getLogger().println(x2.getMessage()); return null; } } return new SCMRevisionImpl(new SCMHead(revision), hash); } },
public Revision toRevision(GitClient git) throws InterruptedException { if (revision != null) { return revision; } ObjectId sha1 = git.revParse(commit); Revision revision = new Revision(sha1); // Here we do not have any local branches, containing the commit. So... // we are to get all the remote branches, and show them to users, as // they are local final List<Branch> branches = normalizeBranches(git.getBranchesContaining( ObjectId.toString(sha1), true)); revision.getBranches().addAll(branches); return revision; }
/** * Return a list of "Revisions" - where a revision knows about all the branch names that refer to * a SHA1. * @return list of revisions * @throws IOException on input or output error * @throws GitException on git error * @throws InterruptedException when interrupted */ public Collection<Revision> getAllBranchRevisions() throws GitException, IOException, InterruptedException { Map<ObjectId, Revision> revisions = new HashMap<>(); for (Branch b : git.getRemoteBranches()) { Revision r = revisions.get(b.getSHA1()); if (r == null) { r = new Revision(b.getSHA1()); revisions.put(b.getSHA1(), r); } r.getBranches().add(b); } for (String tag : git.getTagNames(null)) { String tagRef = Constants.R_TAGS + tag; ObjectId objectId = git.revParse(tagRef); Revision r = revisions.get(objectId); if (r == null) { r = new Revision(objectId); revisions.put(objectId, r); } r.getBranches().add(new Branch(tagRef, objectId)); } return revisions.values(); }
ObjectId headSha1 = git.revParse("HEAD");
private Collection<Revision> getHeadRevision(boolean isPollCall, String singleBranch, GitClient git, TaskListener listener, BuildData data) throws InterruptedException { try { ObjectId sha1 = git.revParse(singleBranch); verbose(listener, "rev-parse {0} -> {1}", singleBranch, sha1);
ObjectId sha1 = git.revParse(rev);
ObjectId sha1 = git.revParse(branchSpec); Revision revision = new Revision(sha1); revision.getBranches().add(new Branch("detached", sha1));
if (StringUtils.isBlank(baseHash)) { try { 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", 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
@Override public Build prevBuildForChangelog(String singleBranch, BuildData data, GitClient git, BuildChooserContext context) throws InterruptedException, IOException { if (data != null) { ObjectId sha1 = git.revParse("FETCH_HEAD"); // Now we cheat and add the parent as the last build on the branch, so we can // get the changelog working properly-ish. ObjectId parentSha1 = getFirstParent(sha1, git); Revision parentRev = new Revision(parentSha1); parentRev.getBranches().add(new Branch(singleBranch, parentSha1)); int prevBuildNum = 0; Result r = null; Build lastBuild = data.getLastBuildOfBranch(singleBranch); if (lastBuild != null) { prevBuildNum = lastBuild.getBuildNumber(); r = lastBuild.getBuildResult(); } return new Build(parentRev, prevBuildNum, r); } else { //Hmm no sure what to do here, but the git plugin can handle us returning null here return null; } }
@Override public SCMRevision run(GitClient client, String remoteName) throws IOException, InterruptedException { if (head instanceof GitTagSCMHead) { try { ObjectId objectId = client.revParse(Constants.R_TAGS + head.getName()); return new GitTagSCMRevision((GitTagSCMHead) head, objectId.name()); } catch (GitException e) { // tag does not exist return null; } } else { for (Branch b : client.getRemoteBranches()) { String branchName = StringUtils.removeStart(b.getName(), remoteName + "/"); if (branchName.equals(head.getName())) { return new SCMRevisionImpl(head, b.getSHA1String()); } } } return null; } },
FreeStyleBuild b = mock(FreeStyleBuild.class); GitClient git = mock(GitClient.class); when(git.revParse("FETCH_HEAD")).thenReturn(fetchHead); gerritCause.setEvent(patchsetCreated); when(b.getCause(GerritCause.class)).thenReturn(gerritCause); when(git.revParse(patchsetRefspec)).thenReturn(patchsetRevision); when(git.revParse(patchsetRevision.toString())).thenReturn(patchsetRevision);
@Override public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev) throws IOException, InterruptedException, GitException { listener.getLogger().println("Merging " + targetBranch.getName() + " commit " + targetBranch.getRevision().getHash() + " into merge-request head commit " + rev.getSha1String()); checkout(scm, build, git, listener, rev); try { git.setAuthor("Jenkins", /* could parse out of JenkinsLocationConfiguration.get().getAdminAddress() but seems overkill */"nobody@nowhere"); git.setCommitter("Jenkins", "nobody@nowhere"); MergeCommand cmd = git.merge().setRevisionToMerge(ObjectId.fromString(targetBranch.getRevision().getHash())); 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 e) { // Try to revert merge conflict markers. checkout(scm, build, git, listener, rev); throw e; } build.addAction(new MergeRecord(targetBranch.getRefSpec().destinationRef(targetBranch.getName()), targetBranch.getRevision().getHash())); // 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 }
@Override public Blames blame(final Report report) { try { report.logInfo("Invoking Git blamer to create author and commit information for all affected files"); report.logInfo("GIT_COMMIT env = '%s'", gitCommit); report.logInfo("Git working tree = '%s'", git.getWorkTree()); ObjectId headCommit = git.revParse(gitCommit); if (headCommit == null) { report.logError("Could not retrieve HEAD commit, aborting"); return new Blames(); } report.logInfo("Git commit ID = '%s'", headCommit.getName()); String workspacePath = getWorkspacePath(); report.logInfo("Job workspace = '%s'", workspacePath); return git.withRepository(new BlameCallback(report, headCommit, workspacePath)); } catch (IOException exception) { report.logException(exception, "Computing blame information failed with an exception:"); } catch (GitException exception) { report.logException(exception, "Can't determine head commit using 'git rev-parse'. Skipping blame."); } catch (InterruptedException e) { // nothing to do, already logged } return new Blames(); }