Example usage for org.eclipse.jgit.lib Constants HEAD

List of usage examples for org.eclipse.jgit.lib Constants HEAD

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants HEAD.

Prototype

String HEAD

To view the source code for org.eclipse.jgit.lib Constants HEAD.

Click Source Link

Document

Special name for the "HEAD" symbolic-ref.

Usage

From source file:org.eclipse.egit.ui.internal.actions.ReplaceWithHeadActionHandler.java

License:Open Source License

@Override
protected String gatherRevision(ExecutionEvent event) {
    return Constants.HEAD;
}

From source file:org.eclipse.egit.ui.internal.actions.RepositoryActionHandler.java

License:Open Source License

/**
 * Checks if merge is possible://from  w w w .j a  v a2 s. c o m
 * <ul>
 * <li>HEAD must point to a branch</li>
 * <li>Repository State must be SAFE</li>
 * </ul>
 *
 * @param repository
 * @param event
 * @return a boolean indicating if merge is possible
 * @throws ExecutionException
 */
protected boolean canMerge(final Repository repository, ExecutionEvent event) throws ExecutionException {
    String message = null;
    try {
        Ref head = repository.getRef(Constants.HEAD);
        if (head == null || !head.isSymbolic())
            message = UIText.MergeAction_HeadIsNoBranch;
        else if (!repository.getRepositoryState().equals(RepositoryState.SAFE))
            message = NLS.bind(UIText.MergeAction_WrongRepositoryState, repository.getRepositoryState());
    } catch (IOException e) {
        Activator.logError(e.getMessage(), e);
        message = e.getMessage();
    }

    if (message != null) {
        MessageDialog.openError(getShell(event), UIText.MergeAction_CannotMerge, message);
    }
    return (message == null);
}

From source file:org.eclipse.egit.ui.internal.actions.ResetQuickdiffBaselineAction.java

License:Open Source License

@Override
protected IEGitOperation createOperation(List<RevCommit> selection) {
    return new QuickdiffBaselineOperation(getActiveRepository(), Constants.HEAD);
}

From source file:org.eclipse.egit.ui.internal.actions.SwitchToMenu.java

License:Open Source License

private void createDynamicMenu(Menu menu, final Repository repository) {
    MenuItem newBranch = new MenuItem(menu, SWT.PUSH);
    newBranch.setText(UIText.SwitchToMenu_NewBranchMenuLabel);
    newBranch.setImage(newBranchImage);//from   www  .  j a  va  2s . c  o  m
    newBranch.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            BranchOperationUI.create(repository).start();
        }
    });
    new MenuItem(menu, SWT.SEPARATOR);
    try {
        String currentBranch = repository.getFullBranch();
        Map<String, Ref> localBranches = repository.getRefDatabase().getRefs(Constants.R_HEADS);
        TreeMap<String, Ref> sortedRefs = new TreeMap<String, Ref>();

        // Add the MAX_NUM_MENU_ENTRIES most recently used branches first
        List<ReflogEntry> reflogEntries = new ReflogReader(repository, Constants.HEAD).getReverseEntries();
        for (ReflogEntry entry : reflogEntries) {
            CheckoutEntry checkout = entry.parseCheckout();
            if (checkout != null) {
                Ref ref = localBranches.get(checkout.getFromBranch());
                if (ref != null)
                    if (sortedRefs.size() < MAX_NUM_MENU_ENTRIES)
                        sortedRefs.put(checkout.getFromBranch(), ref);
                ref = localBranches.get(checkout.getToBranch());
                if (ref != null)
                    if (sortedRefs.size() < MAX_NUM_MENU_ENTRIES)
                        sortedRefs.put(checkout.getToBranch(), ref);
            }
        }

        // Add the recently used branches to the menu, in alphabetical order
        int itemCount = 0;
        for (final Entry<String, Ref> entry : sortedRefs.entrySet()) {
            itemCount++;
            final String shortName = entry.getKey();
            final String fullName = entry.getValue().getName();
            createMenuItem(menu, repository, currentBranch, fullName, shortName);
            // Do not duplicate branch names
            localBranches.remove(shortName);
        }

        if (itemCount < MAX_NUM_MENU_ENTRIES) {
            // A separator between recently used branches and local branches is
            // nice but only if we have both recently used branches and other
            // local branches
            if (itemCount > 0 && localBranches.size() > 0)
                new MenuItem(menu, SWT.SEPARATOR);

            // Now add more other branches if we have only a few branch switches
            // Sort the remaining local branches
            sortedRefs.clear();
            sortedRefs.putAll(localBranches);
            for (final Entry<String, Ref> entry : sortedRefs.entrySet()) {
                itemCount++;
                // protect ourselves against a huge sub-menu
                if (itemCount > MAX_NUM_MENU_ENTRIES)
                    break;
                final String fullName = entry.getValue().getName();
                final String shortName = entry.getKey();
                createMenuItem(menu, repository, currentBranch, fullName, shortName);
            }
        }
        if (itemCount > 0)
            new MenuItem(menu, SWT.SEPARATOR);
        MenuItem others = new MenuItem(menu, SWT.PUSH);
        others.setText(UIText.SwitchToMenu_OtherMenuLabel);
        others.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                BranchOperationUI.checkout(repository).start();
            }
        });
    } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, true);
    }
}

