Example usage for org.eclipse.jgit.lib Repository shortenRefName

List of usage examples for org.eclipse.jgit.lib Repository shortenRefName

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository shortenRefName.

Prototype

@NonNull
public static String shortenRefName(String refName) 

Source Link

Document

Get a shortened more user friendly ref name

Usage

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

License:Open Source License

private void setRemoteConfigs() {
    remoteSelectionCombo.setItems(remoteConfigs);
    if (this.head != null) {
        String branchName = Repository.shortenRefName(this.head.getName());
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName);
        String remoteName = branchConfig.getRemote();
        if (remoteName != null) {
            for (RemoteConfig rc : remoteConfigs) {
                if (remoteName.equals(rc.getName()))
                    remoteSelectionCombo.setSelectedRemote(rc);
            }/*  www  .  j  a v  a2 s . c o m*/
        }
    }

    remoteConfig = remoteSelectionCombo.getSelectedRemote();
    setRefAssist(remoteConfig);
}

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

License:Open Source License

private String getSuggestedBranchName() {
    if (fullBranch != null) {
        String branchName = Repository.shortenRefName(fullBranch);
        StoredConfig config = repository.getConfig();
        BranchConfig branchConfig = new BranchConfig(config, branchName);
        String merge = branchConfig.getMerge();
        if (!branchConfig.isRemoteLocal() && merge != null && merge.startsWith(Constants.R_HEADS)) {
            return Repository.shortenRefName(merge);
        }//w  ww  . j  av a2 s .  c o m
    }
    return ""; //$NON-NLS-1$
}

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

License:Open Source License

