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

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

Introduction

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

Prototype

String DEFAULT_REMOTE_NAME

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

Click Source Link

Document

Default remote name used by clone, push and fetch operations

Usage

From source file:org.eclipse.egit.ui.internal.fetch.SimpleConfigureFetchDialog.java

License:Open Source License

/**
 * @param repository/*from  w w w.java  2  s.  co  m*/
 * @return the configured remote for the current branch, or the default
 *         remote; <code>null</code> if a local branch is checked out that
 *         points to "." as remote
 */
public static RemoteConfig getConfiguredRemote(Repository repository) {
    String branch;
    try {
        branch = repository.getBranch();
    } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, true);
        return null;
    }
    if (branch == null)
        return null;

    String remoteName;
    if (ObjectId.isId(branch))
        remoteName = Constants.DEFAULT_REMOTE_NAME;
    else
        remoteName = repository.getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch,
                ConfigConstants.CONFIG_REMOTE_SECTION);

    // check if we find the configured and default Remotes
    List<RemoteConfig> allRemotes;
    try {
        allRemotes = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
    } catch (URISyntaxException e) {
        allRemotes = new ArrayList<RemoteConfig>();
    }

    RemoteConfig defaultConfig = null;
    RemoteConfig configuredConfig = null;
    for (RemoteConfig config : allRemotes) {
        if (config.getName().equals(Constants.DEFAULT_REMOTE_NAME))
            defaultConfig = config;
        if (remoteName != null && config.getName().equals(remoteName))
            configuredConfig = config;
    }

    RemoteConfig configToUse = configuredConfig != null ? configuredConfig : defaultConfig;
    return configToUse;
}

From source file:org.eclipse.egit.ui.internal.fetch.SimpleConfigureFetchDialog.java

License:Open Source License

/**
 * Add a warning about this remote being used by other branches
 *
 * @param parent/*from  w w  w.  j  ava 2s .co  m*/
 */
private void addDefaultOriginWarningIfNeeded(Composite parent) {
    if (!showBranchInfo)
        return;
    List<String> otherBranches = new ArrayList<String>();
    String currentBranch;
    try {
        currentBranch = repository.getBranch();
    } catch (IOException e) {
        // just don't show this warning
        return;
    }
    String currentRemote = config.getName();
    Config repositoryConfig = repository.getConfig();
    Set<String> branches = repositoryConfig.getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION);
    for (String branch : branches) {
        if (branch.equals(currentBranch))
            continue;
        String remote = repositoryConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch,
                ConfigConstants.CONFIG_KEY_REMOTE);
        if ((remote == null && currentRemote.equals(Constants.DEFAULT_REMOTE_NAME))
                || (remote != null && remote.equals(currentRemote)))
            otherBranches.add(branch);
    }
    if (otherBranches.isEmpty())
        return;

    Composite warningAboutOrigin = new Composite(parent, SWT.NONE);
    warningAboutOrigin.setLayout(new GridLayout(2, false));
    Label warningLabel = new Label(warningAboutOrigin, SWT.NONE);
    warningLabel
            .setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    Text warningText = new Text(warningAboutOrigin, SWT.READ_ONLY);
    warningText.setText(NLS.bind(UIText.SimpleConfigureFetchDialog_ReusedRemoteWarning, config.getName(),
            Integer.valueOf(otherBranches.size())));
    warningText.setToolTipText(otherBranches.toString());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(warningLabel);
}

From source file:org.eclipse.egit.ui.internal.pull.PullWizardPage.java

License:Open Source License

private void setDefaultUpstreamConfig() {
    String branchName = Repository.shortenRefName(this.fullBranch);
    BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName);
    boolean alreadyConfigured = branchConfig.getMerge() != null;
    BranchRebaseMode config;/* w  w  w.j a v  a  2s . c  o  m*/
    if (alreadyConfigured) {
        config = PullCommand.getRebaseMode(branchName, repository.getConfig());
    } else {
        config = CreateLocalBranchOperation.getDefaultUpstreamConfig(repository,
                Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + branchName); //$NON-NLS-1$
    }
    this.upstreamConfig = config;
}

From source file:org.eclipse.egit.ui.internal.push.AddRemotePage.java

License:Open Source License

