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:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java

License:Open Source License

private List<Ref> getBranches(Repository repo) throws IOException {
    List<Ref> ref = new ArrayList<Ref>();

    ref.addAll(repo.getRefDatabase().getRefs(Constants.R_HEADS).values());
    ref.addAll(repo.getRefDatabase().getRefs(Constants.R_REMOTES).values());

    return ref;/*from   w ww .  j  a  va  2s. co m*/
}

From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java

License:Open Source License

private String formatHeadRef(Ref ref) {
    String name = ref.getName();// w ww .  ja v  a  2  s .co m
    if (name.startsWith(Constants.R_HEADS)) {
        return name.substring(Constants.R_HEADS.length());
    } else if (name.startsWith(Constants.R_REMOTES)) {
        return name.substring(Constants.R_REMOTES.length());
    }
    return name;
}

From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java

License:Open Source License

private void setWalkStartPoints(RevWalk walk, Repository repo, AnyObjectId headId) throws IOException {
    markStartAllRefs(repo, walk, Constants.R_HEADS);
    markStartAllRefs(repo, walk, Constants.R_REMOTES);
    markStartAllRefs(repo, walk, Constants.R_TAGS);

    markStartAdditionalRefs(repo, walk);
    markUninteresting(repo, walk, Constants.R_NOTES);

    walk.markStart(walk.parseCommit(headId));
}

From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java

License:Open Source License

private void configObjectInfo(CommunicationChannel channel, HistoryViewInfoDto info) throws IOException {
    if (info.getIsResource()) {
        //         IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember((String) info.getSelectedObject());         
        //         RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
        //         
        //         if (mapping == null) {
        //            throw new IOException();
        //         }
        //         info.setResource1(resource);
        //         info.setRepository1(GitPlugin.getInstance().getGitUtils().getRepository(mapping));   
    } else {/* www. ja v  a 2s .c  o m*/
        Object node = GenericTreeStatefulService.getNodeByPathFor((List<PathFragment>) info.getSelectedObject(),
                null);
        GenericTreeStatefulService service = GenericTreeStatefulService
                .getServiceFromPathWithRoot((List<PathFragment>) info.getSelectedObject());
        NodeInfo nodeInfo = service.getVisibleNodes().get(node);
        Repository repository = GitService.getInstance().getRepository(nodeInfo);

        if (GitNodeType.NODE_TYPE_FILE.equals(nodeInfo.getPathFragment().getType())
                || GitNodeType.NODE_TYPE_WDIR.equals(nodeInfo.getPathFragment().getType())) {
            repository = GitPlugin.getInstance().getUtils().getRepository((File) node);
        } else if (node instanceof RefNode) {
            // create working directory for local branch
            File mainRepoFile = repository.getDirectory().getParentFile();
            String branchName = ((RefNode) node).getRef().getName().substring(Constants.R_HEADS.length());
            File wdirFile = new File(mainRepoFile.getParentFile(),
                    GitUtils.WORKING_DIRECTORY_PREFIX + branchName);
            repository = GitPlugin.getInstance().getUtils().getRepository(wdirFile);
        } else {
            throw new IOException();
        }
        if (repository == null) {
            throw new IOException();
        }

        info.setFile1(null);
        info.setRepository1(repository);
    }
}

From source file:org.flowerplatform.web.git.operation.internal.PullCommand.java

License:Open Source License

/**
 * Executes the {@code Pull} command with all the options and parameters
 * collected by the setter methods (e.g.
 * {@link #setProgressMonitor(ProgressMonitor)}) of this class. Each
 * instance of this class should only be used for one invocation of the
 * command. Don't call this method twice on an instance.
 *
 * @return the result of the pull/*from   w w  w  . ja  v a  2s. c  om*/
 * @throws WrongRepositoryStateException
 * @throws InvalidConfigurationException
 * @throws DetachedHeadException
 * @throws InvalidRemoteException
 * @throws CanceledException
 * @throws RefNotFoundException
 * @throws NoHeadException
 * @throws org.eclipse.jgit.api.errors.TransportException
 * @throws GitAPIException
 */
