List of usage examples for org.eclipse.jgit.lib Repository shortenRefName
@NonNull public static String shortenRefName(String refName)
From source file:com.mooregreatsoftware.gitprocess.lib.SimpleFetchResult.java
License:Apache License
@Override public String toString() { final Collection<TrackingRefUpdate> trackingRefUpdates = fetchResult.getTrackingRefUpdates(); return trackingRefUpdates.stream() .map(tr -> String.format(" %s (%s): %s..%s %s", Repository.shortenRefName(tr.getRemoteName()), Repository.shortenRefName(tr.getLocalName()), tr.getOldObjectId().abbreviate(7).name(), tr.getNewObjectId().abbreviate(7).name(), tr.getResult())) .collect(Collectors.joining("\n")); }
From source file:models.PullRequest.java
License:Apache License
/** * Make merge commit message e.g./*from w w w .j a va 2 s. c o m*/ * * Merge branch 'dev' of dlab/hive into 'next' * * from pull-request 10 * * @param commits * @return * @throws IOException */ private String makeMergeCommitMessage(List<GitCommit> commits) throws IOException { StringBuilder builder = new StringBuilder(); builder.append("Merge branch "); builder.append("\'"); builder.append(Repository.shortenRefName(fromBranch)); builder.append("\'"); if (!fromProject.equals(toProject)) { builder.append(" of "); builder.append(fromProject.owner); builder.append("/"); builder.append(fromProject.name); } if (toBranch.equals("refs/heads/master")) { builder.append("\n\n"); } else { builder.append(" into "); builder.append("\'"); builder.append(Repository.shortenRefName(toBranch)); builder.append("\'"); builder.append("\n\n"); } builder.append("from pull-request "); builder.append(number); builder.append("\n\n"); addCommitMessages(commits, builder); addReviewers(builder); return builder.toString(); }
From source file:models.PullRequest.java
License:Apache License
private void addCommitMessages(List<GitCommit> commits, StringBuilder builder) { builder.append(String.format("* %s:\n", Repository.shortenRefName(this.fromBranch))); for (GitCommit gitCommit : commits) { builder.append(String.format(" %s\n", gitCommit.getShortMessage())); }//from w w w . jav a 2 s . c o m builder.append("\n"); }
From source file:org.ajoberstar.reckon.core.git.GitInventorySupplier.java
License:Apache License
GitInventorySupplier(Repository repo, Function<String, Optional<String>> tagSelector) { this.repo = repo; this.tagParser = ref -> { String tagName = Repository.shortenRefName(ref.getName()); return tagSelector.apply(tagName).flatMap(Versions::valueOf); };//from w ww. ja v a2s. c o m }
From source file:org.apache.maven.scm.provider.git.jgit.command.branch.JGitBranchCommand.java
License:Apache License
/** * gets a set of names of the available branches in the given repo * /*from w w w .j ava 2s . com*/ * @param git the repo to list the branches for * @return set of short branch names * @throws GitAPIException */ public static Set<String> getShortLocalBranchNames(Git git) throws GitAPIException { Set<String> branches = new HashSet<String>(); Iterator<Ref> iter = git.branchList().call().iterator(); while (iter.hasNext()) { branches.add(Repository.shortenRefName(iter.next().getName())); } return branches; }
From source file:org.apache.maven.scm.provider.git.jgit.command.remoteinfo.JGitRemoteInfoCommand.java
License:Apache License
@Override public RemoteInfoScmResult executeRemoteInfoCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException { GitScmProviderRepository repo = (GitScmProviderRepository) repository; Git git = null;/*from ww w. ja v a 2s. c o m*/ try { git = Git.open(fileSet.getBasedir()); CredentialsProvider credentials = JGitUtils.getCredentials(repo); LsRemoteCommand lsCommand = git.lsRemote().setRemote(repo.getPushUrl()) .setCredentialsProvider(credentials); Map<String, String> tag = new HashMap<String, String>(); Collection<Ref> allTags = lsCommand.setHeads(false).setTags(true).call(); for (Ref ref : allTags) { tag.put(Repository.shortenRefName(ref.getName()), ref.getObjectId().name()); } Map<String, String> heads = new HashMap<String, String>(); Collection<Ref> allHeads = lsCommand.setHeads(true).setTags(false).call(); for (Ref ref : allHeads) { heads.put(Repository.shortenRefName(ref.getName()), ref.getObjectId().name()); } return new RemoteInfoScmResult("JGit remoteinfo", heads, tag); } catch (Exception e) { throw new ScmException("JGit remoteinfo failure!", e); } finally { JGitUtils.closeRepo(git); } }
From source file:org.codehaus.mojo.versions.BumpMojo.java
License:Apache License
void gitPush(String d) throws MojoExecutionException { String origin = git.getRepository().getConfig().getString("branch", d, "remote"); String merge = git.getRepository().getConfig().getString("branch", d, "merge"); merge = Repository.shortenRefName(merge); gitPush(origin, merge);/*w w w . ja v a2 s . c om*/ }
From source file:org.codehaus.mojo.versions.BumpMojo.java
License:Apache License
void gitRebase() throws MojoExecutionException { try {//from ww w . java2 s . c om RebaseCommand ff = git.rebase(); String masterOrigin = git.getRepository().getConfig().getString("branch", master, "remote"); String masterMerge = git.getRepository().getConfig().getString("branch", master, "merge"); masterMerge = Repository.shortenRefName(masterMerge); RevWalk walk = new RevWalk(git.getRepository()); RevCommit commit = walk .parseCommit(git.getRepository().getRef(masterOrigin + "/" + masterMerge).getObjectId()); ff.setUpstream(commit); RebaseResult f = ff.call(); if (!f.getStatus().isSuccessful()) { throw new MojoExecutionException(f.getStatus().toString()); } } catch (GitAPIException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (MissingObjectException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IncorrectObjectTypeException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:org.debian.dependency.sources.JGitSource.java
License:Apache License
private void setupRepo() throws GitAPIException, IOException { if (git.status().call().hasUncommittedChanges()) { throw new IllegalStateException("Uncommitted changes detected in tree. Remove before continuing."); }//from w ww.j av a 2 s .co m Ref branchRef = null; for (Ref ref : git.branchList().call()) { if (WORK_BRANCH.equals(Repository.shortenRefName(ref.getName()))) { branchRef = ref; break; } } // assume its setup correctly if its there if (branchRef != null) { return; } // assume the current branch is the correct one Ref headRef = git.getRepository().getRef(Constants.HEAD).getLeaf(); try { // detach head so we don't modify any existing branches git.checkout().setName(ObjectId.toString(headRef.getObjectId())).call(); removeFilesEndsWith(".class", COMMIT_MESSAGE_PREFIX + " Removing class files"); RevCommit newRef = removeFilesEndsWith(".jar", COMMIT_MESSAGE_PREFIX + " Removing jar files"); // now all automated setup routines have been accomplished git.branchCreate().setName(WORK_BRANCH).setStartPoint(newRef).call(); } finally { // failsafe git.getRepository().updateRef(Constants.HEAD).link(headRef.getName()); } }
From source file:org.debian.dependency.sources.TestJGitSource.java
License:Apache License
/** When initializing an existing git repository, we should preserve its history. */ @Test//from w ww .j a va2 s . com public void testInitGit() throws Exception { assertNull("Branch should not exist before first init", git.getRepository().resolve(WORK_BRANCH)); source.initialize(directory, ORIGIN); assertNotNull("Branch must exist after init", git.getRepository().resolve(WORK_BRANCH)); Ref headRef = git.getRepository().getRef(Constants.HEAD).getTarget(); assertEquals("Head should point to the work branch", WORK_BRANCH, Repository.shortenRefName(headRef.getName())); }