Search in sources :

Example 1 with UserConfig

use of org.eclipse.jgit.lib.UserConfig in project jbosstools-openshift by jbosstools.

the class EGitUtils method commit.

private static RevCommit commit(IProject project, String commitMessage, Repository repository, IProgressMonitor monitor) throws CoreException {
    Assert.isLegal(project != null, "Could not commit project. No project provided");
    Assert.isLegal(repository != null, MessageFormat.format("Could not commit. Project \"{0}\" is not connected to a repository (call #connect(project, repository) first)", project.getName()));
    /**
     * TODO: add capability to commit selectively
     */
    UserConfig userConfig = getUserConfig(repository);
    CommitOperation op = new CommitOperation(null, null, null, getFormattedUser(userConfig.getAuthorName(), userConfig.getAuthorEmail()), getFormattedUser(userConfig.getCommitterName(), userConfig.getCommitterEmail()), commitMessage);
    op.setCommitAll(true);
    op.setRepository(repository);
    op.execute(monitor);
    return op.getCommit();
}
Also used : CommitOperation(org.eclipse.egit.core.op.CommitOperation) UserConfig(org.eclipse.jgit.lib.UserConfig)

Example 2 with UserConfig

use of org.eclipse.jgit.lib.UserConfig in project maven-scm by apache.

the class JGitCheckInCommand method getCommitter.

private UserInfo getCommitter(ScmProviderRepository repo, Git git) {
    boolean forceMvnUser = git.getRepository().getConfig().getBoolean(GIT_MAVEN_SECTION, GIT_FORCE, false);
    // git config
    UserConfig user = git.getRepository().getConfig().get(UserConfig.KEY);
    String committerName = null;
    if (!forceMvnUser && !user.isCommitterNameImplicit()) {
        committerName = user.getCommitterName();
    }
    // mvn parameter
    if (StringUtils.isBlank(committerName)) {
        committerName = repo.getUser();
    }
    // git default
    if (StringUtils.isBlank(committerName)) {
        committerName = user.getCommitterName();
    }
    // git config
    String committerMail = null;
    if (!user.isCommitterEmailImplicit()) {
        committerMail = user.getCommitterEmail();
    }
    if (StringUtils.isBlank(committerMail)) {
        String defaultDomain = git.getRepository().getConfig().getString(GIT_MAVEN_SECTION, null, GIT_MAILDOMAIN);
        defaultDomain = StringUtils.isNotBlank(defaultDomain) ? defaultDomain : getHostname();
        // mvn parameter (constructed with username) or git default
        committerMail = StringUtils.isNotBlank(repo.getUser()) ? repo.getUser() + "@" + defaultDomain : user.getCommitterEmail();
    }
    return new UserInfo(committerName, committerMail);
}
Also used : UserConfig(org.eclipse.jgit.lib.UserConfig)

Example 3 with UserConfig

use of org.eclipse.jgit.lib.UserConfig in project maven-scm by apache.

the class JGitCheckInCommand method getAuthor.

private UserInfo getAuthor(ScmProviderRepository repo, Git git) {
    boolean forceMvnUser = git.getRepository().getConfig().getBoolean(GIT_MAVEN_SECTION, GIT_FORCE, false);
    // git config
    UserConfig user = git.getRepository().getConfig().get(UserConfig.KEY);
    String authorName = null;
    if (!forceMvnUser && !user.isAuthorNameImplicit()) {
        authorName = user.getAuthorName();
    }
    // mvn parameter
    if (StringUtils.isBlank(authorName)) {
        authorName = repo.getUser();
    }
    // git default
    if (StringUtils.isBlank(authorName)) {
        authorName = user.getAuthorName();
    }
    // git config
    String authorMail = null;
    if (!user.isAuthorEmailImplicit()) {
        authorMail = user.getAuthorEmail();
    }
    if (StringUtils.isBlank(authorMail)) {
        String defaultDomain = git.getRepository().getConfig().getString(GIT_MAVEN_SECTION, null, GIT_MAILDOMAIN);
        defaultDomain = StringUtils.isNotBlank(defaultDomain) ? defaultDomain : getHostname();
        // mvn parameter (constructed with username) or git default
        authorMail = StringUtils.isNotBlank(repo.getUser()) ? repo.getUser() + "@" + defaultDomain : user.getAuthorEmail();
    }
    return new UserInfo(authorName, authorMail);
}
Also used : UserConfig(org.eclipse.jgit.lib.UserConfig)