@Override
protected void createRemoteNamePanel(Composite panel) {
    Composite remoteNamePanel = new Composite(panel, SWT.NONE);
    remoteNamePanel.setLayout(new GridLayout(2, false));
    GridDataFactory.fillDefaults().grab(true, false).applyTo(remoteNamePanel);

    Label remoteNameLabel = new Label(remoteNamePanel, SWT.NONE);
    remoteNameLabel.setText(UIText.AddRemotePage_RemoteNameLabel);

    remoteNameText = new Text(remoteNamePanel, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(remoteNameText);
    if (!getExistingRemotes().contains(Constants.DEFAULT_REMOTE_NAME)) {
        remoteNameText.setText(Constants.DEFAULT_REMOTE_NAME);
        remoteNameText.setSelection(remoteNameText.getText().length());
    } else//from w  w w .j a va2 s  . c om
        setMessage(UIText.AddRemotePage_EnterRemoteNameMessage);

    remoteNameText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchPage.java

License:Open Source License

private void setDefaultUpstreamConfig() {
    if (this.ref != null) {
        String branchName = Repository.shortenRefName(ref.getName());
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName);
        boolean alreadyConfigured = branchConfig.getMerge() != null;
        BranchRebaseMode config;/*from   ww w .  j a v  a 2  s .com*/
        if (alreadyConfigured) {
            config = PullCommand.getRebaseMode(branchName, repository.getConfig());
        } else {
            config = CreateLocalBranchOperation.getDefaultUpstreamConfig(repository,
                    Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + branchName); //$NON-NLS-1$
        }
        this.upstreamConfig = config;
        this.upstreamConfigComponent.setUpstreamConfig(this.upstreamConfig);
    }
}

From source file:org.eclipse.egit.ui.internal.push.SimpleConfigurePushDialog.java

License:Open Source License

/**
 * Add a warning about this remote being used by other branches
 *
 * @param parent/*from w w w  .  j  a  va 2  s . c  om*/
 */
private void addDefaultOriginWarningIfNeeded(Composite parent) {
    if (!showBranchInfo)
        return;
    List<String> otherBranches = new ArrayList<String>();
    String currentBranch;
    try {
        currentBranch = repository.getBranch();
    } catch (IOException e) {
        // just don't show this warning
        return;
    }
    String currentRemote = config.getName();
    Config repositoryConfig = repository.getConfig();
    Set<String> branches = repositoryConfig.getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION);
    for (String branch : branches) {
        if (branch.equals(currentBranch))
            continue;
        String remote = repositoryConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch,
                ConfigConstants.CONFIG_KEY_REMOTE);
        if ((remote == null && currentRemote.equals(Constants.DEFAULT_REMOTE_NAME))
                || (remote != null && remote.equals(currentRemote)))
            otherBranches.add(branch);
    }
    if (otherBranches.isEmpty())
        return;

    Composite warningAboutOrigin = new Composite(parent, SWT.NONE);
    warningAboutOrigin.setLayout(new GridLayout(2, false));
    Label warningLabel = new Label(warningAboutOrigin, SWT.NONE);
    warningLabel
            .setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    Text warningText = new Text(warningAboutOrigin, SWT.READ_ONLY);
    warningText.setText(NLS.bind(UIText.SimpleConfigurePushDialog_ReusedOriginWarning, config.getName(),
            Integer.valueOf(otherBranches.size())));
    warningText.setToolTipText(otherBranches.toString());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(warningLabel);
}

From source file:org.eclipse.egit.ui.submodule.SubmoduleSyncTest.java

License:Open Source License

@Test
public void syncSubmodule() throws Exception {
    deleteAllProjects();/* w w  w .jav  a  2 s. co  m*/
    assertProjectExistence(PROJ1, false);
    clearView();
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryFile);
    shareProjects(repositoryFile);
    assertProjectExistence(PROJ1, true);
    refreshAndWait();
    assertHasRepo(repositoryFile);
    FileRepository repo = lookupRepository(repositoryFile);

    SubmoduleAddCommand command = new SubmoduleAddCommand(repo);
    String path = "sub";
    command.setPath(path);
    String uri = new URIish(repo.getDirectory().toURI().toString()).toString();
    command.setURI(uri);
    Repository subRepo = command.call();
    assertNotNull(subRepo);

    String newUri = "git://server/repo.git";
    File modulesFile = new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES);
    FileBasedConfig config = new FileBasedConfig(modulesFile, repo.getFS());
    config.load();
    config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL, newUri);
    config.save();

    assertEquals(uri, repo.getConfig().getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
            ConfigConstants.CONFIG_KEY_URL));
    assertEquals(uri, subRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION,
            Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));

    refreshAndWait();
    SWTBotTree tree = getOrOpenView().bot().tree();
    tree.getAllItems()[0].expand().expandNode(UIText.RepositoriesViewLabelProvider_SubmodulesNodeText).select();
    ContextMenuHelper.clickContextMenuSync(tree,
            myUtil.getPluginLocalizedValue(SYNC_SUBMODULE_CONTEXT_MENU_LABEL));
    TestUtil.joinJobs(JobFamilies.SUBMODULE_SYNC);
    refreshAndWait();

    assertEquals(newUri, repo.getConfig().getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
            ConfigConstants.CONFIG_KEY_URL));
    assertEquals(newUri, subRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION,
            Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));
}