private boolean hasDifferentUpstreamConfiguration() {
    String branchName = Repository.shortenRefName(this.fullBranch);
    BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName);

    String remote = branchConfig.getRemote();
    // No upstream config -> don't show warning
    if (remote == null) {
        return false;
    }// w  w  w .  jav  a2  s  .c om
    if (!remote.equals(remoteConfig.getName())) {
        return true;
    }
    String merge = branchConfig.getMerge();
    if (merge == null || !merge.equals(getFullRemoteReference())) {
        return true;
    }
    if (branchConfig.getRebaseMode() != getUpstreamConfig()) {
        return true;
    }
    return false;
}

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;/*from   w  ww . j  av  a 2 s .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.PushBranchPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    try {// ww  w.j a  v a2s  . co m
        this.remoteConfigs = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
        Collections.sort(remoteConfigs, new Comparator<RemoteConfig>() {

            @Override
            public int compare(RemoteConfig first, RemoteConfig second) {
                return String.CASE_INSENSITIVE_ORDER.compare(first.getName(), second.getName());
            }
        });
    } catch (URISyntaxException e) {
        this.remoteConfigs = new ArrayList<>();
        handleError(e);
    }

    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(GridLayoutFactory.swtDefaults().create());

    Composite inputPanel = new Composite(main, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(inputPanel);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(inputPanel);

    Label sourceLabel = new Label(inputPanel, SWT.NONE);
    sourceLabel.setText(UIText.PushBranchPage_Source);

    Composite sourceComposite = new Composite(inputPanel, SWT.NONE);
    sourceComposite
            .setLayoutData(GridDataFactory.fillDefaults().indent(UIUtils.getControlIndent(), 0).create());
    RowLayout rowLayout = RowLayoutFactory.fillDefaults().create();
    rowLayout.center = true;
    sourceComposite.setLayout(rowLayout);

    if (this.ref != null) {
        Image branchIcon = UIIcons.BRANCH.createImage();
        this.disposables.add(branchIcon);

        Label branchIconLabel = new Label(sourceComposite, SWT.NONE);
        branchIconLabel.setLayoutData(new RowData(branchIcon.getBounds().width, branchIcon.getBounds().height));
        branchIconLabel.setImage(branchIcon);
        Label localBranchLabel = new Label(sourceComposite, SWT.NONE);
        localBranchLabel.setText(Repository.shortenRefName(this.ref.getName()));

        Label spacer = new Label(sourceComposite, SWT.NONE);
        spacer.setLayoutData(new RowData(3, SWT.DEFAULT));
    }

    Image commitIcon = UIIcons.CHANGESET.createImage();
    this.disposables.add(commitIcon);
    Label commitIconLabel = new Label(sourceComposite, SWT.NONE);
    commitIconLabel.setImage(commitIcon);
    commitIconLabel.setLayoutData(new RowData(commitIcon.getBounds().width, commitIcon.getBounds().height));

    Label commit = new Label(sourceComposite, SWT.NONE);
    StringBuilder commitBuilder = new StringBuilder(this.commitToPush.abbreviate(7).name());
    StringBuilder commitTooltipBuilder = new StringBuilder(this.commitToPush.getName());
    try (RevWalk revWalk = new RevWalk(repository)) {
        RevCommit revCommit = revWalk.parseCommit(this.commitToPush);
        commitBuilder.append("  "); //$NON-NLS-1$
        commitBuilder.append(Utils.shortenText(revCommit.getShortMessage(), MAX_SHORTCOMMIT_MESSAGE_LENGTH));
        commitTooltipBuilder.append("\n\n"); //$NON-NLS-1$
        commitTooltipBuilder.append(revCommit.getFullMessage());
    } catch (IOException ex) {
        commitBuilder.append(UIText.PushBranchPage_CannotAccessCommitDescription);
        commitTooltipBuilder.append(ex.getMessage());
        Activator.handleError(ex.getLocalizedMessage(), ex, false);
    }
    commit.setText(commitBuilder.toString());
    commit.setToolTipText(commitTooltipBuilder.toString());

    Label destinationLabel = new Label(inputPanel, SWT.NONE);
    destinationLabel.setText(UIText.PushBranchPage_Destination);
    GridDataFactory.fillDefaults().applyTo(destinationLabel);

    Composite remoteGroup = new Composite(inputPanel, SWT.NONE);
    remoteGroup.setLayoutData(GridDataFactory.fillDefaults().indent(UIUtils.getControlIndent(), 0).create());
    remoteGroup.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).create());

    Label remoteLabel = new Label(remoteGroup, SWT.NONE);
    remoteLabel.setText(UIText.PushBranchPage_RemoteLabel);

    // Use full width in case "New Remote..." button is not shown
    int remoteSelectionSpan = showNewRemoteButton ? 1 : 2;

    remoteSelectionCombo = new RemoteSelectionCombo(remoteGroup, SWT.NONE, SelectionType.PUSH);
    GridDataFactory.fillDefaults().grab(true, false).span(remoteSelectionSpan, 1).applyTo(remoteSelectionCombo);
    setRemoteConfigs();
    remoteSelectionCombo.addRemoteSelectionListener(new IRemoteSelectionListener() {
        @Override
        public void remoteSelected(RemoteConfig rc) {
            remoteConfig = rc;
            setRefAssist(rc);
            checkPage();
        }
    });

    if (showNewRemoteButton) {
        Button newRemoteButton = new Button(remoteGroup, SWT.PUSH);
        newRemoteButton.setText(UIText.PushBranchPage_NewRemoteButton);
        GridDataFactory.fillDefaults().applyTo(newRemoteButton);
        newRemoteButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                showNewRemoteDialog();
            }
        });
    }

    Label branchNameLabel = new Label(remoteGroup, SWT.NONE);
    branchNameLabel.setText(UIText.PushBranchPage_RemoteBranchNameLabel);

    remoteBranchNameText = new Text(remoteGroup, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(remoteBranchNameText);
    remoteBranchNameText.setText(getSuggestedBranchName());
    UIUtils.addRefContentProposalToText(remoteBranchNameText, this.repository, () -> {
        if (PushBranchPage.this.assist != null) {
            return PushBranchPage.this.assist.getRefsForContentAssist(false, true);
        }
        return Collections.emptyList();
    });

    if (this.ref != null) {
        upstreamConfigComponent = new UpstreamConfigComponent(inputPanel, SWT.NONE);
        upstreamConfigComponent.getContainer().setLayoutData(
                GridDataFactory.fillDefaults().grab(true, false).span(3, 1).indent(SWT.DEFAULT, 20).create());
        upstreamConfigComponent.addUpstreamConfigSelectionListener(new UpstreamConfigSelectionListener() {
            @Override
            public void upstreamConfigSelected(BranchRebaseMode newUpstreamConfig) {
                upstreamConfig = newUpstreamConfig;
                checkPage();
            }
        });
        setDefaultUpstreamConfig();
    }

    final Button forceUpdateButton = new Button(inputPanel, SWT.CHECK);
    forceUpdateButton.setText(UIText.PushBranchPage_ForceUpdateButton);
    forceUpdateButton.setSelection(false);
    forceUpdateButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(3, 1).create());
    forceUpdateButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            forceUpdateSelected = forceUpdateButton.getSelection();
        }
    });

    Link advancedDialogLink = new Link(main, SWT.NONE);
    advancedDialogLink.setText(UIText.PushBranchPage_advancedWizardLink);
    advancedDialogLink.setToolTipText(UIText.PushBranchPage_advancedWizardLinkTooltip);
    advancedDialogLink.setLayoutData(new GridData(SWT.END, SWT.END, false, true));
    advancedDialogLink.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            Shell parentShell = getShell().getParent().getShell();
            PushWizard advancedWizard = null;
            try {
                advancedWizard = new PushWizard(repository);
                getShell().close();
                new WizardDialog(parentShell, advancedWizard).open();
            } catch (URISyntaxException ex) {
                Activator.logError(ex.getMessage(), ex);
            }

        }
    });

    setControl(main);

    checkPage();

    // Add listener now to avoid setText above to already trigger it.
    remoteBranchNameText.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 setRemoteConfigs() {
    remoteSelectionCombo.setItems(remoteConfigs);
    if (this.ref != null) {
        String branchName = Repository.shortenRefName(this.ref.getName());
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName);
        String remoteName = branchConfig.getRemote();
        if (remoteName != null) {
            for (RemoteConfig rc : remoteConfigs) {
                if (remoteName.equals(rc.getName()))
                    remoteSelectionCombo.setSelectedRemote(rc);
            }//from  www  .  j  a v a2 s  .  c  om
        }
    }

    remoteConfig = remoteSelectionCombo.getSelectedRemote();
    setRefAssist(remoteConfig);
}

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;//w  w  w  . ja va  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;
        this.upstreamConfigComponent.setUpstreamConfig(this.upstreamConfig);
    }
}

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

License:Open Source License

private String getSuggestedBranchName() {
    if (ref != null && !ref.getName().startsWith(Constants.R_REMOTES)) {
        StoredConfig config = repository.getConfig();
        String branchName = Repository.shortenRefName(ref.getName());

        BranchConfig branchConfig = new BranchConfig(config, branchName);
        String merge = branchConfig.getMerge();
        if (!branchConfig.isRemoteLocal() && merge != null && merge.startsWith(Constants.R_HEADS))
            return Repository.shortenRefName(merge);

        return branchName;
    } else {//from  w  w  w  .  j  a va  2  s . co  m
        return ""; //$NON-NLS-1$
    }
}

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

License:Open Source License

private boolean hasDifferentUpstreamConfiguration() {
    String branchName = Repository.shortenRefName(ref.getName());
    BranchConfig branchConfig = new BranchConfig(repository.getConfig(), branchName);

    String remote = branchConfig.getRemote();
    // No upstream config -> don't show warning
    if (remote == null) {
        return false;
    }// www.j a v a 2 s.c  om
    if (!remote.equals(remoteConfig.getName())) {
        return true;
    }
    String merge = branchConfig.getMerge();
    if (merge == null || !merge.equals(getFullRemoteReference())) {
        return true;
    }
    if (branchConfig.getRebaseMode() != upstreamConfig) {
        return true;
    }
    return false;
}

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

License:Open Source License

@Override
public String getWindowTitle() {
    if (ref != null)
        return MessageFormat.format(UIText.PushBranchWizard_WindowTitle,
                Repository.shortenRefName(this.ref.getName()));
    else//from ww  w . j a v a 2s.  c om
        return UIText.PushCommitHandler_pushCommitTitle;
}