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

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

Introduction

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

Prototype

@Nullable
public String getBranch() throws IOException 

Source Link

Document

Get the short name of the current branch that HEAD points to.

Usage

From source file:org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider.java

License:Open Source License

public StyledString getStyledText(Object element) {
    if (!(element instanceof RepositoryTreeNode))
        return null;

    RepositoryTreeNode node = (RepositoryTreeNode) element;

    try {//  ww w  .jav a 2  s .co m
        switch (node.getType()) {
        case REPO:
            Repository repository = (Repository) node.getObject();
            File directory = repository.getDirectory();
            StyledString string = new StyledString(directory.getParentFile().getName());
            string.append(" - " + directory.getAbsolutePath(), StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
            String branch = repository.getBranch();
            if (repository.getRepositoryState() != RepositoryState.SAFE)
                branch += " - " + repository.getRepositoryState().getDescription(); //$NON-NLS-1$
            string.append(" [" + branch + "]", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$//$NON-NLS-2$
            return string;
        case ADDITIONALREF:
            Ref ref = (Ref) node.getObject();
            // shorten the name
            StyledString refName = new StyledString(Repository.shortenRefName(ref.getName()));
            if (ref.isSymbolic()) {
                refName.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
                refName.append(ref.getLeaf().getName(), StyledString.QUALIFIER_STYLER);
                refName.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
                refName.append(ObjectId.toString(ref.getLeaf().getObjectId()), StyledString.QUALIFIER_STYLER);
            } else {
                refName.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
                refName.append(ObjectId.toString(ref.getObjectId()), StyledString.QUALIFIER_STYLER);

            }
            return refName;
        case WORKINGDIR:
            StyledString dirString = new StyledString(UIText.RepositoriesView_WorkingDir_treenode);
            dirString.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
            if (node.getRepository().isBare()) {
                dirString.append(UIText.RepositoriesViewLabelProvider_BareRepositoryMessage,
                        StyledString.QUALIFIER_STYLER);
            } else {
                dirString.append(node.getRepository().getWorkTree().getAbsolutePath(),
                        StyledString.QUALIFIER_STYLER);
            }
            return dirString;
        case PUSH:
            // fall through
        case FETCH:
            // fall through
        case FILE:
            // fall through
        case FOLDER:
            // fall through
        case BRANCHES:
            // fall through
        case LOCAL:
            // fall through
        case REMOTETRACKING:
            // fall through
        case BRANCHHIERARCHY:
            // fall through
        case TAGS:
            // fall through;
        case ADDITIONALREFS:
            // fall through
        case REMOTES:
            // fall through
        case REMOTE:
            // fall through
        case ERROR:
            // fall through
        case REF:
            // fall through
        case TAG: {
            String label = getSimpleText(node);
            if (label != null)
                return new StyledString(label);
        }

        }
    } catch (IOException e) {
        Activator.logError(e.getMessage(), e);
    }

    return null;

}

From source file:org.eclipse.egit.ui.internal.repository.tree.command.CreateTagCommand.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    RepositoryTreeNode node = getSelectedNodes(event).get(0);

    final Repository repo = node.getRepository();

    if (!repo.getRepositoryState().canCheckout()) {
        MessageDialog.openError(getShell(event), UIText.TagAction_cannotCheckout,
                NLS.bind(UIText.TagAction_repositoryState, repo.getRepositoryState().getDescription()));
        return null;
    }//from   w  w  w . ja  va2 s  .  com

    String currentBranchName;
    try {
        currentBranchName = repo.getBranch();
    } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, true);
        // TODO correct message
        throw new ExecutionException(e.getMessage(), e);
    }

    CreateTagDialog dialog = new CreateTagDialog(getView(event).getSite().getShell(), currentBranchName, repo);

    if (dialog.open() != IDialogConstants.OK_ID)
        return null;

    final TagBuilder tag = new TagBuilder();
    PersonIdent personIdent = new PersonIdent(repo);
    String tagName = dialog.getTagName();

    tag.setTag(tagName);
    tag.setTagger(personIdent);
    tag.setMessage(dialog.getTagMessage());
    tag.setObjectId(getTagTarget(dialog.getTagCommit(), repo));

    String tagJobName = NLS.bind(UIText.TagAction_creating, tagName);
    final boolean shouldMoveTag = dialog.shouldOverWriteTag();

    Job tagJob = new Job(tagJobName) {
        protected IStatus run(IProgressMonitor monitor) {
            try {
                new TagOperation(repo, tag, shouldMoveTag).execute(monitor);
            } catch (CoreException e) {
                return Activator.createErrorStatus(UIText.TagAction_taggingFailed, e);
            } finally {
                GitLightweightDecorator.refresh();
            }

            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (family.equals(JobFamilies.TAG))
                return true;
            return super.belongsTo(family);
        }
    };

    tagJob.setUser(true);
    tagJob.schedule();

    return null;
}