From source file:org.eclipse.egit.ui.wizards.clone.GitCloneWizardTestBase.java

License:Open Source License

protected void cloneRepo(File destRepo, RepoRemoteBranchesPage remoteBranches) throws Exception {
    remoteBranches.assertRemoteBranches(SampleTestRepository.FIX, Constants.MASTER);
    remoteBranches.selectBranches(SampleTestRepository.FIX, Constants.MASTER);

    WorkingCopyPage workingCopy = remoteBranches.nextToWorkingCopy();
    workingCopy.setDirectory(destRepo.toString());

    workingCopy.assertDirectory(destRepo.toString());
    workingCopy.assertBranch(Constants.MASTER);
    workingCopy.assertRemoteName(Constants.DEFAULT_REMOTE_NAME);
    workingCopy.waitForCreate();/*  w w  w  .jav a2 s. c  om*/

    // Some random sampling to see we got something. We do not test
    // the integrity of the repository here. Only a few basic properties
    // we'd expect from a clone made this way, that would possibly
    // not hold true given other parameters in the GUI.
    Repository repository = new FileRepository(new File(destRepo, Constants.DOT_GIT));
    // we always have an origin/master
    assertNotNull(repository.resolve("origin/master"));
    // and a local master initialized from origin/master (default!)
    assertEquals(repository.resolve("master"), repository.resolve("origin/master"));
    // A well known tag
    assertNotNull(repository.resolve(Constants.R_TAGS + SampleTestRepository.v1_0_name).name());
    // lots of refs
    int refs = repository.getAllRefs().size();
    assertTrue(refs >= 4);
    // and a known file in the working dir
    assertTrue(new File(destRepo, SampleTestRepository.A_txt_name).exists());
    DirCacheEntry fileEntry = null;
    DirCache dc = repository.lockDirCache();
    fileEntry = dc.getEntry(SampleTestRepository.A_txt_name);
    dc.unlock();
    // check that we have the file in the index
    assertNotNull(fileEntry);
    // No project has been imported
    assertEquals(0, ResourcesPlugin.getWorkspace().getRoot().getProjects().length);
}

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

License:Open Source License

/**
 * Get Git repository for pull request//  w  w w .  j a  va  2 s .c  o  m
 *
 * @param request
 * @return repository or null if none found
 */
public static Repository getRepository(PullRequest request) {
    org.eclipse.egit.github.core.Repository remoteRepo = request.getBase().getRepo();
    String id = remoteRepo.getOwner().getLogin() + '/' + remoteRepo.getName() + Constants.DOT_GIT;
    RepositoryCache cache = Activator.getDefault().getRepositoryCache();
    for (String path : Activator.getDefault().getRepositoryUtil().getConfiguredRepositories())
        try {
            Repository repo = cache.lookupRepository(new File(path));
            RemoteConfig rc = new RemoteConfig(repo.getConfig(), Constants.DEFAULT_REMOTE_NAME);
            for (URIish uri : rc.getURIs())
                if (uri.toString().endsWith(id))
                    return repo;
        } catch (IOException e) {
            GitHub.logError(e);
            continue;
        } catch (URISyntaxException e) {
            GitHub.logError(e);
            continue;
        }
    return null;
}

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

License:Open Source License

/**
 * Get remote for given pull request//from ww w.  j  a va2  s . c  o m
 *
 * @param repo
 * @param request
 * @return remote config
 * @throws URISyntaxException
 */
public static RemoteConfig getRemote(Repository repo, PullRequest request) throws URISyntaxException {
    if (isFromSameRepository(request))
        return getRemoteConfig(repo, Constants.DEFAULT_REMOTE_NAME);
    else
        return getRemoteConfig(repo, getOwner(request.getHead()));
}