Example 4 with UserConfig

use of org.eclipse.jgit.lib.UserConfig in project egit by eclipse.

the class BasicConfigurationDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    userScopedConfig = loadUserScopedConfig();
    UserConfig userConfig = userScopedConfig.get(UserConfig.KEY);
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(2, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
    // user name
    Label userNameLabel = new Label(main, SWT.NONE);
    userNameLabel.setText(UIText.BasicConfigurationDialog_UserNameLabel);
    userName = new Text(main, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(userName);
    String currentName = null;
    if (userConfig != null)
        currentName = userConfig.getAuthorName();
    if (currentName != null)
        userName.setText(currentName);
    userName.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            needsUpdate = true;
        }
    });
    // user email
    Label emailLabel = new Label(main, SWT.NONE);
    emailLabel.setText(UIText.BasicConfigurationDialog_UserEmailLabel);
    email = new Text(main, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(email);
    String currentMail = null;
    if (userConfig != null)
        currentMail = userConfig.getAuthorEmail();
    if (currentMail != null)
        email.setText(currentMail);
    email.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            needsUpdate = true;
        }
    });
    CLabel configLocationInfoLabel = new CLabel(main, SWT.NONE);
    configLocationInfoLabel.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO));
    configLocationInfoLabel.setText(UIText.BasicConfigurationDialog_ConfigLocationInfo);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(configLocationInfoLabel);
    dontShowAgain = new Button(main, SWT.CHECK);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(dontShowAgain);
    dontShowAgain.setText(UIText.BasicConfigurationDialog_DontShowAgain);
    dontShowAgain.setSelection(true);
    Link link = new Link(main, SWT.UNDERLINE_LINK);
    GridDataFactory.fillDefaults().span(2, 1).applyTo(link);
    link.setText(UIText.BasicConfigurationDialog_OpenPreferencePage);
    link.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(getShell(), GlobalConfigurationPreferencePage.ID, null, null).open();
        }
    });
    applyDialogFont(main);
    return main;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) UserConfig(org.eclipse.jgit.lib.UserConfig) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Link(org.eclipse.swt.widgets.Link)

Example 5 with UserConfig

use of org.eclipse.jgit.lib.UserConfig in project egit by eclipse.

the class CommitHelper method calculateCommitInfo.

private void calculateCommitInfo() {
    Repository mergeRepository = null;
    isMergedResolved = false;
    isCherryPickResolved = false;
    RepositoryState state = repository.getRepositoryState();
    canCommit = state.canCommit();
    if (!canCommit) {
        cannotCommitMessage = NLS.bind(UIText.CommitAction_repositoryState, state.getDescription());
        return;
    }
    if (state.equals(RepositoryState.MERGING_RESOLVED)) {
        isMergedResolved = true;
        mergeRepository = repository;
    } else if (state.equals(RepositoryState.CHERRY_PICKING_RESOLVED)) {
        isCherryPickResolved = true;
        mergeRepository = repository;
    }
    previousCommit = getHeadCommit(repository);
    final UserConfig config = repository.getConfig().get(UserConfig.KEY);
    author = config.getAuthorName();
    final String authorEmail = config.getAuthorEmail();
    // $NON-NLS-1$ //$NON-NLS-2$
    author = author + " <" + authorEmail + ">";
    committer = config.getCommitterName();
    final String committerEmail = config.getCommitterEmail();
    // $NON-NLS-1$ //$NON-NLS-2$
    committer = committer + " <" + committerEmail + ">";
    if (isMergedResolved || isCherryPickResolved) {
        commitMessage = getMergeResolveMessage(mergeRepository);
    }
    if (isCherryPickResolved) {
        author = getCherryPickOriginalAuthor(mergeRepository);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryState(org.eclipse.jgit.lib.RepositoryState) UserConfig(org.eclipse.jgit.lib.UserConfig)

Aggregations

UserConfig (org.eclipse.jgit.lib.UserConfig)5 CommitOperation (org.eclipse.egit.core.op.CommitOperation)1 UIText (org.eclipse.egit.ui.internal.UIText)1 Repository (org.eclipse.jgit.lib.Repository)1 RepositoryState (org.eclipse.jgit.lib.RepositoryState)1 CLabel (org.eclipse.swt.custom.CLabel)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Link (org.eclipse.swt.widgets.Link)1 Text (org.eclipse.swt.widgets.Text)1