From source file:org.eclipse.egit.ui.internal.repository.tree.command.PullCommand.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {

    final Repository repository = getSelectedNodes(event).get(0).getRepository();
    if (repository == null)
        return null;

    // obtain the currently checked-out branch
    String branchName;/*w  w  w  . j  a v  a2 s . co m*/
    try {
        branchName = repository.getBranch();
    } catch (IOException e) {
        throw new ExecutionException(e.getMessage(), e);
    }

    String jobname = NLS.bind(UIText.PullCurrentBranchActionHandler_PullJobname, branchName);
    int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
    final PullOperation pull = new PullOperation(repository, timeout);
    Job job = new Job(jobname) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                pull.execute(monitor);
            } catch (final CoreException e) {
                return e.getStatus();
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.setRule(pull.getSchedulingRule());
    job.addJobChangeListener(new JobChangeAdapter() {
        @Override
        public void done(IJobChangeEvent cevent) {
            IStatus result = cevent.getJob().getResult();
            if (result.getSeverity() == IStatus.CANCEL) {
                Display.getDefault().asyncExec(new Runnable() {
                    public void run() {
                        // don't use getShell(event) here since
                        // the active shell has changed since the
                        // execution has been triggered.
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        MessageDialog.openInformation(shell,
                                UIText.PullCurrentBranchActionHandler_PullCanceledTitle,
                                UIText.PullCurrentBranchActionHandler_PullCanceledMessage);
                    }
                });
            } else if (result.isOK()) {
                Display.getDefault().asyncExec(new Runnable() {
                    public void run() {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        new PullResultDialog(shell, repository, pull.getResult()).open();
                    }
                });
            }
        }
    });
    job.schedule();
    return null;
}

From source file:org.eclipse.egit.ui.test.history.HistoryViewTest.java

License:Open Source License

@Test
public void testCheckOut() throws Exception {
    Repository repo = lookupRepository(repoFile);
    assertEquals(Constants.MASTER, repo.getBranch());

    final SWTBotTable table = getHistoryViewTable(PROJ1);
    // check out the second line
    table.getTableItem(1).select();//from w  w  w .  j a va 2  s  .  c  om
    final RevCommit[] commit = new RevCommit[1];

    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            TableItem tableItem = table.widget.getSelection()[0];
            ensureTableItemLoaded(tableItem);
            commit[0] = (RevCommit) tableItem.getData();
        }
    });

    ContextMenuHelper.clickContextMenu(table, UIText.GitHistoryPage_CheckoutMenuLabel);
    TestUtil.joinJobs(JobFamilies.CHECKOUT);
    assertEquals(commit[0].getId().name(), repo.getBranch());
}

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

License:Open Source License

@Before
public void prepare() throws Exception {
    Repository repo = lookupRepository(repositoryFile);
    if (!repo.getBranch().equals("master")) {
        BranchOperation bop = new BranchOperation(repo, "refs/heads/master");
        bop.execute(null);// ww w  . j  a  va2 s  .com
    }
}

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

License:Open Source License

