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:com.barchart.jenkins.cascade.PluginScmGit.java

License:BSD License

/**
 * Local remote tracking branch reference.
 * <p>/*w w  w  .j a  va 2 s .c  om*/
 * Example: refs/remotes/origin/master
 */
public static String refRemotes(final String remoteName, final String remoteBranchName) {
    return Constants.R_REMOTES + remote(remoteName, remoteBranchName);
}

From source file:com.denimgroup.threadfix.service.repository.GitServiceImpl.java

License:Mozilla Public License

@Override
public File cloneRepoToDirectory(Application application, File dirLocation) {

    if (dirLocation.exists()) {
        File gitDirectoryFile = new File(dirLocation.getAbsolutePath() + File.separator + ".git");

        try {/* w  w  w .  j a v  a2  s. c  o m*/
            if (!gitDirectoryFile.exists()) {
                Git newRepo = clone(application, dirLocation);
                if (newRepo != null)
                    return newRepo.getRepository().getWorkTree();
            } else {
                Repository localRepo = new FileRepository(gitDirectoryFile);
                Git git = new Git(localRepo);

                if (application.getRepositoryRevision() != null
                        && !application.getRepositoryRevision().isEmpty()) {
                    //remote checkout
                    git.checkout().setCreateBranch(true).setStartPoint(application.getRepositoryRevision())
                            .setName(application.getRepositoryRevision()).call();
                } else {

                    List<Ref> refs = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call();

                    String repoBranch = (application.getRepositoryBranch() != null
                            && !application.getRepositoryBranch().isEmpty()) ? application.getRepositoryBranch()
                                    : "master";

                    boolean localCheckout = false;

                    for (Ref ref : refs) {
                        String refName = ref.getName();
                        if (refName.contains(repoBranch) && !refName.contains(Constants.R_REMOTES)) {
                            localCheckout = true;
                        }
                    }

                    String HEAD = localRepo.getFullBranch();

                    if (HEAD.contains(repoBranch)) {
                        git.pull().setRemote("origin").setRemoteBranchName(repoBranch)
                                .setCredentialsProvider(getApplicationCredentials(application)).call();
                    } else {
                        if (localCheckout) {
                            //local checkout
                            git.checkout().setName(application.getRepositoryBranch()).call();
                            git.pull().setRemote("origin").setRemoteBranchName(repoBranch)
                                    .setCredentialsProvider(getApplicationCredentials(application)).call();
                        } else {
                            //remote checkout
                            git.checkout().setCreateBranch(true).setName(repoBranch)
                                    .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
                                    .setStartPoint("origin/" + repoBranch).call();
                        }
                    }
                }

                return git.getRepository().getWorkTree();
            }
        } catch (JGitInternalException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (IOException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (WrongRepositoryStateException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (InvalidConfigurationException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (DetachedHeadException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (InvalidRemoteException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (CanceledException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (RefNotFoundException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (NoHeadException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (RefAlreadyExistsException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (CheckoutConflictException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (InvalidRefNameException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (TransportException e) {
            log.error(EXCEPTION_MESSAGE, e);
        } catch (GitAPIException e) {
            log.error(EXCEPTION_MESSAGE, e);
        }
    } else {
        try {
            log.info("Attempting to clone application from repository.");
            Git result = clone(application, dirLocation);
            if (result != null) {
                log.info("Application was successfully cloned from repository.");
                return result.getRepository().getWorkTree();
            }
            log.error(EXCEPTION_MESSAGE);
        } catch (JGitInternalException e) {
            log.error(EXCEPTION_MESSAGE, e);
        }
    }
    return null;
}

From source file:com.genuitec.org.eclipse.egit.ui.internal.branch.BranchOperationUI.java

License:Open Source License

private static boolean shouldShowCheckoutRemoteTrackingDialog(String refName) {
    boolean isRemoteTrackingBranch = refName != null && refName.startsWith(Constants.R_REMOTES);
    if (isRemoteTrackingBranch) {
        boolean showDetachedHeadWarning = Activator.getDefault().getPreferenceStore()
                .getBoolean(UIPreferences.SHOW_DETACHED_HEAD_WARNING);
        // If the user has not yet chosen to ignore the warning about
        // getting into a "detached HEAD" state, then we show them a dialog
        // whether a remote-tracking branch should be checked out with a
        // detached HEAD or checking it out as a new local branch.
        return showDetachedHeadWarning;
    } else {/*from  w ww.ja  v a  2  s .  c o  m*/
        return false;
    }
}

From source file:com.gitblit.client.MessageRenderer.java

License:Apache License

private void showRef(String ref, JLabel label) {
    String name = ref;/*from  w  w w  .  j  a  v  a2s  .  c o  m*/
    Color bg = getBackground();
    Border border = null;
    if (name.startsWith(Constants.R_HEADS)) {
        // local branch
        bg = Color.decode("#CCFFCC");
        name = name.substring(Constants.R_HEADS.length());
        border = new LineBorder(Color.decode("#00CC33"), 1);
    } else if (name.startsWith(Constants.R_REMOTES)) {
        // remote branch
        bg = Color.decode("#CAC2F5");
        name = name.substring(Constants.R_REMOTES.length());
        border = new LineBorder(Color.decode("#6C6CBF"), 1);
    } else if (name.startsWith(Constants.R_TAGS)) {
        // tag
        bg = Color.decode("#FFFFAA");
        name = name.substring(Constants.R_TAGS.length());
        border = new LineBorder(Color.decode("#FFCC00"), 1);
    } else if (name.equals(Constants.HEAD)) {
        // HEAD
        bg = Color.decode("#FFAAFF");
        border = new LineBorder(Color.decode("#FF00EE"), 1);
    } else {
    }
    label.setText(name);
    label.setBackground(bg);
    label.setBorder(border);
    label.setVisible(true);
}

From source file:com.gitblit.client.MessageRenderer.java

License:Apache License

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (isSelected)
        setBackground(table.getSelectionBackground());
    else/*from  ww  w  .  j  a v  a  2 s . co  m*/
        setBackground(table.getBackground());
    messageLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
    if (value == null) {
        return this;
    }
    FeedEntryModel entry = (FeedEntryModel) value;

    if (gitblit == null) {
        // no gitblit client, just display message
        messageLabel.setText(entry.title);
    } else {
        // show message in BOLD if its a new entry
        if (entry.published.after(gitblit.getLastFeedRefresh(entry.repository, entry.branch))) {
            messageLabel.setText("<html><body><b>" + entry.title);
        } else {
            messageLabel.setText(entry.title);
        }
    }

    // reset ref label
    resetRef(headLabel);
    resetRef(branchLabel);
    resetRef(remoteLabel);
    resetRef(tagLabel);

    int parentCount = 0;
    if (entry.tags != null) {
        for (String tag : entry.tags) {
            if (tag.startsWith("ref:")) {
                // strip ref:
                tag = tag.substring("ref:".length());
            } else {
                // count parents
                if (tag.startsWith("parent:")) {
                    parentCount++;
                }
            }
            if (tag.equals(entry.branch)) {
                // skip current branch label
                continue;
            }
            if (tag.startsWith(Constants.R_HEADS)) {
                // local branch
                showRef(tag, branchLabel);
            } else if (tag.startsWith(Constants.R_REMOTES)) {
                // remote branch
                showRef(tag, remoteLabel);
            } else if (tag.startsWith(Constants.R_TAGS)) {
                // tag
                showRef(tag, tagLabel);
            } else if (tag.equals(Constants.HEAD)) {
                // HEAD
                showRef(tag, headLabel);
            }
        }
    }

    if (parentCount > 1) {
        // multiple parents, show merge icon
        messageLabel.setIcon(mergeIcon);
    } else {
        messageLabel.setIcon(blankIcon);
    }
    return this;
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testBranches() throws Exception {
    Repository repository = GitBlitSuite.getJGitRepository();
    assertTrue(JGitUtils.getLocalBranches(repository, true, 0).size() == 0);
    for (RefModel model : JGitUtils.getLocalBranches(repository, true, -1)) {
        assertTrue(model.getName().startsWith(Constants.R_HEADS));
        assertTrue(model.equals(model));
        assertFalse(model.equals(""));
        assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode() + model.getName().hashCode());
        assertTrue(model.getShortMessage().equals(model.getShortMessage()));
    }//from ww w . j  av  a  2s  . co m
    for (RefModel model : JGitUtils.getRemoteBranches(repository, true, -1)) {
        assertTrue(model.getName().startsWith(Constants.R_REMOTES));
        assertTrue(model.equals(model));
        assertFalse(model.equals(""));
        assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode() + model.getName().hashCode());
        assertTrue(model.getShortMessage().equals(model.getShortMessage()));
    }
    assertTrue(JGitUtils.getRemoteBranches(repository, true, 8).size() == 8);
    repository.close();
}

From source file:com.gitblit.utils.JGitUtils.java

License:Apache License

/**
 * Returns all refs grouped by their associated object id.
 *
 * @param repository//from   w ww.j  ava  2s .c  o  m
 * @param includeRemoteRefs
 * @return all refs grouped by their referenced object id
 */
public static Map<ObjectId, List<RefModel>> getAllRefs(Repository repository, boolean includeRemoteRefs) {
    List<RefModel> list = getRefs(repository, org.eclipse.jgit.lib.RefDatabase.ALL, true, -1);
    Map<ObjectId, List<RefModel>> refs = new HashMap<ObjectId, List<RefModel>>();
    for (RefModel ref : list) {
        if (!includeRemoteRefs && ref.getName().startsWith(Constants.R_REMOTES)) {
            continue;
        }
        ObjectId objectid = ref.getReferencedObjectId();
        if (!refs.containsKey(objectid)) {
            refs.put(objectid, new ArrayList<RefModel>());
        }
        refs.get(objectid).add(ref);
    }
    return refs;
}

From source file:com.gitblit.utils.JGitUtils.java

License:Apache License

/**
 * Returns the list of remote branches in the repository. If repository does
 * not exist or is empty, an empty list is returned.
 *
 * @param repository/* ww w .  j av  a 2s . c o m*/
 * @param fullName
 *            if true, /refs/remotes/yadayadayada is returned. If false,
 *            yadayadayada is returned.
 * @param maxCount
 *            if < 0, all remote branches are returned
 * @return list of remote branches
 */
public static List<RefModel> getRemoteBranches(Repository repository, boolean fullName, int maxCount) {
    return getRefs(repository, Constants.R_REMOTES, fullName, maxCount);
}

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.rimerosolutions.ant.git.tasks.FetchTask.java

License:Apache License

@Override
public void doExecute() {
    try {//from ww w . ja v  a 2 s. c  om
        StoredConfig config = git.getRepository().getConfig();
        List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config);

        if (remoteConfigs.isEmpty()) {
            URIish uri = new URIish(getUri());

            RemoteConfig remoteConfig = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME);
            remoteConfig.addURI(uri);
            remoteConfig.addFetchRefSpec(new RefSpec("+" + Constants.R_HEADS + "*:" + Constants.R_REMOTES
                    + Constants.DEFAULT_REMOTE_NAME + "/*"));

            config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER,
                    ConfigConstants.CONFIG_KEY_REMOTE, Constants.DEFAULT_REMOTE_NAME);
            config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER,
                    ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + Constants.MASTER);

            remoteConfig.update(config);
            config.save();
        }

        List<RefSpec> specs = new ArrayList<RefSpec>(3);

        specs.add(new RefSpec(
                "+" + Constants.R_HEADS + "*:" + Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/*"));
        specs.add(new RefSpec("+" + Constants.R_NOTES + "*:" + Constants.R_NOTES + "*"));
        specs.add(new RefSpec("+" + Constants.R_TAGS + "*:" + Constants.R_TAGS + "*"));

        FetchCommand fetchCommand = git.fetch().setDryRun(dryRun).setThin(thinPack).setRemote(getUri())
                .setRefSpecs(specs).setRemoveDeletedRefs(removeDeletedRefs);

        setupCredentials(fetchCommand);

        if (getProgressMonitor() != null) {
            fetchCommand.setProgressMonitor(getProgressMonitor());
        }

        FetchResult fetchResult = fetchCommand.call();

        GitTaskUtils.validateTrackingRefUpdates(FETCH_FAILED_MESSAGE, fetchResult.getTrackingRefUpdates());

        log(fetchResult.getMessages());

    } catch (URISyntaxException e) {
        throw new GitBuildException("Invalid URI syntax: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new GitBuildException("Could not save or get repository configuration: " + e.getMessage(), e);
    } catch (InvalidRemoteException e) {
        throw new GitBuildException("Invalid remote URI: " + e.getMessage(), e);
    } catch (TransportException e) {
        throw new GitBuildException("Communication error: " + e.getMessage(), e);
    } catch (GitAPIException e) {
        throw new GitBuildException("Unexpected exception: " + e.getMessage(), e);
    }
}