List of usage examples for org.eclipse.jgit.lib Constants R_REFS
String R_REFS
To view the source code for org.eclipse.jgit.lib Constants R_REFS.
Click Source Link
From source file:org.eclipse.egit.ui.internal.repository.tree.command.CheckoutCommand.java
License:Open Source License
public Object execute(final ExecutionEvent event) throws ExecutionException { final RepositoryTreeNode node = getSelectedNodes(event).get(0); if (!(node.getObject() instanceof Ref)) return null; final Ref ref = (Ref) node.getObject(); Repository repo = node.getRepository(); String refName = ref.getLeaf().getName(); final BranchOperation op; if (refName.startsWith(Constants.R_REFS)) op = new BranchOperation(repo, ref.getName()); else//from w w w . j a v a 2 s.co m op = new BranchOperation(repo, ref.getLeaf().getObjectId()); // for the sake of UI responsiveness, let's start a job Job job = new Job(NLS.bind(UIText.RepositoriesView_CheckingOutMessage, ref.getName())) { @Override protected IStatus run(IProgressMonitor monitor) { IWorkspaceRunnable wsr = new IWorkspaceRunnable() { public void run(IProgressMonitor myMonitor) throws CoreException { op.execute(myMonitor); } }; try { ResourcesPlugin.getWorkspace().run(wsr, ResourcesPlugin.getWorkspace().getRoot(), IWorkspace.AVOID_UPDATE, monitor); } catch (CoreException e1) { return new Status(IStatus.ERROR, Activator.getPluginId(), e1.getMessage(), e1); } return Status.OK_STATUS; } @Override public boolean belongsTo(Object family) { if (family.equals(JobFamilies.CHECKOUT)) return true; return super.belongsTo(family); } }; job.setUser(true); job.schedule(); return null; }
From source file:org.eclipse.egit.ui.internal.repository.tree.RepositoriesViewPropertyTester.java
License:Open Source License
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (!(receiver instanceof RepositoryTreeNode)) return false; RepositoryTreeNode node = (RepositoryTreeNode) receiver; if (property.equals("isBare")) //$NON-NLS-1$ return node.getRepository().isBare(); if (property.equals("isSafe")) //$NON-NLS-1$ return node.getRepository().getRepositoryState() == RepositoryState.SAFE; if (property.equals("isRefCheckedOut")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) return false; Ref ref = (Ref) node.getObject(); try {/*w ww . j av a 2s. c o m*/ if (ref.getName().startsWith(Constants.R_REFS)) { return ref.getName().equals(node.getRepository().getFullBranch()); } else if (ref.getName().equals(Constants.HEAD)) return true; else { String leafname = ref.getLeaf().getName(); if (leafname.startsWith(Constants.R_REFS) && leafname.equals(node.getRepository().getFullBranch())) return true; else ref.getLeaf().getObjectId().equals(node.getRepository().resolve(Constants.HEAD)); } } catch (IOException e) { return false; } } if (property.equals("isLocalBranch")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) return false; Ref ref = (Ref) node.getObject(); return ref.getName().startsWith(Constants.R_HEADS); } if (property.equals("fetchExists")) { //$NON-NLS-1$ if (node instanceof RemoteNode) { String configName = ((RemoteNode) node).getObject(); RemoteConfig rconfig; try { rconfig = new RemoteConfig(node.getRepository().getConfig(), configName); } catch (URISyntaxException e2) { return false; } // we need to have a fetch ref spec and a fetch URI return !rconfig.getFetchRefSpecs().isEmpty() && !rconfig.getURIs().isEmpty(); } } if (property.equals("pushExists")) { //$NON-NLS-1$ if (node instanceof RemoteNode) { String configName = ((RemoteNode) node).getObject(); RemoteConfig rconfig; try { rconfig = new RemoteConfig(node.getRepository().getConfig(), configName); } catch (URISyntaxException e2) { return false; } // we need to have at least a push ref spec and any URI return !rconfig.getPushRefSpecs().isEmpty() && (!rconfig.getPushURIs().isEmpty() || !rconfig.getURIs().isEmpty()); } } if (property.equals("canMerge")) { //$NON-NLS-1$ Repository rep = node.getRepository(); if (rep.getRepositoryState() != RepositoryState.SAFE) return false; try { String branch = rep.getFullBranch(); if (branch == null) return false; // fail gracefully... return branch.startsWith(Constants.R_HEADS); } catch (IOException e) { return false; } } if (property.equals("canAbortRebase")) //$NON-NLS-1$ switch (node.getRepository().getRepositoryState()) { case REBASING_INTERACTIVE: return true; default: return false; } return false; }
From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTagHandlingTest.java
License:Open Source License
private String getObjectIdOfCommit() throws Exception { String branch = repository.getFullBranch(); if (ObjectId.isId(branch)) return branch; if (branch.startsWith(Constants.R_REFS)) { RevCommit commit = revWalk.parseCommit(repository.resolve(branch)); return commit.getId().getName(); }//ww w .j av a 2s .c om if (branch.startsWith(Constants.R_TAGS)) { RevTag tag = revWalk.parseTag(repository.resolve(branch)); return tag.getObject().getId().name(); } throw new IllegalStateException("Can't resolve commit"); }
From source file:org.fedoraproject.eclipse.packager.tests.commands.ConvertLocalToRemoteCommandTest.java
License:Open Source License
/** * Test if the command works properly//from w w w .j ava 2 s .com * when there is no remote repository added manually * * @throws Exception */ @Test public void testConvertCommand() throws Exception { boolean localRefsOk = false; ConvertLocalToRemoteCommand convertCmd; convertCmd = (ConvertLocalToRemoteCommand) packager.getCommandInstance(ConvertLocalToRemoteCommand.ID); convertCmd.call(new NullProgressMonitor()); // Make sure the property of the project changed // from local to main fedorapackager assertTrue(lfpRoot.getProject().getPersistentProperty(PackagerPlugin.PROJECT_PROP).equals("true")); //$NON-NLS-1$ assertNull(lfpRoot.getProject().getPersistentProperty(PackagerPlugin.PROJECT_LOCAL_PROP)); // Make sure the url for remote repository is correct assertTrue(projectBits.getScmUrl().contains("pkgs.fedoraproject.org/alchemist.git")); //$NON-NLS-1$ // Find the local repository in the project location findGitRepository(); // Make sure the current checked out branch is master assertTrue(git.getRepository().getBranch().equals("master")); //$NON-NLS-1$ // Check a random branch (f10), // and make sure both remote and local version of it exists List<Ref> remoteRefs = git.branchList().setListMode(ListMode.REMOTE).call(); assertTrue( remoteRefs.toString().contains("refs/remotes/origin/f10=2f12e50b9860dc05cf3ac09c1cd82b45fae28637")); //$NON-NLS-1$ Map<String, Ref> localRefs = git.getRepository().getRefDatabase().getRefs(Constants.R_REFS); for (Ref refValue : localRefs.values()) { if (refValue.toString().contains("refs/heads/f10=2f12e50b9860dc05cf3ac09c1cd82b45fae28637")) { //$NON-NLS-1$ localRefsOk = true; } } assertTrue(localRefsOk); }
From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMBuilder.java
License:Open Source License
/** * {@inheritDoc}/* www . ja v a2s .c o m*/ */ @NonNull @Override public GitSCM build() { final SCMHead h = head(); final SCMRevision r = revision(); try { withGitHubRemote(); if (h instanceof PullRequestSCMHead) { PullRequestSCMHead head = (PullRequestSCMHead) h; if (head.isMerge()) { // add the target branch to ensure that the revision we want to merge is also available String name = head.getTarget().getName(); String localName = "remotes/" + remoteName() + "/" + name; Set<String> localNames = new HashSet<>(); boolean match = false; String targetSrc = Constants.R_HEADS + name; String targetDst = Constants.R_REMOTES + remoteName() + "/" + name; for (RefSpec b : asRefSpecs()) { String dst = b.getDestination(); assert dst.startsWith(Constants.R_REFS) : "All git references must start with refs/"; if (targetSrc.equals(b.getSource())) { if (targetDst.equals(dst)) { match = true; } else { // pick up the configured destination name localName = dst.substring(Constants.R_REFS.length()); match = true; } } else { localNames.add(dst.substring(Constants.R_REFS.length())); } } if (!match) { if (localNames.contains(localName)) { // conflict with intended name localName = "remotes/" + remoteName() + "/upstream-" + name; } if (localNames.contains(localName)) { // conflict with intended alternative name localName = "remotes/" + remoteName() + "/pr-" + head.getNumber() + "-upstream-" + name; } if (localNames.contains(localName)) { // ok we're just going to mangle our way to something that works Random entropy = new Random(); while (localNames.contains(localName)) { localName = "remotes/" + remoteName() + "/pr-" + head.getNumber() + "-upstream-" + name + "-" + Integer.toHexString(entropy.nextInt(Integer.MAX_VALUE)); } } withRefSpec("+refs/heads/" + name + ":refs/" + localName); } withExtension(new MergeWithGitSCMExtension(localName, r instanceof PullRequestSCMRevision ? ((PullRequestSCMRevision) r).getBaseHash() : null)); } if (r instanceof PullRequestSCMRevision) { PullRequestSCMRevision rev = (PullRequestSCMRevision) r; withRevision(new AbstractGitSCMSource.SCMRevisionImpl(head, rev.getPullHash())); } } return super.build(); } finally { withHead(h); withRevision(r); } }
From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMFile.java
License:Open Source License
private Object metadata() throws IOException { if (metadata == null && !resolved) { try {//from www . j a v a 2 s . c o m switch (info) { case DIRECTORY_ASSUMED: metadata = repo.getDirectoryContent(getPath(), ref.indexOf('/') == -1 ? ref : Constants.R_REFS + ref); info = TypeInfo.DIRECTORY_CONFIRMED; resolved = true; break; case DIRECTORY_CONFIRMED: metadata = repo.getDirectoryContent(getPath(), ref.indexOf('/') == -1 ? ref : Constants.R_REFS + ref); resolved = true; break; case NON_DIRECTORY_CONFIRMED: metadata = repo.getFileContent(getPath(), ref.indexOf('/') == -1 ? ref : Constants.R_REFS + ref); resolved = true; break; case UNRESOLVED: checkOpen(); try { metadata = repo.getFileContent(getPath(), ref.indexOf('/') == -1 ? ref : Constants.R_REFS + ref); info = TypeInfo.NON_DIRECTORY_CONFIRMED; resolved = true; } catch (IOException e) { if (e.getCause() instanceof IOException && e.getCause().getCause() instanceof JsonMappingException) { metadata = repo.getDirectoryContent(getPath(), ref.indexOf('/') == -1 ? ref : Constants.R_REFS + ref); info = TypeInfo.DIRECTORY_CONFIRMED; resolved = true; } else { throw e; } } break; } } catch (FileNotFoundException e) { metadata = null; resolved = true; } } return metadata; }
From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMFile.java
License:Open Source License
@NonNull @Override/* w ww . ja v a 2s . c o m*/ public Iterable<SCMFile> children() throws IOException { checkOpen(); List<GHContent> content = repo.getDirectoryContent(getPath(), ref.indexOf('/') == -1 ? ref : Constants.R_REFS + ref); List<SCMFile> result = new ArrayList<>(content.size()); for (GHContent c : content) { result.add(new GitHubSCMFile(this, c.getName(), c)); } return result; }
From source file:org.jenkinsci.plugins.github_branch_source.GitHubSCMProbe.java
License:Open Source License
@NonNull @Override//w w w. ja va 2 s. co m public SCMProbeStat stat(@NonNull String path) throws IOException { checkOpen(); try { int index = path.lastIndexOf('/') + 1; List<GHContent> directoryContent = repo.getDirectoryContent(path.substring(0, index), Constants.R_REFS + ref); for (GHContent content : directoryContent) { if (content.getPath().equals(path)) { if (content.isFile()) { return SCMProbeStat.fromType(SCMFile.Type.REGULAR_FILE); } else if (content.isDirectory()) { return SCMProbeStat.fromType(SCMFile.Type.DIRECTORY); } else if ("symlink".equals(content.getType())) { return SCMProbeStat.fromType(SCMFile.Type.LINK); } else { return SCMProbeStat.fromType(SCMFile.Type.OTHER); } } if (content.getPath().equalsIgnoreCase(path)) { return SCMProbeStat.fromAlternativePath(content.getPath()); } } } catch (FileNotFoundException fnf) { // means that does not exist and this is handled below this try/catch block. } return SCMProbeStat.fromType(SCMFile.Type.NONEXISTENT); }
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;//from w ww . j a v a 2 s . c om 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", 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.sonatype.m2e.egit.internal.EgitScmHandler.java
License:Open Source License
protected String getRefName(MavenProjectScmInfo info) { String branch = info.getBranch(); if (branch == null || branch.trim().length() == 0) { branch = Constants.MASTER;//from w ww . jav a 2s . c om } if (!branch.startsWith(Constants.R_REFS)) { branch = Constants.R_HEADS + branch; } return branch; }