Example usage for org.eclipse.jgit.lib ConfigConstants CONFIG_REMOTE_SECTION

List of usage examples for org.eclipse.jgit.lib ConfigConstants CONFIG_REMOTE_SECTION

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ConfigConstants CONFIG_REMOTE_SECTION.

Prototype

String CONFIG_REMOTE_SECTION

To view the source code for org.eclipse.jgit.lib ConfigConstants CONFIG_REMOTE_SECTION.

Click Source Link

Document

The "remote" section

Usage

From source file:org.eclipse.orion.server.git.objects.Remote.java

License:Open Source License

public JSONObject toJSON(boolean includeChildren)
        throws JSONException, URISyntaxException, IOException, CoreException {
    Assert.isLegal(getConfig().getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION).contains(name),
            NLS.bind("Remote {0} not found.", name));
    if (includeChildren)
        return jsonSerializer.serialize(this, DEFAULT_RESOURCE_SHAPE);
    else/*w w w. j a va 2 s . co  m*/
        return jsonSerializer.serialize(this, DEFAULT_RESOURCE_SHAPE_WITHOUT_CHILDREN);
}

From source file:org.eclipse.orion.server.git.objects.Remote.java

License:Open Source License

@PropertyDescription(name = GitConstants.KEY_URL)
private String getUrl() {
    return getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, name, "url" /*RemoteConfig.KEY_URL*/); //$NON-NLS-1$
}

From source file:org.eclipse.orion.server.git.objects.Remote.java

License:Open Source License

@PropertyDescription(name = GitConstants.KEY_PUSH_URL)
private String getPushUrl() {
    return getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, name,
            "pushurl" /*RemoteConfig.KEY_PUSHURL*/); //$NON-NLS-1$
}

From source file:org.eclipse.orion.server.git.objects.RemoteBranch.java

License:Open Source License

private Ref findRef() {
    try {//from w  ww .ja  v a2s  .  c  om
        Set<String> configNames = getConfig().getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);
        for (String configName : configNames) {
            if (configName.equals(remote.getName())) {
                final String fullName = getName(true, false);
                Ref ref = db.getRefDatabase().getRef(fullName);
                if (ref != null && !ref.isSymbolic()) {
                    return ref;
                }
            }
        }
    } catch (IOException e) {
        // ignore, return null
    }
    return null;
}

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

License:Open Source License

private JSONObject toJSON(Entry<IPath, File> entry, URI baseLocation) throws URISyntaxException {
    IPath k = entry.getKey();//from  w  ww . jav  a  2 s. com
    JSONObject result = new JSONObject();
    try {
        result.put(ProtocolConstants.KEY_ID, k);

        result.put(ProtocolConstants.KEY_NAME,
                k.segmentCount() == 1 ? WebProject.fromId(k.segment(0)).getName() : k.lastSegment());

        IPath np = new Path(GitServlet.GIT_URI).append(GitConstants.CLONE_RESOURCE).append("file").append(k); //$NON-NLS-1$
        URI location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(),
                baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment());
        result.put(ProtocolConstants.KEY_LOCATION, location);

        np = new Path("file").append(k).makeAbsolute(); //$NON-NLS-1$
        location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(),
                baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment());
        result.put(ProtocolConstants.KEY_CONTENT_LOCATION, location);

        np = new Path(GitServlet.GIT_URI).append(GitConstants.REMOTE_RESOURCE).append("file").append(k); //$NON-NLS-1$
        location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(),
                baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment());
        result.put(GitConstants.KEY_REMOTE, location);

        np = new Path(GitServlet.GIT_URI).append(GitConstants.CONFIG_RESOURCE)
                .append(GitConstants.CLONE_RESOURCE).append("file").append(k); //$NON-NLS-1$
        location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(),
                baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment());
        result.put(GitConstants.KEY_CONFIG, location);

        np = new Path(GitServlet.GIT_URI).append(GitConstants.COMMIT_RESOURCE).append(Constants.HEAD)
                .append("file").append(k); //$NON-NLS-1$
        location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(),
                baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment());
        result.put(GitConstants.KEY_HEAD, location);

        np = new Path(GitServlet.GIT_URI).append(GitConstants.COMMIT_RESOURCE).append("file").append(k); //$NON-NLS-1$
        location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(),
                baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment());
        result.put(GitConstants.KEY_COMMIT, location);

        np = new Path(GitServlet.GIT_URI).append(GitConstants.BRANCH_RESOURCE).append("file").append(k); //$NON-NLS-1$
        location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(),
                baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment());
        result.put(GitConstants.KEY_BRANCH, location);

        np = new Path(GitServlet.GIT_URI).append(GitConstants.INDEX_RESOURCE).append("file").append(k); //$NON-NLS-1$
        location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(),
                baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment());
        result.put(GitConstants.KEY_INDEX, location);

        np = new Path(GitServlet.GIT_URI).append(GitConstants.STATUS_RESOURCE).append("file").append(k); //$NON-NLS-1$
        location = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(),
                baseLocation.getPort(), np.toString(), baseLocation.getQuery(), baseLocation.getFragment());
        result.put(GitConstants.KEY_STATUS, location);

        try {
            FileBasedConfig config = new FileRepository(entry.getValue()).getConfig();
            String remoteUri = config.getString(ConfigConstants.CONFIG_REMOTE_SECTION,
                    Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL);
            if (remoteUri != null)
                result.put(GitConstants.KEY_URL, remoteUri);
        } catch (IOException e) {
            // ignore and skip Git URL
        }
    } catch (JSONException e) {
        //cannot happen, we know keys and values are valid
    }
    return result;
}

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);// w w w  . j a  v  a2s .co m
        }
        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));
}

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