private void checkoutAndVerify(String[] currentBranch, String[] newBranch) throws IOException, Exception {
    SWTBotShell dialog = openBranchDialog();
    TableCollection tc = dialog.bot().tree().selection();
    assertEquals("Wrong selection count", 1, tc.rowCount());
    assertEquals("Wrong item selected", currentBranch[1], tc.get(0, 0));

    dialog.bot().tree().getTreeItem(newBranch[0]).expand().getNode(newBranch[1]).select();
    tc = dialog.bot().tree().selection();
    assertEquals("Wrong selection count", 1, tc.rowCount());
    assertEquals("Wrong item selected", newBranch[1], tc.get(0, 0));

    Repository repo = lookupRepository(repositoryFile);

    dialog.bot().button(UIText.BranchSelectionDialog_OkCheckout).click();
    waitInUI();/*from   w w w  .  jav a  2s.  c  o  m*/
    if (ObjectId.isId(repo.getBranch())) {
        String mapped = Activator.getDefault().getRepositoryUtil().mapCommitToRef(repo, repo.getBranch(),
                false);
        assertEquals("Wrong branch", newBranch[1], mapped.substring(mapped.lastIndexOf('/') + 1));
    } else
        assertEquals("Wrong branch", newBranch[1], repo.getBranch());
}

From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewBranchHandlingTest.java

License:Open Source License

@Test
public void testCheckoutRemote() throws Exception {
    SWTBotPerspective perspective = null;
    try {//from ww w .j  a va2 s .  c  o  m
        perspective = bot.activePerspective();
        bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
        clearView();
        Activator.getDefault().getRepositoryUtil().addConfiguredRepository(clonedRepositoryFile);
        shareProjects(clonedRepositoryFile);
        refreshAndWait();

        Repository repo = lookupRepository(clonedRepositoryFile);
        BranchOperation bop = new BranchOperation(repo, "refs/heads/master");
        bop.execute(null);

        assertEquals("master", repo.getBranch());
        SWTBotTree tree = getOrOpenView().bot().tree();

        SWTBotTreeItem item = myRepoViewUtil.getLocalBranchesItem(tree, clonedRepositoryFile).expand();

        touchAndSubmit(null);
        refreshAndWait();

        item = myRepoViewUtil.getRemoteBranchesItem(tree, clonedRepositoryFile).expand();
        List<String> children = item.getNodes();
        assertEquals("Wrong number of remote children", 2, children.size());

        item.getNode("origin/stable").select();
        ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("CheckoutCommand"));
        TestUtil.joinJobs(JobFamilies.CHECKOUT);
        refreshAndWait();

        GitLightweightDecorator.refresh();

        assertTrue("Branch should not be symbolic",
                ObjectId.isId(lookupRepository(clonedRepositoryFile).getBranch()));

        // now let's try to create a local branch from the remote one
        item = myRepoViewUtil.getRemoteBranchesItem(tree, clonedRepositoryFile).expand();
        item.getNode("origin/stable").select();
        ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("CreateBranchCommand"));

        SWTBotShell createPage = bot.shell(UIText.CreateBranchWizard_NewBranchTitle);
        createPage.activate();
        assertEquals("Wrong suggested branch name", "stable",
                createPage.bot().textWithId("BranchName").getText());
        createPage.close();
        // checkout master again

        myRepoViewUtil.getLocalBranchesItem(tree, clonedRepositoryFile).expand().getNode("master").select();
        ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("CheckoutCommand"));
        TestUtil.joinJobs(JobFamilies.CHECKOUT);
        refreshAndWait();

    } finally {
        if (perspective != null)
            perspective.activate();
    }
}

From source file:org.eclipse.orion.server.git.BranchToJSONConverter.java

License:Open Source License

public static JSONObject toJSON(Ref ref, Repository db, URI baseLocation, int segmentsToRemove)
        throws JSONException, URISyntaxException, IOException, CoreException {
    JSONObject result = new JSONObject();
    String shortName = Repository.shortenRefName(ref.getName());
    result.put(ProtocolConstants.KEY_NAME, shortName);
    result.put(ProtocolConstants.KEY_TYPE, GitConstants.KEY_BRANCH_NAME);

    IPath basePath = new Path(baseLocation.getPath());
    IPath newPath = new Path(GitServlet.GIT_URI).append(GitConstants.BRANCH_RESOURCE).append(shortName)
            .append(basePath.removeFirstSegments(segmentsToRemove));
    URI location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(),
            baseLocation.getPort(), newPath.toString(), baseLocation.getQuery(), baseLocation.getFragment());
    result.put(ProtocolConstants.KEY_LOCATION, location);

    // add Git Clone URI
    result.put(GitConstants.KEY_CLONE,/*from   w ww  . j  a  v  a  2  s .c o m*/
            BaseToCloneConverter.getCloneLocation(location, BaseToCloneConverter.BRANCH));

    // add Git Commit URI
    result.put(GitConstants.KEY_COMMIT,
            BaseToCommitConverter.getCommitLocation(location, shortName, BaseToCommitConverter.REMOVE_FIRST_3));

    result.put(GitConstants.KEY_REMOTE, BaseToRemoteConverter.getRemoteBranchLocation(location, shortName, db,
            BaseToRemoteConverter.REMOVE_FIRST_3));
    result.put(GitConstants.KEY_HEAD, BaseToCommitConverter.getCommitLocation(location, Constants.HEAD,
            BaseToCommitConverter.REMOVE_FIRST_3));
    result.put(GitConstants.KEY_BRANCH_CURRENT, shortName.equals(db.getBranch()));

    return result;
}