From source file:org.eclipse.egit.ui.internal.actions.SwitchToMenuTest.java

License:Open Source License

@Test
public void selectionWithProj1AndReflog() throws Exception {
    File gitDir = createProjectAndCommitToRepository();

    // create additional reflog entries
    Git git = new Git(lookupRepository(gitDir));
    git.checkout().setName("stable").call();
    git.checkout().setName("master").call();

    selectionWithProj1Common();//from  w w w. j  av a2s .  c o  m

    // delete reflog again to not confuse other tests
    new File(gitDir, Constants.LOGS + "/" + Constants.HEAD).delete();
}

From source file:org.eclipse.egit.ui.internal.actions.SynchronizeWithMenu.java

License:Open Source License

@Override
public void fill(final Menu menu, int index) {
    if (srv == null)
        return;/*  w ww  .ja  v a 2 s  . c om*/
    final IResource selectedResource = getSelection();
    if (selectedResource == null || selectedResource.isLinked(IResource.CHECK_ANCESTORS))
        return;

    RepositoryMapping mapping = RepositoryMapping.getMapping(selectedResource.getProject());
    if (mapping == null)
        return;

    final Repository repo = mapping.getRepository();
    if (repo == null)
        return;

    List<Ref> refs = new LinkedList<Ref>();
    RefDatabase refDatabase = repo.getRefDatabase();
    try {
        refs.addAll(refDatabase.getAdditionalRefs());
    } catch (IOException e) {
        // do nothing
    }
    try {
        refs.addAll(refDatabase.getRefs(RefDatabase.ALL).values());
    } catch (IOException e) {
        // do nothing
    }
    Collections.sort(refs, CommonUtils.REF_ASCENDING_COMPARATOR);
    String currentBranch;
    try {
        currentBranch = repo.getFullBranch();
    } catch (IOException e) {
        currentBranch = ""; //$NON-NLS-1$
    }

    int count = 0;
    String oldName = null;
    int refsLength = R_REFS.length();
    int tagsLength = R_TAGS.substring(refsLength).length();
    for (Ref ref : refs) {
        final String name = ref.getName();
        if (name.equals(Constants.HEAD) || name.equals(currentBranch) || excludeTag(ref, repo))
            continue;
        if (name.startsWith(R_REFS) && oldName != null
                && !oldName.regionMatches(refsLength, name, refsLength, tagsLength))
            new MenuItem(menu, SWT.SEPARATOR);

        MenuItem item = new MenuItem(menu, SWT.PUSH);
        item.setText(name);
        if (name.startsWith(Constants.R_TAGS))
            item.setImage(tagImage);
        else if (name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_REMOTES))
            item.setImage(branchImage);

        item.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent event) {
                GitSynchronizeData data;
                try {
                    data = new GitSynchronizeData(repo, HEAD, name, true);
                    if (!(selectedResource instanceof IProject)) {
                        HashSet<IContainer> containers = new HashSet<IContainer>();
                        containers.add((IContainer) selectedResource);
                        data.setIncludedPaths(containers);
                    }

                    GitModelSynchronize.launch(data, new IResource[] { selectedResource });
                } catch (IOException e) {
                    Activator.logError(e.getMessage(), e);
                }
            }
        });

        if (++count == MAX_NUM_MENU_ENTRIES)
            break;
        oldName = name;
    }

    if (count > 1)
        new MenuItem(menu, SWT.SEPARATOR);

    MenuItem custom = new MenuItem(menu, SWT.PUSH);
    custom.setText(UIText.SynchronizeWithMenu_custom);
    custom.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            GitSynchronizeWizard gitWizard = new GitSynchronizeWizard();
            WizardDialog wizard = new WizardDialog(menu.getShell(), gitWizard);
            wizard.create();
            wizard.open();
        }
    });
}

