Example usage for org.eclipse.jgit.lib UserConfig getCommitterEmail

List of usage examples for org.eclipse.jgit.lib UserConfig getCommitterEmail

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib UserConfig getCommitterEmail.

Prototype

public String getCommitterEmail() 

Source Link

Document

Get the committer email as defined in git variables and configurations.

Usage

From source file:org.apache.maven.scm.provider.git.jgit.command.checkin.JGitCheckInCommand.java

License:Apache License

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;//  w  ww .  j a v a  2 s .  c  om
    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);
}

From source file:org.eclipse.egit.ui.internal.actions.CommitActionHandler.java

License:Open Source License

public Object execute(final ExecutionEvent event) throws ExecutionException {
    // let's see if there is any dirty editor around and
    // ask the user if they want to save or abort
    if (!PlatformUI.getWorkbench().saveAllEditors(true)) {
        return null;
    }//  w ww  .ja  va  2 s.c  o m

    resetState();
    final IProject[] projects = getProjectsInRepositoryOfSelectedResources(event);
    try {
        PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    buildIndexHeadDiffList(projects, monitor);
                } catch (IOException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        Activator.handleError(UIText.CommitAction_errorComputingDiffs, e.getCause(), true);
        return null;
    } catch (InterruptedException e) {
        return null;
    }

    Repository[] repos = getRepositoriesFor(getProjectsForSelectedResources(event));
    Repository repository = null;
    Repository mergeRepository = null;
    amendAllowed = repos.length == 1;
    boolean isMergedResolved = false;
    for (Repository repo : repos) {
        repository = repo;
        RepositoryState state = repo.getRepositoryState();
        if (!state.canCommit()) {
            MessageDialog.openError(getShell(event), UIText.CommitAction_cannotCommit,
                    NLS.bind(UIText.CommitAction_repositoryState, state.getDescription()));
            return null;
        } else if (state.equals(RepositoryState.MERGING_RESOLVED)) {
            isMergedResolved = true;
            mergeRepository = repo;
        }
    }

    loadPreviousCommit(event);
    if (files.isEmpty()) {
        if (amendAllowed && previousCommit != null) {
            boolean result = MessageDialog.openQuestion(getShell(event), UIText.CommitAction_noFilesToCommit,
                    UIText.CommitAction_amendCommit);
            if (!result)
                return null;
            amending = true;
        } else {
            MessageDialog.openWarning(getShell(event), UIText.CommitAction_noFilesToCommit,
                    UIText.CommitAction_amendNotPossible);
            return null;
        }
    }

    String author = null;
    String committer = null;
    if (repository != null) {
        final UserConfig config = repository.getConfig().get(UserConfig.KEY);
        author = config.getAuthorName();
        final String authorEmail = config.getAuthorEmail();
        author = author + " <" + authorEmail + ">"; //$NON-NLS-1$ //$NON-NLS-2$

        committer = config.getCommitterName();
        final String committerEmail = config.getCommitterEmail();
        committer = committer + " <" + committerEmail + ">"; //$NON-NLS-1$ //$NON-NLS-2$
    }

    CommitDialog commitDialog = new CommitDialog(getShell(event));
    commitDialog.setAmending(amending);
    commitDialog.setAmendAllowed(amendAllowed);
    commitDialog.setFileList(files, indexDiffs);
    commitDialog.setPreselectedFiles(getSelectedFiles(event));
    commitDialog.setAuthor(author);
    commitDialog.setCommitter(committer);
    commitDialog.setAllowToChangeSelection(!isMergedResolved);

    if (previousCommit != null) {
        commitDialog.setPreviousCommitMessage(previousCommit.getFullMessage());
        PersonIdent previousAuthor = previousCommit.getAuthorIdent();
        commitDialog
                .setPreviousAuthor(previousAuthor.getName() + " <" + previousAuthor.getEmailAddress() + ">"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    if (isMergedResolved) {
        commitDialog.setCommitMessage(getMergeResolveMessage(mergeRepository, event));
    }

    if (commitDialog.open() != IDialogConstants.OK_ID)
        return null;

    final CommitOperation commitOperation = new CommitOperation(commitDialog.getSelectedFiles(), notIndexed,
            notTracked, commitDialog.getAuthor(), commitDialog.getCommitter(), commitDialog.getCommitMessage());
    if (commitDialog.isAmending()) {
        commitOperation.setAmending(true);
        commitOperation.setPreviousCommit(previousCommit);
        commitOperation.setRepos(repos);
    }
    commitOperation.setComputeChangeId(commitDialog.getCreateChangeId());
    commitOperation.setCommitAll(isMergedResolved);
    if (isMergedResolved)
        commitOperation.setRepos(repos);
    String jobname = UIText.CommitAction_CommittingChanges;
    Job job = new Job(jobname) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                commitOperation.execute(monitor);

                for (IProject proj : getProjectsForSelectedResources(event)) {
                    RepositoryMapping.getMapping(proj).fireRepositoryChanged();
                }
            } catch (CoreException e) {
                return Activator.createErrorStatus(UIText.CommitAction_CommittingFailed, e);
            } catch (ExecutionException e) {
                return Activator.createErrorStatus(UIText.CommitAction_CommittingFailed, e);
            } finally {
                GitLightweightDecorator.refresh();
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (family.equals(JobFamilies.COMMIT))
                return true;
            return super.belongsTo(family);
        }

    };
    job.setUser(true);
    job.schedule();
    return null;
}

From source file:org.eclipse.egit.ui.internal.commit.CommitHelper.java

License:Open Source License

private void calculateCommitInfo() {
    Repository mergeRepository = null;// w  ww .ja  v a  2  s.  c om
    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();
    author = author + " <" + authorEmail + ">"; //$NON-NLS-1$ //$NON-NLS-2$

    committer = config.getCommitterName();
    final String committerEmail = config.getCommitterEmail();
    committer = committer + " <" + committerEmail + ">"; //$NON-NLS-1$ //$NON-NLS-2$

    if (isMergedResolved || isCherryPickResolved) {
        commitMessage = getMergeResolveMessage(mergeRepository);
    }

    if (isCherryPickResolved) {
        author = getCherryPickOriginalAuthor(mergeRepository);
    }
}

From source file:org.jboss.tools.feedhenry.ui.internal.util.GitUtil.java

License:Open Source License

private static RevCommit commit(IProject project, String commitMessage, Repository repository,
        IProgressMonitor monitor) throws CoreException {
    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);/* w  ww. j  a  v a  2  s.c  o  m*/
    op.setRepository(repository);
    op.execute(monitor);
    return op.getCommit();
}

From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java

License:Open Source License

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()));/*from www  . j a  va 2 s  .  c  om*/
    /**
     * 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();
}