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

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

Introduction

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

Prototype

String R_HEADS

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

Click Source Link

Document

Prefix for branch refs

Usage

From source file:com.google.gitiles.VisibilityCache.java

License:Open Source License

private boolean isVisible(Repository repo, RevWalk walk, ObjectId id) throws IOException {
    RevCommit commit;/*www  . jav a2  s .c o m*/
    try {
        commit = walk.parseCommit(id);
    } catch (IncorrectObjectTypeException e) {
        return false;
    }

    // If any reference directly points at the requested object, permit display.
    // Common for displays of pending patch sets in Gerrit Code Review, or
    // bookmarks to the commit a tag points at.
    Collection<Ref> allRefs = repo.getRefDatabase().getRefs(RefDatabase.ALL).values();
    for (Ref ref : allRefs) {
        ref = repo.getRefDatabase().peel(ref);
        if (id.equals(ref.getObjectId()) || id.equals(ref.getPeeledObjectId())) {
            return true;
        }
    }

    // Check heads first under the assumption that most requests are for refs
    // close to a head. Tags tend to be much further back in history and just
    // clutter up the priority queue in the common case.
    return isReachableFrom(walk, commit, filter(allRefs, refStartsWith(Constants.R_HEADS)))
            || isReachableFrom(walk, commit, filter(allRefs, refStartsWith(Constants.R_TAGS)))
            || isReachableFrom(walk, commit, filter(allRefs, not(refStartsWith("refs/changes/"))));
}

From source file:com.googlesource.gerrit.plugins.xdocs.XDocServlet.java

License:Apache License

private String getRevision(String revision, ProjectControl projectControl)
        throws ResourceNotFoundException, AuthException, IOException {
    if (revision == null) {
        return null;
    }/*from  www  .j  a v a2  s .  c o m*/

    if (ObjectId.isId(revision)) {
        return revision;
    }

    if (Constants.HEAD.equals(revision)) {
        return getHead.get().apply(new ProjectResource(projectControl));
    } else {
        String rev = revision;
        if (!rev.startsWith(Constants.R_REFS)) {
            rev = Constants.R_HEADS + rev;
        }
        if (!projectControl.controlForRef(rev).isVisible()) {
            throw new ResourceNotFoundException();
        }
        return rev;
    }
}

From source file:com.hazelcast.simulator.utils.jars.GitSupport.java

License:Open Source License

private void addRepository(StoredConfig config, GitRepository repository) {
    String url = repository.getUrl();
    String name = repository.getName();
    LOGGER.info("Adding a new custom repository " + url);
    config.setString(CONFIG_REMOTE, name, CONFIG_URL, url);
    RefSpec refSpec = new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + '*',
            Constants.R_REMOTES + name + "/*");
    config.setString(CONFIG_REMOTE, name, "fetch", refSpec.toString());
}

From source file:com.microsoft.gittf.client.clc.commands.framework.Command.java

License:Open Source License

protected void verifyMasterBranch() throws Exception {
    final Repository repository = getRepository();

    if (!RepositoryUtil.isEmptyRepository(repository)) {
        Ref master = repository.getRef(Constants.R_HEADS + Constants.MASTER);
        Ref head = repository.getRef(Constants.HEAD);
        Ref masterHeadRef = master != null ? master.getLeaf() : null;
        Ref currentHeadRef = head != null ? head.getLeaf() : null;

        if (masterHeadRef == null || !masterHeadRef.getName().equals(currentHeadRef.getName())) {
            throw new Exception(Messages.getString("Command.MasterNotCurrentBranch")); //$NON-NLS-1$
        }//from   ww  w. j  ava2s.c  o  m
    }
}

From source file:com.microsoft.gittf.core.tasks.CloneTask.java

License:Open Source License