License:Open Source License

private boolean handleDelete(HttpServletRequest request, HttpServletResponse response, String path)
        throws CoreException, IOException, URISyntaxException, JSONException, ServletException {
    Path p = new Path(path);
    if (p.segment(1).equals("file")) { //$NON-NLS-1$
        // expected path: /gitapi/remote/{remote}/file/{path}
        String remoteName = p.segment(0);

        File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1));
        Repository db = new FileRepository(gitDir);
        StoredConfig config = db.getConfig();
        config.unsetSection(ConfigConstants.CONFIG_REMOTE_SECTION, remoteName);
        config.save();/*from   ww  w.ja va 2  s.  c om*/
        //TODO: handle result
        return true;
    }
    return false;
}

From source file:org.fedoraproject.eclipse.packager.git.api.ConvertLocalToRemoteCommand.java

License:Open Source License

/**
 * Implementation of the {@code ConvertLocalToRemoteCommand}.
 *
 * @param monitor/*w  w  w.  j av  a 2s  .c o  m*/
 * @throws CommandMisconfiguredException
 *             If the command was not properly configured when it was
 *             called.
 * @throws CommandListenerException
 *             If some listener detected a problem.
 * @return The result of this command.
 * @throws LocalProjectConversionFailedException
 * @throws RemoteAlreadyExistsException
 */
@Override
public ConvertLocalResult call(IProgressMonitor monitor) throws CommandMisconfiguredException,
        CommandListenerException, LocalProjectConversionFailedException, RemoteAlreadyExistsException {

    try {
        callPreExecListeners();
    } catch (CommandListenerException e) {
        if (e.getCause() instanceof CommandMisconfiguredException) {
            // explicitly throw the specific exception
            throw (CommandMisconfiguredException) e.getCause();
        }
        throw e;
    }

    IFpProjectBits projectBits = FedoraPackagerUtils.getVcsHandler(projectRoot);

    // Find the local repository
    RepositoryCache repoCache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();

    try {
        git = new Git(
                repoCache.lookupRepository(projectRoot.getProject().getFile(".git").getLocation().toFile())); //$NON-NLS-1$

        String uri = projectBits.getScmUrl();
        Map<String, Ref> ref = git.getRepository().getAllRefs();

        Set<String> existingRemoteList = git.getRepository().getConfig()
                .getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);

        if (existingRemoteList.size() == 0) {
            addRemote = true;
            addBranch = true;
        }

        Iterator<String> itr = existingRemoteList.iterator();
        while (itr.hasNext()) {
            String remote = itr.next();
            if (remote.equals("origin")) { //$NON-NLS-1$
                if (!checkExistingRemoteRepository(uri)) {
                    throw new RemoteAlreadyExistsException(NLS.bind(
                            FedoraPackagerGitText.ConvertLocalToRemoteCommand_existingRemoteNotficiation,
                            existingRemote));
                } else {
                    if (ref.toString().contains(Constants.R_REMOTES)) {
                        hadFetched = true;
                        addBranch = true;
                    } else {
                        addRemote = true;
                        addBranch = true;
                        hadFetched = false;
                    }
                }
            } else {
                addRemote = true;
                addBranch = true;
            }
        }

        if (addRemote) {
            addRemoteRepository(uri, monitor);
        }
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        if (addBranch) {
            GitUtils.createLocalBranches(git, monitor);
        }
        mergeLocalRemoteBranches(monitor);
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        // set the project property to main fedora packager's property
        projectRoot.getProject().setPersistentProperty(PackagerPlugin.PROJECT_PROP, "true"); //$NON-NLS-1$
        projectRoot.getProject().setPersistentProperty(PackagerPlugin.PROJECT_LOCAL_PROP, null);
    } catch (Exception e) {
        if (e instanceof OperationCanceledException) {
            throw ((OperationCanceledException) e);
        } else if (e instanceof RemoteAlreadyExistsException) {
            throw ((RemoteAlreadyExistsException) e);
        } else {
            throw new LocalProjectConversionFailedException(e.getMessage(), e);
        }
    }

    ConvertLocalResult result = new ConvertLocalResult(git, addRemote, addBranch, hadFetched);

    // Call post-exec listeners
    callPostExecListeners();
    result.setSuccessful(true);
    setCallable(false);
    return result;
}

From source file:org.fedoraproject.eclipse.packager.git.api.ConvertLocalToRemoteCommand.java

License:Open Source License

/**
 * Find the added remote uri, if it exists
 *
 * @param uri//from www  . ja v a2s .  c  o m
 * @return boolean
 */
private boolean checkExistingRemoteRepository(String uri) {
    existingRemote = git.getRepository().getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", //$NON-NLS-1$
            "url"); //$NON-NLS-1$
    String[] existingRemoteSplit = existingRemote.split("://"); //$NON-NLS-1$
    return uri.contains(existingRemoteSplit[1]);
}

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 av a  2s .  c o  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;
}