From source file:org.eclipse.orion.server.git.GitFileDecorator.java

License:Open Source License

private void addGitLinks(URI location, JSONObject representation)
        throws URISyntaxException, JSONException, CoreException, IOException {
    JSONObject gitSection = new JSONObject();
    IPath targetPath = new Path(location.getPath());

    File gitDir = GitUtils.getGitDir(targetPath);
    Repository db = new FileRepository(gitDir);

    // add Git Diff URI
    IPath path = new Path(
            GitServlet.GIT_URI + '/' + GitConstants.DIFF_RESOURCE + '/' + GitConstants.KEY_DIFF_DEFAULT)
                    .append(targetPath);
    URI link = new URI(location.getScheme(), location.getAuthority(), path.toString(), null, null);
    gitSection.put(GitConstants.KEY_DIFF, link);

    // add Git Status URI
    path = new Path(GitServlet.GIT_URI + '/' + GitConstants.STATUS_RESOURCE).append(targetPath);
    link = new URI(location.getScheme(), location.getAuthority(), path.toString(), null, null);
    gitSection.put(GitConstants.KEY_STATUS, link);

    // add Git Index URI
    path = new Path(GitServlet.GIT_URI + '/' + GitConstants.INDEX_RESOURCE).append(targetPath);
    link = new URI(location.getScheme(), location.getAuthority(), path.toString(), null, null);
    gitSection.put(GitConstants.KEY_INDEX, link);

    // add Git HEAD URI
    path = new Path(GitServlet.GIT_URI + '/' + GitConstants.COMMIT_RESOURCE).append(Constants.HEAD)
            .append(targetPath);//from   w  w w  . j a v a  2  s  .c  om
    link = new URI(location.getScheme(), location.getAuthority(), path.toString(), null, null);
    gitSection.put(GitConstants.KEY_HEAD, link);

    // add Git Commit URI
    path = new Path(GitServlet.GIT_URI + '/' + GitConstants.COMMIT_RESOURCE).append(db.getBranch())
            .append(targetPath);
    link = new URI(location.getScheme(), location.getAuthority(), path.toString(), null, null);
    gitSection.put(GitConstants.KEY_COMMIT, link);

    // add Git Remote URI
    path = new Path(GitServlet.GIT_URI + '/' + GitConstants.REMOTE_RESOURCE).append(targetPath);
    link = new URI(location.getScheme(), location.getAuthority(), path.toString(), null, null);
    gitSection.put(GitConstants.KEY_REMOTE, link);

    // add Git Clone Config URI
    path = new Path(GitServlet.GIT_URI + '/' + GitConstants.CONFIG_RESOURCE + '/' + GitConstants.CLONE_RESOURCE)
            .append(targetPath);
    link = new URI(location.getScheme(), location.getAuthority(), path.toString(), null, null);
    gitSection.put(GitConstants.KEY_CONFIG, link);

    // add Git Default Remote Branch URI
    gitSection.put(GitConstants.KEY_DEFAULT_REMOTE_BRANCH, BaseToRemoteConverter
            .getRemoteBranchLocation(location, db.getBranch(), db, BaseToRemoteConverter.FILE));

    // add Git Tag URI
    path = new Path(GitServlet.GIT_URI + '/' + GitConstants.TAG_RESOURCE).append(targetPath);
    link = new URI(location.getScheme(), location.getAuthority(), path.toString(), null, null);
    gitSection.put(GitConstants.KEY_TAG, link);

    // add Git Clone URI
    gitSection.put(GitConstants.KEY_CLONE,
            BaseToCloneConverter.getCloneLocation(location, BaseToCloneConverter.FILE));

    representation.put(GitConstants.KEY_GIT, gitSection);
}

