Example usage for org.eclipse.jgit.lib Repository getFullBranch

List of usage examples for org.eclipse.jgit.lib Repository getFullBranch

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository getFullBranch.

Prototype

@Nullable
public String getFullBranch() throws IOException 

Source Link

Document

Get the name of the reference that HEAD points to.

Usage

From source file:org.eclipse.egit.ui.test.team.actions.BranchAndResetActionTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);/*from  w  ww .j ava 2s  .c  om*/
    touchAndSubmit(null);

    RepositoriesViewLabelProvider provider = new RepositoriesViewLabelProvider();
    LOCAL_BRANCHES = provider.getText(new LocalNode(new RepositoryNode(null, repo), repo));
    TAGS = provider.getText(new TagsNode(new RepositoryNode(null, repo), repo));
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.CommitActionTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    // TODO delete the second project for the time being (.gitignore is
    // currently not hiding the .project file from commit)
    ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2).delete(false, null);

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);//from  w  w w  . j a v  a2 s  . c o  m
    touchAndSubmit(null);

    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.CompareActionsTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    commitOfTag = tag.getObjectId();/*  ww  w . j a  v  a  2  s.  c om*/
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);
    touchAndSubmit(null);

    RepositoriesViewLabelProvider provider = GitRepositoriesViewTestUtils.createLabelProvider();
    // LOCAL_BRANCHES = provider.getText(new LocalNode(new RepositoryNode(
    // null, repo), repo));
    TAGS = provider.getText(new TagsNode(new RepositoryNode(null, repo), repo));
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.FetchAndMergeActionTest.java

License:Open Source License

private String prepare() throws Exception {
    deleteAllProjects();/*from ww w  .  j av  a2 s .  c  o  m*/
    shareProjects(repositoryFile);
    Repository repo = lookupRepository(repositoryFile);
    RevWalk rw = new RevWalk(repo);
    ObjectId id = repo.resolve(repo.getFullBranch());
    String commitId = rw.parseCommit(id).name();
    touchAndSubmit(null);
    deleteAllProjects();
    shareProjects(childRepositoryFile);
    waitInUI();
    return commitId;
}

From source file:org.eclipse.egit.ui.test.team.actions.ReplaceActionsTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    commitOfTag = tag.getObjectId();/*  w w  w  .  ja v a 2s  . co m*/
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);
    touchAndSubmit(null);
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.TagActionTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);/*ww  w  .j  av a2  s.co  m*/
    touchAndSubmit(null);
    waitInUI();
}

From source file:org.eclipse.emf.compare.egit.ui.internal.merge.ModelGitMergeEditorInput.java

License:Open Source License

private void setLabels(Repository repository, RevCommit rightCommit, RevCommit leftCommit,
        RevCommit ancestorCommit) throws InvocationTargetException {
    CompareConfiguration config = getCompareConfiguration();
    config.setRightLabel(NLS.bind(LABELPATTERN, rightCommit.getShortMessage(),
            CompareUtils.truncatedRevision(rightCommit.name())));

    if (!useWorkspace) {
        config.setLeftLabel(NLS.bind(LABELPATTERN, leftCommit.getShortMessage(),
                CompareUtils.truncatedRevision(leftCommit.name())));
    } else {/*from   w  w w.ja v  a  2 s . c o  m*/
        config.setLeftLabel(UIText.GitMergeEditorInput_WorkspaceHeader);
    }

    if (ancestorCommit != null) {
        config.setAncestorLabel(NLS.bind(LABELPATTERN, ancestorCommit.getShortMessage(),
                CompareUtils.truncatedRevision(ancestorCommit.name())));
    }

    // set title and icon
    final String fullBranch;
    try {
        fullBranch = repository.getFullBranch();
    } catch (IOException e) {
        throw new InvocationTargetException(e);
    }
    setTitle(NLS.bind(UIText.GitMergeEditorInput_MergeEditorTitle,
            new Object[] { Activator.getDefault().getRepositoryUtil().getRepositoryName(repository),
                    rightCommit.getShortMessage(), fullBranch }));
}

From source file:org.eclipse.mylyn.internal.github.core.pr.PullRequestUtils.java

License:Open Source License

/**
 * Is given branch name the currently checked out branch?
 *
 * @param name/*  ww  w.j a v a 2 s  . c om*/
 * @param repo
 * @return true if checked out branch, false otherwise
 */