@SuppressWarnings("restriction")
public PullResult call() throws GitAPIException, WrongRepositoryStateException, InvalidConfigurationException,
        DetachedHeadException, InvalidRemoteException, CanceledException, RefNotFoundException, NoHeadException,
        org.eclipse.jgit.api.errors.TransportException {
    checkCallable();

    monitor.beginTask(JGitText.get().pullTaskName, 2);

    Object[] data = GitPlugin.getInstance().getUtils().getFetchPushUpstreamDataRefSpecAndRemote(repo);

    String fullBranch = (String) data[0];
    String branchName = fullBranch.substring(Constants.R_HEADS.length());

    if (!repo.getRepositoryState().equals(RepositoryState.SAFE))
        throw new WrongRepositoryStateException(MessageFormat.format(JGitText.get().cannotPullOnARepoWithState,
                repo.getRepositoryState().name()));

    // get the configured remote for the currently checked out branch
    // stored in configuration key branch.<branch name>.remote
    Config repoConfig = repo.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 = (String) data[1];

    // determines whether rebase should be used after fetching
    boolean doRebase = (boolean) data[3];

    final boolean isRemote = !remote.equals("."); //$NON-NLS-1$
    String remoteUri;
    FetchResult fetchRes;
    if (isRemote) {
        remoteUri = (String) data[2];

        if (monitor.isCancelled())
            throw new CanceledException(
                    MessageFormat.format(JGitText.get().operationCanceled, JGitText.get().pullTaskName));

        RefSpec refSpec = new RefSpec();
        refSpec = refSpec.setForceUpdate(true);
        refSpec = refSpec.setSourceDestination(remoteBranchName, fullBranch);

        FetchCommand fetch = new Git(repo).fetch().setRemote(remote).setRefSpecs(refSpec);

        fetch.setProgressMonitor(monitor);
        configure(fetch);

        fetchRes = fetch.call();
    } else {
        // we can skip the fetch altogether
        remoteUri = "local repository";
        fetchRes = null;
    }

    monitor.update(1);

    if (monitor.isCancelled())
        throw new CanceledException(
                MessageFormat.format(JGitText.get().operationCanceled, JGitText.get().pullTaskName));

    // we check the updates to see which of the updated branches
    // corresponds
    // to the remote branch name
    AnyObjectId commitToMerge;
    if (isRemote) {
        Ref r = null;
        if (fetchRes != null) {
            r = fetchRes.getAdvertisedRef(remoteBranchName);
            if (r == null)
                r = fetchRes.getAdvertisedRef(Constants.R_HEADS + remoteBranchName);
        }
        if (r == null)
            throw new JGitInternalException(
                    MessageFormat.format(JGitText.get().couldNotGetAdvertisedRef, remoteBranchName));
        else
            commitToMerge = r.getObjectId();
    } else {
        try {
            commitToMerge = repo.resolve(remoteBranchName);
            if (commitToMerge == null)
                throw new RefNotFoundException(
                        MessageFormat.format(JGitText.get().refNotResolved, remoteBranchName));
        } catch (IOException e) {
            throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfPullCommand, e);
        }
    }

    String upstreamName = "branch \'" + Repository.shortenRefName(remoteBranchName) + "\' of " + remoteUri;

    PullResult result;
    if (doRebase) {
        RebaseCommand rebase = new Git(repo).rebase();
        RebaseResult rebaseRes = rebase.setUpstream(commitToMerge).setUpstreamName(upstreamName)
                .setProgressMonitor(monitor).setOperation(Operation.BEGIN).call();
        result = new PullResult(fetchRes, remote, rebaseRes);
    } else {
        MergeCommand merge = new Git(repo).merge();
        merge.include(upstreamName, commitToMerge);
        MergeResult mergeRes = merge.call();
        monitor.update(1);
        result = new PullResult(fetchRes, remote, mergeRes);
    }
    monitor.endTask();
    return result;
}

From source file:org.gitective.tests.RepositoryUtilsTest.java

License:Open Source License

