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.push.RefSpecDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite main = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(main); main.setLayout(new GridLayout(2, false)); URIish uriToCheck;/* w ww. j av a 2 s . com*/ if (pushMode) { if (config.getPushURIs().isEmpty()) uriToCheck = config.getURIs().get(0); else uriToCheck = config.getPushURIs().get(0); } else uriToCheck = config.getURIs().get(0); final RefContentAssistProvider assistProvider = new RefContentAssistProvider(repo, uriToCheck, getShell()); // source Label sourceLabel = new Label(main, SWT.NONE); if (pushMode) sourceLabel.setText(UIText.RefSpecDialog_SourceBranchPushLabel); else sourceLabel.setText(UIText.RefSpecDialog_SourceBranchFetchLabel); sourceText = new Text(main, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(sourceText); if (spec != null && spec.getSource() != null) sourceText.setText(spec.getSource()); sourceText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (sourceText.isFocusControl()) if (autoSuggestDestination) { String name = sourceText.getText(); if (name.startsWith(Constants.R_HEADS)) name = name.substring(Constants.R_HEADS.length()); else if (name.startsWith(Constants.R_TAGS)) name = name.substring(Constants.R_TAGS.length()); RefSpec sourceChanged = getSpec().setSource(sourceText.getText()); setSpec(sourceChanged.setDestination(Constants.R_REMOTES + config.getName() + '/' + name)); } else setSpec(getSpec().setSource(sourceText.getText())); } }); // content assist for source UIUtils.addRefContentProposalToText(sourceText, repo, new IRefListProvider() { public List<Ref> getRefList() { return assistProvider.getRefsForContentAssist(true, pushMode); } }); // suggest remote tracking branch if (!pushMode) { final Button autoSuggest = new Button(main, SWT.CHECK); GridDataFactory.fillDefaults().span(2, 1).applyTo(autoSuggest); autoSuggest.setText(UIText.RefSpecDialog_AutoSuggestCheckbox); autoSuggest.setSelection(true); autoSuggest.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { autoSuggestDestination = autoSuggest.getSelection(); } }); } // destination Label destinationLabel = new Label(main, SWT.NONE); if (pushMode) destinationLabel.setText(UIText.RefSpecDialog_DestinationPushLabel); else destinationLabel.setText(UIText.RefSpecDialog_DestinationFetchLabel); destinationText = new Text(main, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(destinationText); if (spec != null && spec.getDestination() != null) destinationText.setText(spec.getDestination()); destinationText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (destinationText.isFocusControl()) setSpec(getSpec().setDestination(destinationText.getText())); } }); // content assist for destination UIUtils.addRefContentProposalToText(destinationText, repo, new IRefListProvider() { public List<Ref> getRefList() { return assistProvider.getRefsForContentAssist(false, pushMode); } }); // force update forceButton = new Button(main, SWT.CHECK); forceButton.setText(UIText.RefSpecDialog_ForceUpdateCheckbox); GridDataFactory.fillDefaults().span(2, 1).applyTo(forceButton); if (spec != null) forceButton.setSelection(spec.isForceUpdate()); forceButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (getSpec().isForceUpdate() == forceButton.getSelection()) return; setSpec(getSpec().setForceUpdate(forceButton.getSelection())); } }); // RefSpec as String Label stringLabel = new Label(main, SWT.NONE); stringLabel.setText(UIText.RefSpecDialog_SpecificationLabel); specString = new Text(main, SWT.BORDER); GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(specString); if (spec != null) specString.setText(spec.toString()); specString.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (!specString.isFocusControl() || getSpec().toString().equals(specString.getText())) return; setSpec(new RefSpec(specString.getText())); } }); applyDialogFont(main); return main; }
From source file:org.eclipse.egit.ui.internal.repository.CreateBranchPage.java
License:Open Source License
/** * Constructs this page./*from w ww .j a va 2 s . c o m*/ * <p> * If a base branch is provided, the drop down will be selected accordingly * * @param repo * the repository * @param baseRef * the branch or tag to base the new branch on, may be null */ public CreateBranchPage(Repository repo, Ref baseRef) { super(CreateBranchPage.class.getName()); this.myRepository = repo; this.myBaseRef = baseRef.getName(); this.myBaseCommit = null; this.myValidator = ValidationUtils.getRefNameInputValidator(myRepository, Constants.R_HEADS, true); setTitle(UIText.CreateBranchPage_Title); setMessage(UIText.CreateBranchPage_ChooseBranchAndNameMessage); }
From source file:org.eclipse.egit.ui.internal.repository.CreateBranchPage.java
License:Open Source License
/** * Constructs this page./* ww w .j a v a 2s .c o m*/ * <p> * If a base branch is provided, the drop down will be selected accordingly * * @param repo * the repository * @param baseCommit * the commit to base the new branch on, must not be null */ public CreateBranchPage(Repository repo, RevCommit baseCommit) { super(CreateBranchPage.class.getName()); this.myRepository = repo; this.myBaseRef = null; this.myBaseCommit = baseCommit; this.myValidator = ValidationUtils.getRefNameInputValidator(myRepository, Constants.R_HEADS, true); setTitle(UIText.CreateBranchPage_Title); setMessage(UIText.CreateBranchPage_ChooseNameMessage); }
From source file:org.eclipse.egit.ui.internal.repository.CreateBranchPage.java
License:Open Source License
public void createControl(Composite parent) { Composite main = new Composite(parent, SWT.NONE); main.setLayout(new GridLayout(3, false)); Label sourceLabel = new Label(main, SWT.NONE); if (this.myBaseCommit != null) { sourceLabel.setText(UIText.CreateBranchPage_SourceCommitLabel); sourceLabel.setToolTipText(UIText.CreateBranchPage_SourceCommitTooltip); } else {/*from w w w. j a v a2 s.c om*/ sourceLabel.setText(UIText.CreateBranchPage_SourceBranchLabel); sourceLabel.setToolTipText(UIText.CreateBranchPage_SourceBranchTooltip); } this.branchCombo = new Combo(main, SWT.READ_ONLY | SWT.DROP_DOWN); GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(this.branchCombo); if (this.myBaseCommit != null) { this.branchCombo.add(myBaseCommit.name()); this.branchCombo.setText(myBaseCommit.name()); this.branchCombo.setEnabled(false); } else { try { for (Entry<String, Ref> ref : myRepository.getRefDatabase().getRefs(Constants.R_HEADS).entrySet()) { if (!ref.getValue().isSymbolic()) this.branchCombo.add(ref.getValue().getName()); } for (Entry<String, Ref> ref : myRepository.getRefDatabase().getRefs(Constants.R_REMOTES) .entrySet()) { if (!ref.getValue().isSymbolic()) this.branchCombo.add(ref.getValue().getName()); } for (Entry<String, Ref> ref : myRepository.getRefDatabase().getRefs(Constants.R_TAGS).entrySet()) { if (!ref.getValue().isSymbolic()) this.branchCombo.add(ref.getValue().getName()); } } catch (IOException e1) { // ignore here } this.branchCombo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); // select the current branch in the drop down if (myBaseRef != null) { this.branchCombo.setText(myBaseRef); } } Label nameLabel = new Label(main, SWT.NONE); nameLabel.setText(UIText.CreateBranchPage_BranchNameLabel); // we visualize the prefix here Text prefix = new Text(main, SWT.NONE); prefix.setText(Constants.R_HEADS); prefix.setEnabled(false); nameText = new Text(main, SWT.BORDER); // enable testing with SWTBot nameText.setData("org.eclipse.swtbot.widget.key", "BranchName"); //$NON-NLS-1$ //$NON-NLS-2$ GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText); boolean isBare = myRepository.isBare(); checkout = new Button(main, SWT.CHECK); checkout.setText(UIText.CreateBranchPage_CheckoutButton); // most of the time, we probably will check this out // unless we have a bare repository which doesn't allow // check out at all checkout.setSelection(!isBare); checkout.setEnabled(!isBare); checkout.setVisible(!isBare); GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(checkout); checkout.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { checkPage(); } }); Dialog.applyDialogFont(main); setControl(main); nameText.setFocus(); if (myBaseRef != null && (myBaseRef.startsWith(Constants.R_REMOTES) || myBaseRef.startsWith(Constants.R_TAGS))) { // additional convenience: the last part of the name is suggested // as name for the local branch nameText.setText(myBaseRef.substring(myBaseRef.lastIndexOf('/') + 1)); checkPage(); } else { // in any case, we will have to enter the name setPageComplete(false); } // add the listener just now to avoid unneeded checkPage() nameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { checkPage(); } }); }
From source file:org.eclipse.egit.ui.internal.repository.CreateBranchPage.java
License:Open Source License
/** * @param monitor//from w ww.ja v a 2 s . c o m * @throws CoreException * @throws IOException */ public void createBranch(IProgressMonitor monitor) throws CoreException, IOException { monitor.beginTask(UIText.CreateBranchPage_CreatingBranchMessage, IProgressMonitor.UNKNOWN); String newRefName = getBranchName(); final CreateLocalBranchOperation cbop; if (myBaseCommit != null) cbop = new CreateLocalBranchOperation(myRepository, newRefName, myBaseCommit); else cbop = new CreateLocalBranchOperation(myRepository, newRefName, myRepository.getRef(this.branchCombo.getText())); cbop.execute(monitor); if (checkout.getSelection()) { if (monitor.isCanceled()) return; monitor.beginTask(UIText.CreateBranchPage_CheckingOutMessage, IProgressMonitor.UNKNOWN); new BranchOperation(myRepository, Constants.R_HEADS + newRefName).execute(monitor); } }
From source file:org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider.java
License:Open Source License
public Object[] getChildren(Object parentElement) { RepositoryTreeNode node = (RepositoryTreeNode) parentElement; Repository repo = node.getRepository(); switch (node.getType()) { case BRANCHES: { List<RepositoryTreeNode> nodes = new ArrayList<RepositoryTreeNode>(); nodes.add(new LocalNode(node, repo)); nodes.add(new RemoteTrackingNode(node, repo)); return nodes.toArray(); }/*from w w w . j a v a 2s . co m*/ case LOCAL: { if (branchHierarchyMode) { BranchHierarchyNode hierNode = new BranchHierarchyNode(node, repo, new Path(Constants.R_HEADS)); List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>(); try { for (IPath path : hierNode.getChildPaths()) { children.add(new BranchHierarchyNode(node, node.getRepository(), path)); } for (Ref ref : hierNode.getChildRefs()) { children.add(new RefNode(node, node.getRepository(), ref)); } } catch (IOException e) { return handleException(e, node); } return children.toArray(); } else { List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>(); try { for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(Constants.R_HEADS) .entrySet()) { if (!refEntry.getValue().isSymbolic()) refs.add(new RefNode(node, repo, refEntry.getValue())); } } catch (IOException e) { return handleException(e, node); } return refs.toArray(); } } case REMOTETRACKING: { if (branchHierarchyMode) { BranchHierarchyNode hierNode = new BranchHierarchyNode(node, repo, new Path(Constants.R_REMOTES)); List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>(); try { for (IPath path : hierNode.getChildPaths()) { children.add(new BranchHierarchyNode(node, node.getRepository(), path)); } for (Ref ref : hierNode.getChildRefs()) { children.add(new RefNode(node, node.getRepository(), ref)); } } catch (IOException e) { return handleException(e, node); } return children.toArray(); } else { List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>(); try { for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(Constants.R_REMOTES) .entrySet()) { if (!refEntry.getValue().isSymbolic()) refs.add(new RefNode(node, repo, refEntry.getValue())); } } catch (IOException e) { return handleException(e, node); } return refs.toArray(); } } case BRANCHHIERARCHY: { BranchHierarchyNode hierNode = (BranchHierarchyNode) node; List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>(); try { for (IPath path : hierNode.getChildPaths()) { children.add(new BranchHierarchyNode(node, node.getRepository(), path)); } for (Ref ref : hierNode.getChildRefs()) { children.add(new RefNode(node, node.getRepository(), ref)); } } catch (IOException e) { return handleException(e, node); } return children.toArray(); } case TAGS: { List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>(); try { for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(Constants.R_TAGS).entrySet()) { refs.add(new TagNode(node, repo, refEntry.getValue())); } } catch (IOException e) { return handleException(e, node); } return refs.toArray(); } case ADDITIONALREFS: { List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>(); try { for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(RefDatabase.ALL).entrySet()) { String name = refEntry.getKey(); if (!(name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_TAGS) || name.startsWith(Constants.R_REMOTES))) refs.add(new AdditionalRefNode(node, repo, refEntry.getValue())); } for (Ref r : repo.getRefDatabase().getAdditionalRefs()) refs.add(new AdditionalRefNode(node, repo, r)); } catch (IOException e) { return handleException(e, node); } return refs.toArray(); } case REMOTES: { List<RepositoryTreeNode<String>> remotes = new ArrayList<RepositoryTreeNode<String>>(); Repository rep = node.getRepository(); Set<String> configNames = rep.getConfig().getSubsections(RepositoriesView.REMOTE); for (String configName : configNames) { remotes.add(new RemoteNode(node, repo, configName)); } return remotes.toArray(); } case REPO: { List<RepositoryTreeNode<? extends Object>> nodeList = new ArrayList<RepositoryTreeNode<? extends Object>>(); nodeList.add(new BranchesNode(node, repo)); nodeList.add(new TagsNode(node, repo)); nodeList.add(new AdditionalRefsNode(node, repo)); nodeList.add(new WorkingDirNode(node, repo)); nodeList.add(new RemotesNode(node, repo)); return nodeList.toArray(); } case WORKINGDIR: { List<RepositoryTreeNode<File>> children = new ArrayList<RepositoryTreeNode<File>>(); if (node.getRepository().isBare()) return children.toArray(); File workingDir = repo.getWorkTree(); if (workingDir == null || !workingDir.exists()) return children.toArray(); File[] childFiles = workingDir.listFiles(); Arrays.sort(childFiles, new Comparator<File>() { public int compare(File o1, File o2) { if (o1.isDirectory()) { if (o2.isDirectory()) { return o1.compareTo(o2); } return -1; } else if (o2.isDirectory()) { return 1; } return o1.compareTo(o2); } }); for (File file : childFiles) { if (file.isDirectory()) { children.add(new FolderNode(node, repo, file)); } else { children.add(new FileNode(node, repo, file)); } } return children.toArray(); } case FOLDER: { List<RepositoryTreeNode<File>> children = new ArrayList<RepositoryTreeNode<File>>(); File parent = ((File) node.getObject()); File[] childFiles = parent.listFiles(); Arrays.sort(childFiles, new Comparator<File>() { public int compare(File o1, File o2) { if (o1.isDirectory()) { if (o2.isDirectory()) { return o1.compareTo(o2); } return -1; } else if (o2.isDirectory()) { return 1; } return o1.compareTo(o2); } }); for (File file : childFiles) { if (file.isDirectory()) { children.add(new FolderNode(node, repo, file)); } else { children.add(new FileNode(node, repo, file)); } } return children.toArray(); } case REMOTE: { List<RepositoryTreeNode<String>> children = new ArrayList<RepositoryTreeNode<String>>(); String remoteName = (String) node.getObject(); RemoteConfig rc; try { rc = new RemoteConfig(node.getRepository().getConfig(), remoteName); } catch (URISyntaxException e) { return handleException(e, node); } if (!rc.getURIs().isEmpty()) children.add(new FetchNode(node, node.getRepository(), rc.getURIs().get(0).toPrivateString())); int uriCount = rc.getPushURIs().size(); if (uriCount == 0 && !rc.getURIs().isEmpty()) uriCount++; // show push if either a fetch or push URI is specified and // at least one push specification if (uriCount > 0 && !rc.getPushRefSpecs().isEmpty()) { URIish firstUri; if (!rc.getPushURIs().isEmpty()) firstUri = rc.getPushURIs().get(0); else firstUri = rc.getURIs().get(0); if (uriCount == 1) children.add(new PushNode(node, node.getRepository(), firstUri.toPrivateString())); else children.add(new PushNode(node, node.getRepository(), firstUri.toPrivateString() + "...")); //$NON-NLS-1$ } return children.toArray(); } case FILE: // fall through case REF: // fall through case PUSH: // fall through case TAG: // fall through case FETCH: // fall through case ERROR: // fall through case ADDITIONALREF: return null; } return null; }
From source file:org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider.java
License:Open Source License
private Image decorateImage(final Image image, Object element) { RepositoryTreeNode node = (RepositoryTreeNode) element; switch (node.getType()) { case TAG:/* w w w . j av a 2 s. c o m*/ // fall through case ADDITIONALREF: // fall through case REF: // if the branch or tag is checked out, // we want to decorate the corresponding // node with a little check indicator String refName = ((Ref) node.getObject()).getName(); Ref leaf = ((Ref) node.getObject()).getLeaf(); String branchName; String compareString; try { branchName = node.getRepository().getFullBranch(); if (branchName == null) return image; if (refName.startsWith(Constants.R_HEADS)) { // local branch: HEAD would be on the branch compareString = refName; } else if (refName.startsWith(Constants.R_TAGS)) { // tag: HEAD would be on the commit id to which the tag is // pointing ObjectId id = node.getRepository().resolve(refName); if (id == null) return image; RevWalk rw = new RevWalk(node.getRepository()); RevTag tag = rw.parseTag(id); compareString = tag.getObject().name(); } else if (refName.startsWith(Constants.R_REMOTES)) { // remote branch: HEAD would be on the commit id to which // the branch is pointing ObjectId id = node.getRepository().resolve(refName); if (id == null) return image; RevWalk rw = new RevWalk(node.getRepository()); RevCommit commit = rw.parseCommit(id); compareString = commit.getId().name(); } else if (refName.equals(Constants.HEAD)) return getDecoratedImage(image); else { String leafname = leaf.getName(); if (leafname.startsWith(Constants.R_REFS) && leafname.equals(node.getRepository().getFullBranch())) return getDecoratedImage(image); else if (leaf.getObjectId().equals(node.getRepository().resolve(Constants.HEAD))) return getDecoratedImage(image); // some other symbolic reference return image; } } catch (IOException e1) { return image; } if (compareString.equals(branchName)) { return getDecoratedImage(image); } return image; default: return image; } }
From source file:org.eclipse.egit.ui.internal.repository.SelectResetTypePage.java
License:Open Source License
private Image getIcon(final String ref) { if (ref.startsWith(Constants.R_TAGS)) return UIIcons.TAG.createImage(); else if (ref.startsWith(Constants.R_HEADS) || ref.startsWith(Constants.R_REMOTES)) return UIIcons.BRANCH.createImage(); else/*w ww . jav a 2s . c o m*/ return UIIcons.CHANGESET.createImage(); }
From source file:org.eclipse.egit.ui.internal.repository.tree.command.CreateBranchCommand.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { final RepositoryTreeNode node = getSelectedNodes(event).get(0); if (node.getType() == RepositoryTreeNodeType.ADDITIONALREF) { Ref ref = (Ref) node.getObject(); try {/*from w w w .ja v a2 s .c o m*/ RevCommit baseCommit = new RevWalk(node.getRepository()).parseCommit(ref.getLeaf().getObjectId()); WizardDialog dlg = new WizardDialog(getShell(event), new CreateBranchWizard(node.getRepository(), baseCommit)); dlg.setHelpAvailable(false); dlg.open(); } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); } return null; } final Ref baseBranch; if (node.getObject() instanceof Ref) baseBranch = (Ref) node.getObject(); else { // we are on another node, so we have no Ref as context // -> try to determine the currently checked out branch Ref branch; try { if (node.getRepository().getFullBranch().startsWith(Constants.R_HEADS)) { // simple case: local branch checked out branch = node.getRepository().getRef(node.getRepository().getFullBranch()); } else { // remote branch or tag checked out: resolve the commit String ref = Activator.getDefault().getRepositoryUtil().mapCommitToRef(node.getRepository(), node.getRepository().getFullBranch(), false); if (ref == null) branch = null; else { if (ref.startsWith(Constants.R_TAGS)) // if a tag is checked out, we don't suggest // anything branch = null; else branch = node.getRepository().getRef(ref); } } } catch (IOException e) { branch = null; } baseBranch = branch; } new WizardDialog(getShell(event), new CreateBranchWizard(node.getRepository(), baseBranch)).open(); return null; }
From source file:org.eclipse.egit.ui.internal.repository.tree.command.RenameBranchCommand.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { final List<RefNode> nodes = getSelectedNodes(event); RefNode refNode = nodes.get(0);//from w w w. j a va2 s. com Shell shell = getShell(event); String oldName = refNode.getObject().getName(); String prefix; if (oldName.startsWith(Constants.R_HEADS)) prefix = Constants.R_HEADS; else if (oldName.startsWith(Constants.R_REMOTES)) prefix = Constants.R_REMOTES; else throw new ExecutionException(NLS.bind(UIText.RenameBranchCommand_WrongNameMessage, oldName)); Repository db = refNode.getRepository(); IInputValidator inputValidator = ValidationUtils.getRefNameInputValidator(db, prefix, true); String defaultValue = Repository.shortenRefName(oldName); InputDialog newNameDialog = new InputDialog(shell, UIText.RepositoriesView_RenameBranchTitle, NLS.bind(UIText.RepositoriesView_RenameBranchMessage, defaultValue), defaultValue, inputValidator); if (newNameDialog.open() == Window.OK) { try { String newName = newNameDialog.getValue(); new RenameBranchOperation(db, refNode.getObject(), newName).execute(null); } catch (CoreException e) { Activator.handleError(UIText.RepositoriesView_RenameBranchFailure, e, true); } } return null; }