From source file:org.eclipse.egit.ui.internal.actions.TagAction.java

License:Open Source License

private RevWalk getRevCommits() {
    RevWalk revWalk = new RevWalk(repo);
    revWalk.sort(RevSort.COMMIT_TIME_DESC, true);
    revWalk.sort(RevSort.BOUNDARY, true);

    try {/* w  w  w .j  a v  a2 s  .c o  m*/
        AnyObjectId headId = repo.resolve(Constants.HEAD);
        if (headId != null)
            revWalk.markStart(revWalk.parseCommit(headId));
    } catch (IOException e) {
        ErrorDialog.openError(getShell(), UIText.TagAction_errorDuringTagging,
                UIText.TagAction_errorWhileGettingRevCommits,
                new Status(IStatus.ERROR, Activator.getPluginId(), e.getMessage(), e));
    }

    return revWalk;
}

From source file:org.eclipse.egit.ui.internal.actions.TagAction.java

License:Open Source License

private ObjectId getTagCommit(ObjectId objectId) throws InvocationTargetException {
    ObjectId result = null;/*from   w  w  w.  j av  a  2  s  .  com*/
    if (objectId == null) {
        try {
            result = repo.resolve(Constants.HEAD);
        } catch (IOException e) {
            throw new InvocationTargetException(e, UIText.TagAction_unableToResolveHeadObjectId);
        }
    } else {
        result = objectId;
    }
    return result;
}

From source file:org.eclipse.egit.ui.internal.actions.TagActionHandler.java

License:Open Source License

private RevObject getTagTarget(ObjectId objectId) throws IOException {
    RevWalk rw = new RevWalk(repo);
    try {//from   ww  w  .  j  a v  a 2  s  .co m
        if (objectId == null) {
            return rw.parseAny(repo.resolve(Constants.HEAD));

        } else {
            return rw.parseAny(objectId);
        }
    } finally {
        rw.release();
    }
}

From source file:org.eclipse.egit.ui.internal.branch.BranchResultDialog.java

License:Open Source License

@Override
protected void buttonPressed(int buttonId) {
    boolean shouldCheckout = false;
    switch (buttonId) {
    case IDialogConstants.PROCEED_ID:
        CommitUI commitUI = new CommitUI(getShell(), repository, new IResource[0], true);
        shouldCheckout = commitUI.commit();
        break;/*from w  ww  .  j a v a 2  s .  com*/
    case IDialogConstants.ABORT_ID:
        final ResetOperation operation = new ResetOperation(repository, Constants.HEAD, ResetType.HARD);
        String jobname = NLS.bind(UIText.ResetAction_reset, Constants.HEAD);
        JobUtil.scheduleUserJob(operation, jobname, JobFamilies.RESET);
        shouldCheckout = true;
        break;
    case IDialogConstants.SKIP_ID:
        StashCreateUI stashCreateUI = new StashCreateUI(getShell(), repository);
        shouldCheckout = stashCreateUI.createStash();
        break;
    case IDialogConstants.CANCEL_ID:
        super.buttonPressed(buttonId);
        return;
    }
    if (shouldCheckout) {
        super.buttonPressed(buttonId);
        BranchOperationUI op = BranchOperationUI.checkout(repository, target);
        op.start();
    }
}