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

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

Introduction

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

Prototype

String R_REMOTES

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

Click Source Link

Document

Prefix for remotes refs

Usage

From source file:org.eclipse.egit.ui.view.synchronize.SynchronizeViewPushTest.java

License:Open Source License

@Test
public void shouldUpdateTrackingBranchOnPush() throws Exception {
    makeChangesAndCommit(PROJ1);//w w w .j  a  va  2  s .c om
    FileRepository repository = lookupRepository(repositoryFile);
    ObjectId headId = repository.resolve(Constants.HEAD);

    String trackingBranch = Constants.R_REMOTES + "origin/master";
    launchSynchronization(Constants.HEAD, trackingBranch, false);

    SWTBotView viewBot = bot.viewByTitle("Synchronize");
    SWTBotToolbarButton pushButton = viewBot.toolbarButton(UIText.GitActionContributor_Push);
    JobJoiner jobJoiner = JobJoiner.startListening(JobFamilies.PUSH, 30, TimeUnit.SECONDS);
    pushButton.click();
    jobJoiner.join();

    String destinationString = repositoryFile.getParentFile().getName() + " - " + "origin";
    SWTBotShell resultDialog = bot.shell(NLS.bind(UIText.ResultDialog_title, destinationString));
    resultDialog.close();

    FileRepository remoteRepository = lookupRepository(childRepositoryFile);
    ObjectId masterOnRemote = remoteRepository.resolve("master");
    assertThat("Expected push to update branch on remote repository", masterOnRemote, is(headId));

    ObjectId trackingId = repository.resolve(trackingBranch);
    assertThat("Expected tracking branch to be updated", trackingId, is(headId));
}

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

License:Open Source License

/**
 * Get destination ref spec//from   w w w.  ja  v  a  2 s . co  m
 *
 * @param remote
 * @return ref spec
 */
public static String getDesintationRef(RemoteConfig remote) {
    return Constants.R_REMOTES + remote.getName() + "/*"; //$NON-NLS-1$
}

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

License:Open Source License

/**
 * Get head branch ref for outside repository pull requests
 *
 * @param request// ww  w .ja  v  a  2  s .c  o  m
 * @return remote head branch ref name
 */
public static String getHeadBranch(PullRequest request) {
    PullRequestMarker head = request.getHead();
    return Constants.R_REMOTES + head.getRepo().getOwner().getLogin() + "/" + head.getRef();
}

From source file:org.eclipse.orion.server.git.jobs.FetchJob.java

License:Open Source License

private IStatus doFetch() throws IOException, CoreException, URISyntaxException, GitAPIException {
    Repository db = getRepository();//from   www . j  a  va  2  s.c  o  m

    Git git = new Git(db);
    FetchCommand fc = git.fetch();

    RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), remote);
    credentials.setUri(remoteConfig.getURIs().get(0));

    fc.setCredentialsProvider(credentials);
    fc.setRemote(remote);
    if (branch != null) {
        // refs/heads/{branch}:refs/remotes/{remote}/{branch}
        RefSpec spec = new RefSpec(
                Constants.R_HEADS + branch + ":" + Constants.R_REMOTES + remote + "/" + branch); //$NON-NLS-1$ //$NON-NLS-2$
        spec = spec.setForceUpdate(force);
        fc.setRefSpecs(spec);
    }
    FetchResult fetchResult = fc.call();
    return handleFetchResult(fetchResult);
}

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

License:Open Source License

@PropertyDescription(name = GitConstants.KEY_REMOTE)
private JSONArray getRemotes() throws URISyntaxException, JSONException, IOException, CoreException {
    String branchName = Repository.shortenRefName(ref.getName());
    JSONArray result = new JSONArray();
    String remoteName = getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
            ConfigConstants.CONFIG_KEY_REMOTE);
    if (remoteName != null) {
        RemoteConfig remoteConfig = new RemoteConfig(getConfig(), remoteName);
        if (!remoteConfig.getFetchRefSpecs().isEmpty()) {
            Remote remote = new Remote(cloneLocation, db, remoteName);
            remote.setNewBranch(branchName);
            result.put(remote.toJSON());
        }// w w w . j ava 2 s  .co m
    } else {
        List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(getConfig());
        for (RemoteConfig remoteConfig : remoteConfigs) {
            if (!remoteConfig.getFetchRefSpecs().isEmpty()) {
                Remote r = new Remote(cloneLocation, db, remoteConfig.getName());
                r.setNewBranch(branchName);
                if (db.resolve(Constants.R_REMOTES + remoteConfig.getName() + "/" + branchName) != null) { //$NON-NLS-1$
                    // it's an existing branch, not a new one, use it as filter
                    return new JSONArray().put(r.toJSON());
                }
                result.put(r.toJSON());
            }
        }
    }
    return result;
}

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

