List of usage examples for org.eclipse.jgit.lib Constants R_HEADS
String R_HEADS
To view the source code for org.eclipse.jgit.lib Constants R_HEADS.
Click Source Link
From source file:org.eclipse.egit.ui.internal.repository.tree.PropertyTester.java
License:Open Source License
/** * TODO javadoc missing//from ww w. j a v a2 s . c o m */ 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$ Repository rep = node.getRepository(); return rep.getConfig().getBoolean("core", "bare", false); //$NON-NLS-1$//$NON-NLS-2$ } if (property.equals("isRefCheckedOut")) { //$NON-NLS-1$ if (!(node.getObject() instanceof Ref)) return false; Ref ref = (Ref) node.getObject(); try { return ref.getName().equals(node.getRepository().getFullBranch()); } 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) { // TODO Exception handling rconfig = null; } boolean fetchExists = rconfig != null && !rconfig.getURIs().isEmpty(); return fetchExists; } } 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) { // TODO Exception handling rconfig = null; } boolean pushExists = rconfig != null && !rconfig.getPushURIs().isEmpty(); return pushExists; } } if (property.equals("canMerge")) { //$NON-NLS-1$ Repository rep = node.getRepository(); try { return rep.getFullBranch().startsWith(Constants.R_HEADS); } catch (IOException e) { return false; } } return false; }
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 {//from w w w .j a va 2s. co 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.internal.search.CommitSearchQuery.java
License:Open Source License
private void walkRepository(Repository repository, Pattern pattern, IProgressMonitor monitor) throws IOException { RevWalk walk = new RevWalk(repository); try {//ww w. j a v a2 s. c om walk.setRetainBody(true); List<RevCommit> commits = new LinkedList<RevCommit>(); if (this.settings.isAllBranches()) { for (Ref ref : repository.getRefDatabase().getRefs(Constants.R_HEADS).values()) if (!ref.isSymbolic()) commits.add(walk.parseCommit(ref.getObjectId())); for (Ref ref : repository.getRefDatabase().getRefs(Constants.R_REMOTES).values()) if (!ref.isSymbolic()) commits.add(walk.parseCommit(ref.getObjectId())); } else { ObjectId headCommit = repository.resolve(Constants.HEAD); if (headCommit != null) commits.add(walk.parseCommit(headCommit)); } if (!commits.isEmpty()) { walk.markStart(commits); for (RevCommit commit : walk) { if (monitor.isCanceled()) throw new OperationCanceledException(); for (SearchMatcher matcher : this.matchers) if (matcher.matches(pattern, commit)) { result.addResult(new RepositoryCommit(repository, commit)); break; } } } } finally { walk.dispose(); } }
From source file:org.eclipse.egit.ui.RepositoryUtil.java
License:Open Source License
/** * Tries to map a commit to a symbolic reference. * <p>//from w ww. j a va 2 s .c o m * This value will be cached for the given commit ID unless refresh is * specified. The return value will be the full name, e.g. * "refs/remotes/someBranch", "refs/tags/v.1.0" * <p> * Since this mapping is not unique, the following precedence rules are * used: * <ul> * <li>Tags take precedence over branches</li> * <li>Local branches take preference over remote branches</li> * <li>Newer references take precedence over older ones where time stamps * are available</li> * <li>If there are still ambiguities, the reference name with the highest * lexicographic value will be returned</li> * </ul> * * @param repository * the {@link Repository} * @param commitId * a commit * @param refresh * if true, the cache will be invalidated * @return the symbolic reference, or <code>null</code> if no such reference * can be found */ public String mapCommitToRef(Repository repository, String commitId, boolean refresh) { synchronized (commitMappingCache) { if (!ObjectId.isId(commitId)) { return null; } Map<String, String> cacheEntry = commitMappingCache.get(repository.getDirectory().toString()); if (!refresh && cacheEntry != null && cacheEntry.containsKey(commitId)) { // this may be null in fact return cacheEntry.get(commitId); } if (cacheEntry == null) { cacheEntry = new HashMap<String, String>(); commitMappingCache.put(repository.getDirectory().getPath(), cacheEntry); } else { cacheEntry.clear(); } Map<String, Date> tagMap = new HashMap<String, Date>(); try { Map<String, Ref> tags = repository.getRefDatabase().getRefs(Constants.R_TAGS); for (Ref tagRef : tags.values()) { Tag tag = repository.mapTag(tagRef.getName()); if (tag.getObjId().name().equals(commitId)) { Date timestamp; if (tag.getTagger() != null) { timestamp = tag.getTagger().getWhen(); } else { timestamp = null; } tagMap.put(tagRef.getName(), timestamp); } } } catch (IOException e) { // ignore here } String cacheValue = null; if (!tagMap.isEmpty()) { // we try to obtain the "latest" tag Date compareDate = new Date(0); for (Map.Entry<String, Date> tagEntry : tagMap.entrySet()) { if (tagEntry.getValue() != null && tagEntry.getValue().after(compareDate)) { compareDate = tagEntry.getValue(); cacheValue = tagEntry.getKey(); } } // if we don't have time stamps, we sort if (cacheValue == null) { String compareString = ""; //$NON-NLS-1$ for (String tagName : tagMap.keySet()) { if (tagName.compareTo(compareString) >= 0) { cacheValue = tagName; compareString = tagName; } } } } if (cacheValue == null) { // we didnt't find a tag, so let's look for local branches Set<String> branchNames = new TreeSet<String>(); // put this into a sorted set try { Map<String, Ref> remoteBranches = repository.getRefDatabase().getRefs(Constants.R_HEADS); for (Ref branch : remoteBranches.values()) { if (branch.getObjectId().name().equals(commitId)) { branchNames.add(branch.getName()); } } } catch (IOException e) { // ignore here } if (!branchNames.isEmpty()) { // get the last (sorted) entry cacheValue = branchNames.toArray(new String[branchNames.size()])[branchNames.size() - 1]; } } if (cacheValue == null) { // last try: remote branches Set<String> branchNames = new TreeSet<String>(); // put this into a sorted set try { Map<String, Ref> remoteBranches = repository.getRefDatabase().getRefs(Constants.R_REMOTES); for (Ref branch : remoteBranches.values()) { if (branch.getObjectId().name().equals(commitId)) { branchNames.add(branch.getName()); } } if (!branchNames.isEmpty()) { // get the last (sorted) entry cacheValue = branchNames.toArray(new String[branchNames.size()])[branchNames.size() - 1]; } } catch (IOException e) { // ignore here } } cacheEntry.put(commitId, cacheValue); return cacheValue; } }
From source file:org.eclipse.egit.ui.submodule.SubmoduleUpdateTest.java
License:Open Source License
@Test public void updateSubmodule() throws Exception { deleteAllProjects();//from w w w .j a v a 2 s . co m assertProjectExistence(PROJ1, false); clearView(); Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryFile); shareProjects(repositoryFile); assertProjectExistence(PROJ1, true); refreshAndWait(); assertHasRepo(repositoryFile); FileRepository repo = lookupRepository(repositoryFile); ObjectId repoHead = repo.resolve(Constants.HEAD); SubmoduleAddCommand command = new SubmoduleAddCommand(repo); String path = "sub"; command.setPath(path); String uri = new URIish(repo.getDirectory().toURI().toString()).toString(); command.setURI(uri); Repository subRepo = command.call(); assertNotNull(subRepo); Ref head = subRepo.getRef(Constants.HEAD); assertNotNull(head); assertTrue(head.isSymbolic()); assertEquals(Constants.R_HEADS + Constants.MASTER, head.getLeaf().getName()); assertEquals(repoHead, head.getObjectId()); refreshAndWait(); SWTBotTree tree = getOrOpenView().bot().tree(); tree.getAllItems()[0].expand().expandNode(UIText.RepositoriesViewLabelProvider_SubmodulesNodeText).select(); ContextMenuHelper.clickContextMenuSync(tree, myUtil.getPluginLocalizedValue(UPDATE_SUBMODULE_CONTEXT_MENU_LABEL)); TestUtil.joinJobs(JobFamilies.SUBMODULE_UPDATE); refreshAndWait(); head = subRepo.getRef(Constants.HEAD); assertNotNull(head); assertFalse(head.isSymbolic()); assertEquals(repoHead, head.getObjectId()); }
From source file:org.eclipse.egit.ui.test.history.HistoryViewTest.java
License:Open Source License
@Test public void testAddBranch() throws Exception { Repository repo = lookupRepository(repoFile); assertNull(repo.resolve(Constants.R_HEADS + "NewBranch")); SWTBotTable table = getHistoryViewTable(PROJ1); SWTBotTableItem item = table.getTableItem(0); item.select();// ww w . ja v a 2s.c om ContextMenuHelper.clickContextMenu(table, UIText.GitHistoryPage_CreateBranchMenuLabel); SWTBotShell dialog = bot.shell(UIText.CreateBranchWizard_NewBranchTitle); dialog.bot().textWithId("BranchName").setText("NewBranch"); // for some reason, checkboxwithlabel doesn't seem to work dialog.bot().checkBox().deselect(); dialog.bot().button(IDialogConstants.FINISH_LABEL).click(); assertNotNull(repo.resolve(Constants.R_HEADS + "NewBranch")); }
From source file:org.eclipse.egit.ui.wizards.clone.SampleTestRepository.java
License:Open Source License
private void generateSampleData(int n) throws Exception { A_txt = src.blob("A"); A = src.commit().add(A_txt_name, A_txt).create(); src.update(Constants.R_HEADS + Constants.MASTER, A); // create some random commits RevCommit X = A;//from w w w.j av a 2 s . c o m for (int i = 0; i < n; i++) { X = src.commit().parent(X).add(randomAsciiString(), randomAsciiString()).create(); } B = src.commit().parent(X).add(A_txt_name, "C").add("B", "B").create(); src.update(Constants.R_HEADS + Constants.MASTER, B); v1_0 = src.tag(v1_0_name, B); src.update(Constants.R_TAGS + v1_0_name, v1_0); C = src.commit().parent(A).add(A_txt_name, "D").add("C", "C").create(); src.update(Constants.R_HEADS + FIX, C); v2_0 = src.tag(v2_0_name, C); src.update(Constants.R_TAGS + v2_0_name, v2_0); }
From source file:org.eclipse.mylyn.internal.github.ui.gist.CloneGistHandler.java
License:Open Source License
private CloneOperation createCloneOperation(TaskData data, String name) throws IOException, URISyntaxException { String pullUrl = data.getRoot().getAttribute(GistAttribute.CLONE_URL.getMetadata().getId()).getValue(); URIish uri = new URIish(pullUrl); int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); final File workDir = new File(getParentDirectory(), name); if (getRepoUtil().getConfiguredRepositories() .contains(new File(workDir, Constants.DOT_GIT).getAbsolutePath())) throw new IOException(MessageFormat.format(Messages.CloneGistHandler_ErrorRepoExists, name)); return new CloneOperation(uri, true, null, workDir, Constants.R_HEADS + Constants.MASTER, Constants.DEFAULT_REMOTE_NAME, timeout); }
From source file:org.eclipse.mylyn.internal.github.ui.RepositoryImportWizard.java
License:Open Source License
private CloneOperation createCloneOperation(SearchRepository repo, RepositoryService service) throws IOException, URISyntaxException { Repository fullRepo = service.getRepository(repo); URIish uri = new URIish(fullRepo.getCloneUrl()); IPreferenceStore store = org.eclipse.egit.ui.Activator.getDefault().getPreferenceStore(); String defaultRepoDir = store.getString(UIPreferences.DEFAULT_REPO_DIR); File directory = new File(new File(defaultRepoDir, repo.getOwner()), repo.getName()); int timeout = store.getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); return new CloneOperation(uri, true, null, directory, Constants.R_HEADS + Constants.MASTER, Constants.DEFAULT_REMOTE_NAME, timeout); }
From source file:org.eclipse.orion.server.git.jobs.FetchJob.java
License:Open Source License
private IStatus doFetch() throws IOException, CoreException, URISyntaxException, GitAPIException { Repository db = getRepository();/*from w w w .j a va2 s . c om*/ Git git = new Git(db); FetchCommand fc = git.fetch(); RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), remote); credentials.setUri(remoteConfig.getURIs().get(0)); fc.setCredentialsProvider(credentials); fc.setRemote(remote); if (branch != null) { // refs/heads/{branch}:refs/remotes/{remote}/{branch} RefSpec spec = new RefSpec( Constants.R_HEADS + branch + ":" + Constants.R_REMOTES + remote + "/" + branch); //$NON-NLS-1$ //$NON-NLS-2$ spec = spec.setForceUpdate(force); fc.setRefSpecs(spec); } FetchResult fetchResult = fc.call(); return handleFetchResult(fetchResult); }