From source file:org.eclipse.orion.server.git.servlets.GitRemoteHandlerV1.java

License:Open Source License

private boolean handleGet(HttpServletRequest request, HttpServletResponse response, String path)
        throws IOException, JSONException, ServletException, URISyntaxException, CoreException {
    Path p = new Path(path);
    // FIXME: what if a remote or branch is named "file"?
    if (p.segment(0).equals("file")) { //$NON-NLS-1$
        // /git/remote/file/{path}
        File gitDir = GitUtils.getGitDir(p);
        Repository db = new FileRepository(gitDir);
        Set<String> configNames = db.getConfig().getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);
        JSONObject result = new JSONObject();
        JSONArray children = new JSONArray();
        URI baseLocation = getURI(request);
        for (String configName : configNames) {
            JSONObject o = new JSONObject();
            o.put(ProtocolConstants.KEY_NAME, configName);
            o.put(ProtocolConstants.KEY_TYPE, GitConstants.KEY_REMOTE_NAME);
            o.put(GitConstants.KEY_URL, db.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION,
                    configName, "url" /*RemoteConfig.KEY_URL*/));
            String pushUrl = null;
            if ((pushUrl = db.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, configName,
                    "pushurl" /*RemoteConfig.KEY_PUSHURL*/)) != null)
                o.put(GitConstants.KEY_PUSH_URL, pushUrl);
            o.put(ProtocolConstants.KEY_LOCATION, BaseToRemoteConverter.REMOVE_FIRST_2
                    .baseToRemoteLocation(baseLocation, configName, "" /* no branch name */)); //$NON-NLS-1$
            children.put(o);/*from   w  w w.  ja  va2 s  .com*/
        }
        result.put(ProtocolConstants.KEY_CHILDREN, children);
        OrionServlet.writeJSONResponse(request, response, result);
        return true;
    } else if (p.segment(1).equals("file")) { //$NON-NLS-1$
        // /git/remote/{remote}/file/{path}
        File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1));
        Repository db = new FileRepository(gitDir);
        Set<String> configNames = db.getConfig().getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);
        JSONObject result = new JSONObject();
        URI baseLocation = getURI(request);

        for (String configName : configNames) {
            if (configName.equals(p.segment(0))) {
                result.put(ProtocolConstants.KEY_NAME, configName);
                result.put(ProtocolConstants.KEY_TYPE, GitConstants.KEY_REMOTE_NAME);
                result.put(ProtocolConstants.KEY_LOCATION, BaseToRemoteConverter.REMOVE_FIRST_3
                        .baseToRemoteLocation(baseLocation, p.segment(0), "" /* no branch name */)); //$NON-NLS-1$

                JSONArray children = new JSONArray();
                List<Ref> refs = new ArrayList<Ref>();
                for (Entry<String, Ref> refEntry : db.getRefDatabase()
                        .getRefs(Constants.R_REMOTES + p.uptoSegment(1)).entrySet()) {
                    if (!refEntry.getValue().isSymbolic()) {
                        Ref ref = refEntry.getValue();
                        String name = ref.getName();
                        name = Repository.shortenRefName(name)
                                .substring(Constants.DEFAULT_REMOTE_NAME.length() + 1);
                        if (db.getBranch().equals(name)) {
                            refs.add(0, ref);
                        } else {
                            refs.add(ref);
                        }
                    }
                }
                for (Ref ref : refs) {
                    JSONObject o = new JSONObject();
                    String name = ref.getName();
                    o.put(ProtocolConstants.KEY_NAME, name.substring(Constants.R_REMOTES.length()));
                    o.put(ProtocolConstants.KEY_FULL_NAME, name);
                    o.put(ProtocolConstants.KEY_TYPE, GitConstants.REMOTE_TRACKING_BRANCH_TYPE);
                    o.put(ProtocolConstants.KEY_ID, ref.getObjectId().name());
                    // see bug 342602
                    // o.put(GitConstants.KEY_COMMIT, baseToCommitLocation(baseLocation, name));
                    o.put(ProtocolConstants.KEY_LOCATION,
                            BaseToRemoteConverter.REMOVE_FIRST_3.baseToRemoteLocation(baseLocation,
                                    "" /*short name is {remote}/{branch}*/, Repository.shortenRefName(name))); //$NON-NLS-1$
                    o.put(GitConstants.KEY_COMMIT, BaseToCommitConverter.getCommitLocation(baseLocation,
                            ref.getObjectId().name(), BaseToCommitConverter.REMOVE_FIRST_3));
                    o.put(GitConstants.KEY_HEAD, BaseToCommitConverter.getCommitLocation(baseLocation,
                            Constants.HEAD, BaseToCommitConverter.REMOVE_FIRST_3));
                    o.put(GitConstants.KEY_CLONE,
                            BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.REMOTE));
                    o.put(GitConstants.KEY_BRANCH, BaseToBranchConverter.getBranchLocation(baseLocation,
                            BaseToBranchConverter.REMOTE));
                    o.put(GitConstants.KEY_INDEX,
                            BaseToIndexConverter.getIndexLocation(baseLocation, BaseToIndexConverter.REMOTE));
                    children.put(o);
                }
                result.put(ProtocolConstants.KEY_CHILDREN, children);
                OrionServlet.writeJSONResponse(request, response, result);
                return true;
            }
        }
        String msg = NLS.bind("Couldn't find remote : {0}", p.segment(0));
        return statusHandler.handleRequest(request, response,
                new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null));
    } else if (p.segment(2).equals("file")) { //$NON-NLS-1$
        // /git/remote/{remote}/{branch}/file/{path}
        File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2));
        Repository db = new FileRepository(gitDir);
        Set<String> configNames = db.getConfig().getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);
        URI baseLocation = getURI(request);
        for (String configName : configNames) {
            if (configName.equals(p.segment(0))) {
                for (Entry<String, Ref> refEntry : db.getRefDatabase().getRefs(Constants.R_REMOTES)
                        .entrySet()) {
                    Ref ref = refEntry.getValue();
                    String name = ref.getName();
                    if (!ref.isSymbolic()
                            && name.equals(Constants.R_REMOTES + p.uptoSegment(2).removeTrailingSeparator())) {
                        JSONObject result = new JSONObject();
                        result.put(ProtocolConstants.KEY_NAME, name.substring(Constants.R_REMOTES.length()));
                        result.put(ProtocolConstants.KEY_FULL_NAME, name);
                        result.put(ProtocolConstants.KEY_TYPE, GitConstants.REMOTE_TRACKING_BRANCH_TYPE);
                        result.put(ProtocolConstants.KEY_ID, ref.getObjectId().name());
                        // see bug 342602
                        // result.put(GitConstants.KEY_COMMIT, baseToCommitLocation(baseLocation, name));
                        result.put(ProtocolConstants.KEY_LOCATION,
                                BaseToRemoteConverter.REMOVE_FIRST_4.baseToRemoteLocation(baseLocation,
                                        "" /*short name is {remote}/{branch}*/, //$NON-NLS-1$
                                        Repository.shortenRefName(name)));
                        result.put(GitConstants.KEY_COMMIT, BaseToCommitConverter.getCommitLocation(
                                baseLocation, ref.getObjectId().name(), BaseToCommitConverter.REMOVE_FIRST_4));
                        result.put(GitConstants.KEY_HEAD, BaseToCommitConverter.getCommitLocation(baseLocation,
                                Constants.HEAD, BaseToCommitConverter.REMOVE_FIRST_4));
                        result.put(GitConstants.KEY_CLONE, BaseToCloneConverter.getCloneLocation(baseLocation,
                                BaseToCloneConverter.REMOTE_BRANCH));
                        OrionServlet.writeJSONResponse(request, response, result);
                        return true;
                    }
                }
            }
        }
        JSONObject errorData = new JSONObject();
        errorData.put(GitConstants.KEY_CLONE,
                BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.REMOTE_BRANCH));

        return statusHandler
                .handleRequest(request, response,
                        new ServerStatus(
                                new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE,
                                        "No remote branch found: "
                                                + p.uptoSegment(2).removeTrailingSeparator()),
                                HttpServletResponse.SC_NOT_FOUND, errorData));
    }
    return statusHandler.handleRequest(request, response,
            new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
                    "Bad request, \"/git/remote/{remote}/{branch}/file/{path}\" expected", null));
}