License:Open Source License

private JSONObject createJSONObjectForRef(Ref targetRef)
        throws JSONException, URISyntaxException, IOException, CoreException {
    JSONObject result = null;/*from w  ww  .ja  v  a 2  s .c om*/
    String name = targetRef.getName();
    if (name.startsWith(Constants.R_HEADS)) {
        result = new Branch(cloneLocation, db, targetRef).toJSON();
    } else if (name.startsWith(Constants.R_REMOTES)) {
        Remote remote = findRemote(name);
        String remoteBranchName = computeRemoteBranchName(name, remote);
        result = new RemoteBranch(cloneLocation, db, remote, remoteBranchName).toJSON();
    }
    Assert.isNotNull(result, NLS.bind("Unexpected target Ref: {0}", name));
    return result;
}

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

License:Open Source License

private Remote findRemote(String refName) throws URISyntaxException {
    Assert.isLegal(refName.startsWith(Constants.R_REMOTES),
            NLS.bind("Expected Ref starting with {0} was {1}", Constants.R_REMOTES, refName));
    IPath remoteNameCandidate = new Path(refName).removeFirstSegments(2);
    List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(getConfig());
    for (int i = 1; i < remoteNameCandidate.segmentCount(); i++) {
        for (RemoteConfig remoteConfig : remoteConfigs) {
            IPath uptoSegment = remoteNameCandidate.uptoSegment(i);
            if (remoteConfig.getName().equals(uptoSegment.toString()))
                return new Remote(cloneLocation, db, remoteConfig.getName());
        }//w w w.j a v  a  2s .c o m
    }
    Assert.isTrue(false, NLS.bind("Could not find Remote for {0}", refName));
    return null;
}

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

License:Open Source License

private String computeRemoteBranchName(String targetRefName, Remote remote) {
    String prefix = Constants.R_REMOTES + remote.getName() + "/"; //$NON-NLS-1$
    return targetRefName.substring(prefix.length());
}

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

License:Open Source License

@PropertyDescription(name = ProtocolConstants.KEY_CHILDREN)
private JSONArray getChildren() throws IOException, JSONException, URISyntaxException, CoreException {
    JSONArray children = new JSONArray();
    boolean branchFound = false;
    List<Ref> refs = new ArrayList<Ref>();
    String currentBranch = db.getBranch();
    for (Entry<String, Ref> refEntry : db.getRefDatabase().getRefs(Constants.R_REMOTES + name + "/") //$NON-NLS-1$
            .entrySet()) {//from   w  w w . j av  a  2  s .  c o  m
        if (!refEntry.getValue().isSymbolic()) {
            Ref ref = refEntry.getValue();
            String name = ref.getName();
            name = Repository.shortenRefName(name).substring(Constants.DEFAULT_REMOTE_NAME.length() + 1);
            if (currentBranch.equals(name)) {
                refs.add(0, ref);
            } else {
                refs.add(ref);
            }
        }
    }
    for (Ref ref : refs) {
        String remoteBranchName = Repository.shortenRefName(ref.getName());
        remoteBranchName = remoteBranchName.substring((this.name + "/").length()); //$NON-NLS-1$
        RemoteBranch remoteBranch = new RemoteBranch(cloneLocation, db, this, remoteBranchName);
        children.put(remoteBranch.toJSON());
        if (newBranch != null && !newBranch.isEmpty() && remoteBranchName.equals(newBranch)) {
            children = new JSONArray().put(remoteBranch.toJSON());
            branchFound = true;
            break;
        }
    }

    if (!branchFound && newBranch != null && !newBranch.isEmpty()) {
        JSONObject o = new JSONObject();
        // TODO: this should be a RemoteBranch
        String name = Constants.R_REMOTES + getName() + "/" + newBranch; //$NON-NLS-1$
        o.put(ProtocolConstants.KEY_NAME, name.substring(Constants.R_REMOTES.length()));
        o.put(ProtocolConstants.KEY_FULL_NAME, name);
        o.put(ProtocolConstants.KEY_TYPE, RemoteBranch.TYPE);
        o.put(ProtocolConstants.KEY_LOCATION,
                BaseToRemoteConverter.REMOVE_FIRST_2.baseToRemoteLocation(cloneLocation, "", //$NON-NLS-1$
                        /*short name is {remote}/{branch}*/getName() + "/" + GitUtils.encode(newBranch)));
        children.put(o);
    }

    return children;
}

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

License:Open Source License

private String getName(boolean fullName, boolean encode) {
    String name = Constants.R_REMOTES + remote.getName() + "/" + this.name; //$NON-NLS-1$
    if (!fullName)
        name = Repository.shortenRefName(name);
    if (encode)//from w w w.j a  v  a2 s.  c o m
        name = GitUtils.encode(name);
    return name;
}