public static boolean isCurrentBranch(String name, Repository repo) {
    try {
        return name.equals(Repository.shortenRefName(repo.getFullBranch()));
    } catch (IOException e) {
        return false;
    }
}

From source file:org.flowerplatform.web.git.GitService.java

License:Open Source License

public boolean rebase(ServiceInvocationContext context, String repositoryLocation, String refName) {
    try {/*from w  ww  . ja v a 2s .  c  o  m*/
        Repository repo = RepositoryCache.open(FileKey.exact(new File(repositoryLocation), FS.DETECTED));

        if (!repo.getFullBranch().startsWith(Constants.R_HEADS)) {
            context.getCommunicationChannel()
                    .appendOrSendCommand(new DisplaySimpleMessageClientCommand(
                            CommonPlugin.getInstance().getMessage("error"),
                            GitPlugin.getInstance().getMessage("git.rebase.noLocalBranch"),
                            DisplaySimpleMessageClientCommand.ICON_ERROR));
            return false;
        }
        RebaseOperation op = new RebaseOperation(repo, refName, context.getCommunicationChannel());
        op.execute();

        String result = op.handleRebaseResult();
        if (result != null) {
            context.getCommunicationChannel()
                    .appendOrSendCommand(new DisplaySimpleMessageClientCommand(
                            GitPlugin.getInstance().getMessage("git.rebase.result"), result,
                            DisplaySimpleMessageClientCommand.ICON_INFORMATION));
        }
        return true;
    } catch (Exception e) {
        logger.debug(CommonPlugin.getInstance().getMessage("error"), e);
        context.getCommunicationChannel().appendOrSendCommand(
                new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"),
                        e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR));
        return false;
    }
}

From source file:org.flowerplatform.web.git.GitUtils.java

License:Open Source License

@SuppressWarnings("restriction")
public Object[] getFetchPushUpstreamDataRefSpecAndRemote(Repository repository)
        throws InvalidConfigurationException, NoHeadException, DetachedHeadException {

    String branchName;//  w  w  w  .j  a  va  2  s .  co  m
    String fullBranch;
    try {
        fullBranch = repository.getFullBranch();
        if (fullBranch == null) {
            throw new NoHeadException(JGitText.get().pullOnRepoWithoutHEADCurrentlyNotSupported);
        }
        if (!fullBranch.startsWith(Constants.R_HEADS)) {
            // we can not pull if HEAD is detached and branch is not
            // specified explicitly
            throw new DetachedHeadException();
        }
        branchName = fullBranch.substring(Constants.R_HEADS.length());
    } catch (IOException e) {
        throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfPullCommand, e);
    }
    // get the configured remote for the currently checked out branch
    // stored in configuration key branch.<branch name>.remote
    Config repoConfig = repository.getConfig();
    String remote = repoConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
            ConfigConstants.CONFIG_KEY_REMOTE);
    if (remote == null) {
        // fall back to default remote
        remote = Constants.DEFAULT_REMOTE_NAME;
    }

    // get the name of the branch in the remote repository
    // stored in configuration key branch.<branch name>.merge
    String remoteBranchName = repoConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
            ConfigConstants.CONFIG_KEY_MERGE);

    if (remoteBranchName == null) {
        String missingKey = ConfigConstants.CONFIG_BRANCH_SECTION + "." + branchName + "."
                + ConfigConstants.CONFIG_KEY_MERGE;
        throw new InvalidConfigurationException(
                MessageFormat.format(JGitText.get().missingConfigurationForKey, missingKey));
    }

    // check if the branch is configured for pull-rebase
    boolean doRebase = repoConfig.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
            ConfigConstants.CONFIG_KEY_REBASE, false);

    final boolean isRemote = !remote.equals("."); //$NON-NLS-1$
    String remoteUri;
    if (isRemote) {
        remoteUri = repoConfig.getString(ConfigConstants.CONFIG_REMOTE_SECTION, remote,
                ConfigConstants.CONFIG_KEY_URL);
        if (remoteUri == null) {
            String missingKey = ConfigConstants.CONFIG_REMOTE_SECTION + "." + remote + "."
                    + ConfigConstants.CONFIG_KEY_URL;
            throw new InvalidConfigurationException(
                    MessageFormat.format(JGitText.get().missingConfigurationForKey, missingKey));
        }

        return new Object[] { fullBranch, remoteBranchName, remoteUri, doRebase };
    }
    return null;
}