@Override
public TaskStatus run(final TaskProgressMonitor progressMonitor) throws Exception {
    final String taskName = Messages.formatString("CloneTask.CloningFormat", //$NON-NLS-1$
            tfsPath,// ww w  . j a  v a 2  s  .com
            bare ? repository.getDirectory().getAbsolutePath() : repository.getWorkTree().getAbsolutePath());

    progressMonitor.beginTask(taskName, 1,
            TaskProgressDisplay.DISPLAY_PROGRESS.combine(TaskProgressDisplay.DISPLAY_SUBTASK_DETAIL));

    /*
     * Query the changesets.
     */

    /* See if this is an actual server path. */
    final Item item = vcClient.getItem(tfsPath, versionSpec, DeletedState.NON_DELETED, GetItemsOptions.NONE);
    Check.notNull(item, "item"); //$NON-NLS-1$

    if (item.getItemType() != ItemType.FOLDER) {
        return new TaskStatus(TaskStatus.ERROR,
                Messages.formatString("CloneTask.CannotCloneFileFormat", tfsPath)); //$NON-NLS-1$
    }

    /* Determine the latest changeset on the server. */
    final Changeset[] changesets = vcClient.queryHistory(tfsPath, versionSpec, 0, RecursionType.FULL, null,
            new ChangesetVersionSpec(0), versionSpec, depth, false, false, false, false);

    /*
     * Create and configure the repository.
     */

    repository.create(bare);

    final ConfigureRepositoryTask configureTask = new ConfigureRepositoryTask(repository, serverURI, tfsPath);
    configureTask.setTag(tag);

    final TaskStatus configureStatus = new TaskExecutor(new NullTaskProgressMonitor()).execute(configureTask);

    if (!configureStatus.isOK()) {
        return configureStatus;
    }

    if (changesets.length > 0) {
        ObjectId lastCommitID = null;
        ObjectId lastTreeID = null;
        Item[] previousChangesetItems = null;

        /*
         * Download changesets.
         */
        final int numberOfChangesetToDownload = changesets.length;

        progressMonitor.setWork(numberOfChangesetToDownload);

        for (int i = numberOfChangesetToDownload; i > 0; i--) {
            CreateCommitForChangesetVersionSpecTask commitTask = new CreateCommitForChangesetVersionSpecTask(
                    repository, vcClient, changesets[i - 1], previousChangesetItems, lastCommitID, witClient);

            TaskStatus commitStatus = new TaskExecutor(progressMonitor.newSubTask(1)).execute(commitTask);

            if (!commitStatus.isOK()) {
                return commitStatus;
            }

            lastCommitID = commitTask.getCommitID();
            lastTreeID = commitTask.getCommitTreeID();
            previousChangesetItems = commitTask.getCommittedItems();

            Check.notNull(lastCommitID, "lastCommitID"); //$NON-NLS-1$
            Check.notNull(lastTreeID, "lastTreeID"); //$NON-NLS-1$

            new ChangesetCommitMap(repository).setChangesetCommit(changesets[i - 1].getChangesetID(),
                    commitTask.getCommitID());

            progressMonitor.displayVerbose(Messages.formatString("CloneTask.ClonedFormat", //$NON-NLS-1$
                    Integer.toString(changesets[i - 1].getChangesetID()),
                    ObjectIdUtil.abbreviate(repository, lastCommitID)));
        }

        progressMonitor.setDetail(Messages.getString("CloneTask.Finalizing")); //$NON-NLS-1$

        /* Update master head reference */
        RefUpdate ref = repository.updateRef(Constants.R_HEADS + Constants.MASTER);
        ref.setNewObjectId(lastCommitID);
        ref.update();

        /* Create tfs branch */
        TfsBranchUtil.create(repository, Constants.R_HEADS + Constants.MASTER);

        /*
         * Check out the cloned commit.
         */
        if (!bare) {
            DirCache dirCache = repository.lockDirCache();
            DirCacheCheckout checkout = new DirCacheCheckout(repository, dirCache, lastTreeID);
            checkout.checkout();
            dirCache.unlock();

            RepositoryUtil.fixFileAttributes(repository);
        }

        progressMonitor.endTask();

        final int finalChangesetID = changesets[0].getChangesetID();

        if (numberOfChangesetToDownload == 1) {
            progressMonitor.displayMessage(Messages.formatString("CloneTask.ClonedFormat", //$NON-NLS-1$
                    Integer.toString(finalChangesetID), ObjectIdUtil.abbreviate(repository, lastCommitID)));
        } else {
            progressMonitor.displayMessage(Messages.formatString("CloneTask.ClonedMultipleFormat", //$NON-NLS-1$
                    changesets.length, Integer.toString(finalChangesetID),
                    ObjectIdUtil.abbreviate(repository, lastCommitID)));
        }
    } else {
        // the folder exists on the server but is empty

        progressMonitor.displayMessage(Messages.getString("CloneTask.NothingToDownload")); //$NON-NLS-1$

        progressMonitor.displayMessage(Messages.formatString("CloneTask.ClonedFolderEmptyFormat", //$NON-NLS-1$
                tfsPath));
    }

    log.info("Clone task completed."); //$NON-NLS-1$

    return TaskStatus.OK_STATUS;
}

From source file:com.microsoft.gittf.core.util.CommitUtil.java

License:Open Source License

/**
 * Returns the commit id referenced by refs/heads/master
 * //  w w w. j a  va 2s  . co m
 * @param repository
 *        the git repository
 * @return
 * @throws Exception
 */
public static ObjectId getMasterHeadCommitID(final Repository repository) throws Exception {
    return getCommitId(repository, Constants.R_HEADS + Constants.MASTER);
}

From source file:com.microsoft.gittf.core.util.TfsBranchUtil.java

License:Open Source License

/**
 * Updates the remote tracking branch and branch to point at the commit
 * specified.//from www.  ja  va  2  s  .c om
 * 
 * @param repository
 * @param commitId
 * @throws IOException
 * @throws RefAlreadyExistsException
 * @throws RefNotFoundException
 * @throws InvalidRefNameException
 * @throws GitAPIException
 */
