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.core.synchronize.GitResourceVariantTreeSubscriberTest.java
License:Open Source License
/** * Both source and destination branches has some different commits but they * has also common ancestor. This situation is described more detailed in * bug #317934/*from w w w. j a v a2 s. c om*/ * * This test passes when it is run as a stand alone test case, but it fails * when it is run as part of test suite. It throws NPE when it try's to * checkout master branch. * * @throws Exception */ @Test @Ignore public void shouldReturnCommonAncestorAsBase() throws Exception { // when String fileName = "Main.java"; File file = testRepo.createFile(iProject, fileName); RevCommit commit = testRepo.appendContentAndCommit(iProject, file, "class Main {}", "initial commit"); IFile mainJava = testRepo.getIFile(iProject, file); // this should be our common ancestor ObjectId fileId = findFileId(commit, mainJava); testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS + "test"); testRepo.appendContentAndCommit(iProject, file, "// test 1", "second commit"); testRepo.checkoutBranch(Constants.R_HEADS + Constants.MASTER); testRepo.appendContentAndCommit(iProject, file, "// test 2", "third commit"); // given GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(Constants.HEAD, Constants.R_HEADS + "test"); grvts.getBaseTree(); IResourceVariantTree baseTree = grvts.getBaseTree(); // then IResourceVariant actual = commonAssertionsForBaseTree(baseTree, mainJava); assertEquals(fileId.getName(), actual.getContentIdentifier()); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriberTest.java
License:Open Source License
/** * This test passes when it is run as a stand alone test case, but it fails * when it is run as part of test suite. It throws NPE when it try's to * checkout master branch./*from w ww. j a v a2s.c o m*/ * * @throws Exception */ @Test @Ignore public void shouldReturnRemoteTree() throws Exception { // when String fileName = "Main.java"; File file = testRepo.createFile(iProject, fileName); testRepo.appendContentAndCommit(iProject, file, "class Main {}", "initial commit"); IFile mainJava = testRepo.getIFile(iProject, file); testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS + "test"); RevCommit commit = testRepo.appendContentAndCommit(iProject, file, "// test 1", "second commit"); ObjectId fileId = findFileId(commit, mainJava); // given GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(Constants.HEAD, "test"); grvts.getBaseTree(); IResourceVariantTree remoteTree = grvts.getRemoteTree(); // then assertNotNull(remoteTree); assertTrue(remoteTree instanceof GitRemoteResourceVariantTree); IResourceVariant resourceVariant = remoteTree.getResourceVariant(mainJava); assertNotNull(resourceVariant); assertTrue(resourceVariant instanceof GitResourceVariant); assertEquals(fileId.getName(), resourceVariant.getContentIdentifier()); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriberTest2.java
License:Open Source License
/** * Both source and destination branches has some different commits but they * has also common ancestor. This situation is described more detailed in * bug #317934/*w ww . j a v a2 s .c o m*/ * * This test passes when it is run as a stand alone test case, but it fails * when it is run as part of test suite. It throws NPE when it try's to * checkout master branch. * * @throws Exception */ @Test public void shouldReturnCommonAncestorAsBase() throws Exception { // when String fileName = "Main.java"; File file = testRepo.createFile(iProject, fileName); RevCommit commit = testRepo.appendContentAndCommit(iProject, file, "class Main {}", "initial commit"); IFile mainJava = testRepo.getIFile(iProject, file); // this should be our common ancestor testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS + "test"); testRepo.appendContentAndCommit(iProject, file, "// test 1", "second commit"); testRepo.checkoutBranch(Constants.R_HEADS + Constants.MASTER); testRepo.appendContentAndCommit(iProject, file, "// test 2", "third commit"); // given GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(Constants.HEAD, Constants.R_HEADS + "test"); grvts.getBaseTree(); IResourceVariantTree baseTree = grvts.getBaseTree(); // then IResourceVariant actual = commonAssertionsForBaseTree(baseTree, mainJava); assertEquals(commit.abbreviate(7).name() + "...", actual.getContentIdentifier()); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantTreeTest.java
License:Open Source License
/** * Create and commit Main.java file in master branch, then create branch * "test" checkout nearly created branch and modify Main.java file. * getResourceVariant() should obtain Main.java file content from "master" * branch. Passes only when it is run as a single test, not as a part of * largest test suite/*from w w w .j av a2s . co m*/ * * @throws Exception */ @Test public void shouldReturnDifferentResourceVariant() throws Exception { // when String fileName = "Main.java"; File file = testRepo.createFile(iProject, fileName); testRepo.appendContentAndCommit(iProject, file, "class Main {}", "initial commit"); IFile mainJava = testRepo.getIFile(iProject, file); testRepo.createAndCheckoutBranch(Constants.R_HEADS + Constants.MASTER, Constants.R_HEADS + "test"); testRepo.appendContentAndCommit(iProject, file, "// test", "first commit"); GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, false); GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); // given GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet); // then IResourceVariant actual = grvt.getResourceVariant(mainJava); assertNotNull(actual); assertEquals(fileName, actual.getName()); InputStream actualIn = actual.getStorage(new NullProgressMonitor()).getContents(); byte[] actualByte = getBytesAndCloseStream(actualIn); InputStream expectedIn = mainJava.getContents(); byte[] expectedByte = getBytesAndCloseStream(expectedIn); // assert arrays not equals if (Arrays.equals(expectedByte, actualByte)) fail(); else assertTrue(true); }
From source file:org.eclipse.egit.gitflow.BranchNameValidator.java
License:Open Source License
/** * @param name//ww w . ja va 2 s .c o m * @return Whether or not name would be a valid name for a branch. */ public static boolean isBranchNameValid(String name) { return Repository.isValidRefName(Constants.R_HEADS + name); }
From source file:org.eclipse.egit.gitflow.ui.internal.actions.FeatureCheckoutHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event); if (gfRepo == null) { return error(UIText.Handlers_noGitflowRepositoryFound); }//from w ww. j a v a 2s. c o m Repository repository = gfRepo.getRepository(); final List<Ref> refs = gfRepo.getFeatureBranches(); FeatureBranchSelectionDialog dialog = new FeatureBranchSelectionDialog(HandlerUtil.getActiveShell(event), refs, UIText.FeatureCheckoutHandler_selectFeature, UIText.FeatureCheckoutHandler_localFeatures, Constants.R_HEADS + gfRepo.getConfig().getFeaturePrefix(), gfRepo); if (dialog.open() != Window.OK) { return null; } final Ref ref = dialog.getSelectedNode(); try { String featureName = gfRepo.getFeatureBranchName(ref); // TODO: consider using BranchOperationUI because checkout can take // a long time on large repositories FeatureCheckoutOperation checkoutOperation = new FeatureCheckoutOperation(gfRepo, featureName); JobUtil.scheduleUserWorkspaceJob(checkoutOperation, UIText.FeatureCheckoutHandler_checkingOutFeature, JobFamilies.GITFLOW_FAMILY); IJobManager jobMan = Job.getJobManager(); try { jobMan.join(GITFLOW_FAMILY, null); } catch (OperationCanceledException | InterruptedException e) { return error(e.getMessage(), e); } CheckoutResult result = checkoutOperation.getResult(); if (!CheckoutResult.Status.OK.equals(result.getStatus())) { Shell shell = HandlerUtil.getActiveShell(event); if (!handleUncommittedFiles(gfRepo.getRepository(), shell, repository.getWorkTree().getName())) { return Status.CANCEL_STATUS; } else { JobUtil.scheduleUserWorkspaceJob(checkoutOperation, UIText.FeatureCheckoutHandler_checkingOutFeature, JobFamilies.GITFLOW_FAMILY); } } } catch (GitAPIException e) { throw new RuntimeException(e); } return null; }
From source file:org.eclipse.egit.gitflow.ui.internal.dialogs.FilteredBranchesWidget.java
License:Open Source License
Control create(Composite parent) { Composite area = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(area); area.setLayout(new GridLayout(1, false)); PatternFilter filter = new PatternFilter() { @Override/*from www . j a v a2 s. c o m*/ protected boolean isLeafMatch(Viewer viewer, Object element) { TreeViewer treeViewer = (TreeViewer) viewer; int numberOfColumns = treeViewer.getTree().getColumnCount(); boolean isMatch = false; for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) { ColumnLabelProvider labelProvider = (ColumnLabelProvider) treeViewer .getLabelProvider(columnIndex); String labelText = labelProvider.getText(element); isMatch |= wordMatches(labelText); } return isMatch; } }; filter.setIncludeLeadingWildcard(true); final FilteredTree tree = new FilteredTree(area, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true); tree.setQuickSelectionMode(true); branchesViewer = tree.getViewer(); branchesViewer.getTree().setLinesVisible(false); branchesViewer.getTree().setHeaderVisible(true); comparator = new BranchComparator(); branchesViewer.setComparator(comparator); DecoratedBranchLabelProvider nameLabelProvider = new DecoratedBranchLabelProvider(gfRepo.getRepository(), prefix); TreeColumn nameColumn = createColumn(UIText.BranchSelectionTree_NameColumn, branchesViewer, nameLabelProvider); TreeColumn idColumn = createColumn(UIText.BranchSelectionTree_IdColumn, branchesViewer, new ColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof Ref) { ObjectId objectId = ((Ref) element).getObjectId(); if (objectId == null) { return ""; //$NON-NLS-1$ } return objectId.abbreviate(7).name(); } return super.getText(element); } }); ColumnLabelProvider dateLabelProvider = new ColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof Ref) { String name = ((Ref) element).getName().substring(Constants.R_HEADS.length()); RevCommit revCommit = gfRepo.findHead(name); if (revCommit == null) { return ""; //$NON-NLS-1$ } return getDateFormatter().formatDate(revCommit.getCommitterIdent()); } return super.getText(element); } }; TreeColumn dateColumn = createColumn(UIText.FilteredBranchesWidget_lastModified, branchesViewer, dateLabelProvider); setSortedColumn(dateColumn, dateLabelProvider); TreeColumn msgColumn = createColumn(UIText.BranchSelectionTree_MessageColumn, branchesViewer, new ColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof Ref) { String name = ((Ref) element).getName().substring(Constants.R_HEADS.length()); RevCommit revCommit = gfRepo.findHead(name); if (revCommit == null) { return ""; //$NON-NLS-1$ } return revCommit.getShortMessage(); } return super.getText(element); } }); GridDataFactory.fillDefaults().grab(true, true).applyTo(branchesViewer.getControl()); branchesViewer.setContentProvider(new BranchListContentProvider()); branchesViewer.setInput(refs); // Layout tree for maximum width of message column TreeColumnLayout layout = new TreeColumnLayout(); nameColumn.pack(); layout.setColumnData(nameColumn, new ColumnWeightData(0, nameColumn.getWidth())); idColumn.pack(); layout.setColumnData(idColumn, new ColumnWeightData(0, idColumn.getWidth())); dateColumn.pack(); layout.setColumnData(dateColumn, new ColumnWeightData(0, dateColumn.getWidth())); layout.setColumnData(msgColumn, new ColumnWeightData(100)); branchesViewer.getTree().getParent().setLayout(layout); branchesViewer.addFilter(createFilter()); return area; }
From source file:org.eclipse.egit.internal.mylyn.ui.tasks.RepositoryAndBranchSelectionDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); composite.setLayout(new GridLayout(3, false)); Label repositoryLabel = new Label(composite, SWT.NONE); repositoryLabel.setText("Select a repository:"); GridDataFactory.fillDefaults().span(3, 1).grab(true, false).applyTo(repositoryLabel); repositoryTableViewer = new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI); repositoryTableViewer.setContentProvider(new RepositoriesViewContentProvider()); GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(repositoryTableViewer.getTable()); repositoryTableViewer.setLabelProvider(new RepositoriesViewLabelProvider()); repositoryTableViewer.setInput(util.getConfiguredRepositories()); // TODO use a ComboViewer branchCombo = new Combo(composite, SWT.DROP_DOWN); branchCombo.setLayoutData(GridDataFactory.fillDefaults().span(3, 1).grab(true, false).create()); branchCombo.setEnabled(false);/*from w ww . j a va 2s. c om*/ repositoryTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { try { branchCombo.setEnabled(true); branchCombo.removeAll(); branchCombo.setText(initialBranch); repos = getRepositories(); for (Repository repository : repos) { if (repository != null) { for (Entry<String, Ref> refEntry : repository.getRefDatabase() .getRefs(Constants.R_HEADS).entrySet()) { if (!refEntry.getValue().isSymbolic()) branchesForCombo.put(refEntry.getValue().getName(), refEntry.getValue().getName()); } } } for (String b : branchesForCombo.keySet()) { branchCombo.add(b); } } catch (IOException e) { // do nothing atm } } }); // TODO how do we handle multiple repos? // need to figure out things.. branchCombo.setText(initialBranch); branch = initialBranch; branchCombo.addFocusListener(new FocusListener() { public void focusLost(FocusEvent e) { branch = branchCombo.getText(); } public void focusGained(FocusEvent e) { // Nothing to do } }); setTitle("Select Branch"); setMessage("Select a repository and corresponding branch to checkout."); setTitleImage(UIIcons.WIZBAN_CONNECT_REPO.createImage()); applyDialogFont(composite); return composite; }
From source file:org.eclipse.egit.internal.mylyn.ui.tasks.TaskActivationListener.java
License:Open Source License
public void preTaskActivated(ITask task) { // TODO if there's a context, should we browse it to deduce which repo to choose? String branch = task.getTaskKey() != null ? task.getTaskKey() : task.getTaskId(); String branchFullName = Constants.R_HEADS + branch; RepositoryAndBranchSelectionDialog dialog = new RepositoryAndBranchSelectionDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), branchFullName); if (dialog.open() == Window.OK) { try {/*from w w w. ja v a 2 s . c o m*/ List<Repository> repos = dialog.getSelectedRepositories(); for (Repository repo : repos) { // Create new branch, if branch with proposed name doesn't exist, otherwise checkout if (repo.getRefDatabase().getRef(branch) == null) { CreateLocalBranchOperation createOperation = new CreateLocalBranchOperation(repo, branch, repo.getRef(Constants.R_HEADS + Constants.MASTER)); createOperation.execute(null); } BranchOperation operation = new BranchOperation(repo, dialog.getBranch()); operation.execute(null); } } catch (CoreException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.eclipse.egit.internal.mylyn.ui.tasks.TaskActivationListener.java
License:Open Source License
public void taskDeactivated(ITask task) { // FIXME hack, we should detect which repository to switch to master // we should base this off the task context imho... we should be able to guess based on the projects in the context // if we get a conflict... this may be a bit more complicated... but how common would this be? ContextCorePlugin.getContextManager(); Repository repository = Activator.getDefault().getRepositoryCache().getAllRepositories()[0]; try {//from ww w . j a v a2 s.c om BranchOperation operation = new BranchOperation(repository, Constants.R_HEADS + Constants.MASTER); operation.execute(null); } catch (CoreException e) { e.printStackTrace(); } }