/**
 * Get branches for repository/*from   ww  w  .j  av  a2s  .c  o  m*/
 *
 * @throws Exception
 */
@Test
public void branchesForRepository() throws Exception {
    add("test.txt", "content");
    Collection<String> branches = RepositoryUtils.getBranches(new FileRepository(testRepo));
    assertNotNull(branches);
    assertFalse(branches.isEmpty());
    assertEquals(Constants.R_HEADS + Constants.MASTER, branches.iterator().next());
}

From source file:org.jboss.forge.git.Clone.java

License:Eclipse Distribution License

private void saveRemote(final URIish uri) throws URISyntaxException, IOException {
    final FileBasedConfig dstcfg = db.getConfig();
    final RemoteConfig rc = new RemoteConfig(dstcfg, remoteName);
    rc.addURI(uri);/*w ww. jav a  2s. co m*/
    rc.addFetchRefSpec(new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + "*",
            Constants.R_REMOTES + remoteName + "/*"));
    rc.update(dstcfg);
    dstcfg.save();
}

From source file:org.jboss.tools.openshift.egit.internal.test.util.TestRepository.java

License:Open Source License

public TestRepository cloneRepository(File path)
        throws URISyntaxException, InvocationTargetException, InterruptedException, IOException {
    URIish uri = new URIish("file:///" + repository.getDirectory().toString());
    CloneOperation clop = new CloneOperation(uri, true, null, path, Constants.R_HEADS + Constants.MASTER,
            Constants.DEFAULT_REMOTE_NAME, 0);
    clop.run(null);//from  www .  j a v a  2  s. c om
    RepositoryCache repositoryCache = Activator.getDefault().getRepositoryCache();
    Repository clonedRepository = repositoryCache.lookupRepository(new File(path, Constants.DOT_GIT));
    return new TestRepository(clonedRepository);
}

From source file:org.jboss.tools.openshift.internal.ui.wizard.importapp.ImportProjectOperation.java

License:Open Source License

/**
 * Fetches and creates the branch with the given name from the given remote.
 * @param gitRef/*from ww  w .  j  ava 2 s  . c o m*/
 * @param project
 * @param repository
 * @param monitor
 * @throws CoreException
 * @throws InvocationTargetException
 * @throws IOException
 */
private void fetchBranch(String gitRef, RemoteConfig remote, Repository repository, IProgressMonitor monitor)
        throws CoreException, InvocationTargetException, IOException {
    if (remote == null) {
        throw new CoreException(StatusFactory.errorStatus(OpenShiftUIActivator.PLUGIN_ID, NLS.bind(
                "Could not fetch determine the remote for the repo at {0} that we should fetch branch {1} from.",
                repository.getDirectory(), gitRef)));
    }
    EGitUtils.fetch(remote,
            Arrays.asList(new RefSpec(
                    Constants.R_HEADS + gitRef + ":" + Constants.R_REMOTES + remote.getName() + "/" + gitRef)),
            repository, monitor);
    RevCommit commit = EGitUtils.getLatestCommit(gitRef, remote.getName(), repository);
    EGitUtils.createBranch(gitRef, commit, repository, monitor);
}

From source file:org.jenkinsci.git.FetchOperationTest.java

License:Open Source License

/**
 * Test fetching single commit// ww  w  .  ja  v  a 2s. com
 *
 * @throws Exception
 */
@Test
public void fetchSingleCommit() throws Exception {
    git.add("file.txt", "a");
    File dir = git.tempDirectory();
    BuildRepository repo = new BuildRepository(git.repo().getDirectory().toURI().toString(),
            Constants.R_HEADS + Constants.MASTER, null);
    CloneOperation clone = new CloneOperation(repo);
    Repository cloned = clone.invoke(dir, null);
    assertNotNull(cloned);
    RevCommit commit2 = git.add("file1.txt", "b");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StreamProgressMonitor monitor = new StreamProgressMonitor(new PrintStream(out));
    FetchOperation fetch = new FetchOperation(repo, cloned, monitor);
    RevCommit fetched = fetch.call();
    assertEquals(commit2, fetched);
    assertTrue(out.toString().length() > 0);
}