List of usage examples for org.eclipse.jgit.lib ObjectId getName
public final String getName()
From source file:org.gradle.vcs.git.internal.GitVersionRef.java
License:Apache License
public static GitVersionRef from(Ref ref) { ObjectId commitId = ref.getPeeledObjectId() == null ? ref.getObjectId() : ref.getPeeledObjectId(); return new GitVersionRef(extractName(ref), commitId.getName()); }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
private void assertDetachedHead(GitClient client, ObjectId ref) throws Exception { CliGitCommand gitCmd = new CliGitCommand(client); gitCmd.run("status"); if (CLI_GIT_REPORTS_DETACHED_SHA1) { gitCmd.assertOutputContains(".*(Not currently on any branch|HEAD detached).*", ".*" + ref.getName().substring(0, 6) + ".*"); } else {//from ww w.j ava2s . c o m gitCmd.assertOutputContains(".*Not currently on any branch.*"); } }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
@Test public void testModifiedTrackedFilesReset() throws Exception { ObjectId commitA = commitOneFile("First commit"); /* Modify every plain file in the root of the repository */ String randomUUID = UUID.randomUUID().toString(); String randomString = "Added after initial file checkin " + randomUUID + "\n"; File lastModifiedFile = null; for (File file : repoRoot.listFiles()) { if (file.isFile()) { try (PrintWriter writer = new PrintWriter( new OutputStreamWriter(Files.newOutputStream(file.toPath()), "UTF-8"), true)) { writer.print(randomString); }// w w w . ja v a 2 s. co m lastModifiedFile = file; } } assertTrue("No files modified " + repoRoot, lastModifiedFile != null); /* Checkout a new branch - verify no files retain modification */ gitClient.checkout().branch("master-" + randomUUID).ref(commitA.getName()).execute(); lastModifiedFile = null; for (File file : repoRoot.listFiles()) { if (file.isFile()) { List<String> lines = Files.readAllLines(file.toPath(), Charset.forName("UTF-8")); for (String line : lines) { if (line.contains(randomString)) { lastModifiedFile = file; } } } } assertNull("Checkout did not revert change in " + lastModifiedFile, lastModifiedFile); }
From source file:org.jenkinsci.plugins.github_branch_source.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 {/*from w ww .ja v a 2 s . c o 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) { // 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:org.jenkinsci.plugins.pretestpipelineplugin.PretestPreparer.java
License:Open Source License
@Override public void perform(Run<?, ?> run, FilePath fp, Launcher lnchr, TaskListener tl) throws InterruptedException, IOException { //String assertions before perform assert mode.equals("squash") || mode.equals("accumulate"); GitClient c = PretestShared.createClient(tl, run, fp, workspace, credentialsId); if (mode.equals("squash")) { tl.getLogger().println("[PRETESTED] Squash mode selected"); ObjectId oid = c.revParse("HEAD"); c.checkout().ref(integrationBranch).execute(); ObjectId oidCurrentBranchHead = c.revParse("HEAD"); //Generate changelog from currentBranchHead which is now being merged with c.merge().setRevisionToMerge(oid).setSquash(true).execute(); //TODO//ww w. ja va 2 s.c o m c.commit("Whaatt?"); } else { tl.getLogger().println("[PRETESTED] Accumulated mode selected"); //Record current HEAD ObjectId oid = c.revParse("HEAD"); //This checkout command is much more intelligent. It know to set up a remote tracking branch c.checkout().ref(integrationBranch).execute(); ObjectId oidCurrentBranchHead = c.revParse("HEAD"); String commitAuthor = c .withRepository(new PretestShared.FindCommitAuthorCallback(tl, oidCurrentBranchHead)); c.setAuthor(getPersonIdent(commitAuthor)); //Use the client to write the changelog StringWriter wr = new StringWriter(); c.changelog(oidCurrentBranchHead.name(), oid.getName(), wr); c.merge().setMessage(wr.toString()).setRevisionToMerge(oid) .setGitPluginFastForwardMode(MergeCommand.GitPluginFastForwardMode.NO_FF).execute(); } }
From source file:org.kercoin.magrit.sshd.commands.SendBuildCommand.java
License:Open Source License
private void sendBuild(ObjectId newId, ObjectId cmdId) { try {//from w w w . j a v a2 s. c o m if (buildQueueService.enqueueBuild(committer, repo, newId.getName(), cmdId.getName(), force) != null) { String msg = String.format("Triggering build for commit %s on repository %s by %s.", newId.getName(), repo.getDirectory(), committer); log.info(msg); this.out.write('1'); } else { String msg = String.format("Asked to build the commit %s on repository %s by %s but was skipped", newId.getName(), repo.getDirectory(), committer); log.info(msg); this.out.write('0'); } this.out.write('\n'); this.out.flush(); } catch (Exception e) { log.error("Unable to send build", e); e.printStackTrace(); } }
From source file:org.kuali.student.git.cleaner.RepositorySplitter.java
License:Educational Community License
@Override protected void onNewCommit(RevCommit commit, ObjectId newCommitId) { // intentionally not calling the constructor if (removedParents.size() > 0) { // create the graft. List<String> graftData = new ArrayList<>(); graftData.add(newCommitId.getName()); for (ObjectId parentId : newParents) { graftData.add(parentId.getName()); }//from w w w. jav a 2s .c o m for (ObjectId parentId : removedParents) { graftData.add(parentId.getName()); } pw.println(StringUtils.join(graftData, " ")); /* * Make sure there is a branch or tag on the left side ref * * and if not then put a branch to prevent the graph from being * gc'ed. * * We use a branch and not a tag because branches are namespaced * but tags are global. */ for (ObjectId leftCommitId : removedParents) { if (!commitToTagMap.containsKey(leftCommitId) && !commitToBranchMap.containsKey(leftCommitId) && !leftSidePreventGCCommits.contains(leftCommitId)) { String preventGCBranchName = Constants.R_HEADS + "prevent_gc_" + counter; // put a branch deferCreate(preventGCBranchName, leftCommitId); counter++; leftSidePreventGCCommits.add(leftCommitId); leftRefsWriter.println(preventGCBranchName); } } } }
From source file:org.kuali.student.git.model.SvnRevisionMapper.java
License:Educational Community License
@Override public String storeLargeBranchName(String branchName, long revision) { try {// w w w.ja v a2 s.com ObjectId largeBranchNameId = GitBranchUtils.getBranchNameObjectId(branchName); String existingBranchName = getBranchName(largeBranchNameId.name(), revision); if (existingBranchName != null) return largeBranchNameId.getName(); File revisionFile = new File(revisonMappings, "r" + revision + "-large-branches"); PrintWriter pw = new PrintWriter(new FileOutputStream(revisionFile, true)); pw.println(largeBranchNameId.name() + "::" + branchName); pw.flush(); pw.close(); return largeBranchNameId.name(); } catch (FileNotFoundException e) { log.warn("storeLargeBranchName: failed to open r" + revision + "-large-branches"); return null; } }
From source file:org.kuali.student.git.utils.ExternalGitUtils.java
License:Educational Community License
public static boolean updateRef(String externalGitCommand, Repository repo, String absoluteRefName, ObjectId objectId, boolean force, OutputStream redirectStream) throws IOException { List<String> commandOptions = new ArrayList<>(); commandOptions.add("branch"); if (force)/*w ww . jav a2s . c o m*/ commandOptions.add("-f"); commandOptions.add(absoluteRefName); commandOptions.add(objectId.getName()); try { Process p = runGitCommand(repo, true, commandOptions); waitFor(p, redirectStream); if (p.exitValue() == 0) return true; else return false; } catch (InterruptedException e) { } return false; }
From source file:org.kuali.student.git.utils.ExternalGitUtils.java
License:Educational Community License
/** * Run the batch ref updates using the external git command instead of the * JGit command.// w w w . j av a2s . c o m * * @param externalGitCommand * @param repo * @param deferredReferenceDeletes * @param redirectStream * @throws IOException */ public static void batchRefUpdate(String externalGitCommand, Repository repo, List<ReceiveCommand> deferredReferenceDeletes, OutputStream redirectStream) throws IOException { for (ReceiveCommand receiveCommand : deferredReferenceDeletes) { String[] parts = receiveCommand.getRefName().split("/"); String refName = parts[parts.length - 1]; ObjectId refObjectId = receiveCommand.getNewId(); List<String> commandOptions = new ArrayList<>(); commandOptions.add(externalGitCommand); switch (receiveCommand.getType()) { case CREATE: commandOptions.add("branch"); commandOptions.add(refName); commandOptions.add(refObjectId.getName()); break; case DELETE: commandOptions.add("branch"); commandOptions.add("-D"); commandOptions.add(refName); break; case UPDATE: case UPDATE_NONFASTFORWARD: commandOptions.add("branch"); commandOptions.add("-f"); commandOptions.add(refName); commandOptions.add(refObjectId.getName()); break; } try { Process p = runGitCommand(repo, true, commandOptions); waitFor(p, redirectStream); if (p.exitValue() == 0) { // normal termination if (receiveCommand.getType().equals(Type.CREATE)) { // C git doesn't say anything in this case so log it redirectStream.write(("Created branch " + receiveCommand.getRefName() + "\n").getBytes()); } } } catch (InterruptedException e) { } } }