public static void update(Repository repository, ObjectId commitId) throws IOException,
        RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, GitAPIException {
    if (repository.isBare()) {
        Ref tfsBranchRef = repository.getRef(Constants.R_HEADS + GitTFConstants.GIT_TF_BRANCHNAME);
        if (tfsBranchRef == null) {
            create(repository);
        }

        RefUpdate ref = repository.updateRef(Constants.R_HEADS + GitTFConstants.GIT_TF_BRANCHNAME);
        ref.setNewObjectId(commitId);
        ref.setForceUpdate(true);
        ref.update();
    }

    TfsRemoteReferenceUpdate remoteRefUpdate = new TfsRemoteReferenceUpdate(repository, commitId.name());
    remoteRefUpdate.update();

}

From source file:com.microsoft.tfs.client.common.ui.teambuild.egit.repositories.GitBranch.java

License:Open Source License

public GitBranch(final VersionControlClient vcClient, final GitRepository repository, final String objectId,
        final String localFullName, final String remoteFullName) {
    this.vcClient = vcClient;
    this.repository = repository;
    this.localFullName = localFullName;
    this.remoteFullName = remoteFullName;
    this.localName = StringUtil.isNullOrEmpty(localFullName) ? null
            : localFullName.startsWith(Constants.R_HEADS) ? localFullName.substring(Constants.R_HEADS.length())
                    : localFullName;//from  w w  w .j a v  a 2  s.c o  m
    this.remoteName = StringUtil.isNullOrEmpty(remoteFullName) ? null
            : remoteFullName.startsWith(Constants.R_HEADS)
                    ? remoteFullName.substring(Constants.R_HEADS.length())
                    : remoteFullName;
}

From source file:com.microsoft.tfs.client.common.ui.teambuild.egit.repositories.GitRepositoriesMap.java

License:Open Source License

private Map<String, String> getMappedBranches(final TfsGitRepositoryJson serverRepository,
        final Repository localRepository) {
    Map<String, String> mappedBranches = null;
    String upstreamURL = serverRepository.getRemoteUrl();
    try {//from  w  w  w  .j  a va 2  s .c o m
        upstreamURL = URIUtil.encodePath(serverRepository.getRemoteUrl());
    } catch (final URIException e) {
        log.error("Error encoding repository URL " + upstreamURL, e); //$NON-NLS-1$
    }

    final StoredConfig repositoryConfig = localRepository.getConfig();
    final Set<String> remotes = repositoryConfig.getSubsections(REMOTES_SECTION_NAME);

    for (final String remoteName : remotes) {
        final String remoteURL = repositoryConfig.getString(REMOTES_SECTION_NAME, remoteName, URL_VALUE_NAME);

        if (remoteURL != null && remoteURL.equalsIgnoreCase(upstreamURL)) {
            if (mappedBranches == null) {
                mappedBranches = new HashMap<String, String>();
            }

            final Set<String> branches = repositoryConfig.getSubsections(BRANCHES_SECTION_NAME);

            for (final String branch : branches) {
                final String fullBranchName = Constants.R_HEADS + branch;

                final String[] remoteNames = repositoryConfig.getStringList(BRANCHES_SECTION_NAME, branch,
                        REMOTE_VALUE_NAME);
                final String[] mappedBrancheNames = repositoryConfig.getStringList(BRANCHES_SECTION_NAME,
                        branch, MERGE_VALUE_NAME);

                for (int k = 0; k < remoteNames.length; k++) {
                    if (remoteNames[k].equals(remoteName)) {
                        final String remoteBranchName = mappedBrancheNames[k];

                        if (!mappedBranches.containsKey(remoteBranchName)) {
                            mappedBranches.put(remoteBranchName, fullBranchName);
                        }

                        break;
                    }
                }
            }

            break;
        }
    }

    return mappedBranches;
}

From source file:com.mooregreatsoftware.gitprocess.lib.config.StoredBranchConfig.java

License:Apache License

@Override
public BranchConfig setUpstream(Branch branch, Branch upstream) {
    final String branchShortName = branch.shortName();

    Optional<String> remoteName = upstream.remoteName();
    if (remoteName.isPresent()) {
        String upstreamBranchName = upstream.shortName();
        setString(CONFIG_BRANCH_SECTION, branchShortName, CONFIG_KEY_REMOTE, remoteName.get());
        final String upstreamNameWithoutRemote = upstreamBranchName.substring(remoteName.get().length() + 1);
        setString(CONFIG_BRANCH_SECTION, branchShortName, CONFIG_KEY_MERGE,
                Constants.R_HEADS + upstreamNameWithoutRemote);
        LOG.info("Setting upstream for \"{}\" to remote \"{}\" on \"{}\"", branch.shortName(),
                upstreamNameWithoutRemote, remoteName.get());
    } else {/*from   w  w w. j a va 2s.c o m*/
        setString(CONFIG_BRANCH_SECTION, branchShortName, CONFIG_KEY_REMOTE, ".");
        setString(CONFIG_BRANCH_SECTION, branchShortName, CONFIG_KEY_MERGE, upstream.shortName());
        LOG.info("Setting upstream for \"{}\" to local \"{}\"", branch.shortName(), upstream.shortName());
    }
    return this;
}