List of usage examples for org.eclipse.jgit.lib UserConfig getAuthorEmail
public String getAuthorEmail()
From source file:me.cmoz.gradle.snapshot.GitSCMCommand.java
License:Apache License
@Override @SneakyThrows(IOException.class) public Commit getLatestCommit(@NonNull final String dateFormat) { if (repoDir == null) { throw new IllegalStateException("'.git' folder could not be found."); }//from w w w . j a va2 s.c o m final FileRepositoryBuilder builder = new FileRepositoryBuilder(); final Repository repo = builder.setGitDir(repoDir).readEnvironment().build(); final StoredConfig conf = repo.getConfig(); int abbrev = Commit.ABBREV_LENGTH; if (conf != null) { abbrev = conf.getInt("core", "abbrev", abbrev); } final SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); final Ref HEAD = repo.getRef(Constants.HEAD); if (HEAD.getObjectId() == null) { throw new RuntimeException("Could not find any commits from HEAD ref."); } final RevWalk revWalk = new RevWalk(repo); if (HEAD.getObjectId() == null) { throw new RuntimeException("Could not find any commits from HEAD ref."); } final RevCommit revCommit = revWalk.parseCommit(HEAD.getObjectId()); revWalk.markStart(revCommit); try { // git commit time in sec and java datetime is in ms final Date commitTime = new Date(revCommit.getCommitTime() * 1000L); final PersonIdent ident = revCommit.getAuthorIdent(); final UserConfig userConf = conf.get(UserConfig.KEY); return Commit.builder().buildTime(sdf.format(new Date())).buildAuthorName(userConf.getAuthorName()) .buildAuthorEmail(userConf.getAuthorEmail()).branchName(repo.getBranch()) .commitId(revCommit.getName()).commitTime(sdf.format(commitTime)) .commitUserName(ident.getName()).commitUserEmail(ident.getEmailAddress()) .commitMessage(revCommit.getFullMessage().trim()).build(); } finally { revWalk.dispose(); repo.close(); } }
From source file:org.apache.maven.scm.provider.git.jgit.command.checkin.JGitCheckInCommand.java
License:Apache License
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;/*from w ww .j a va 2 s. com*/ 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); }
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; }//from w ww . jav a2 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 w w . jav a2 s . c o m*/ 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.eclipse.egit.ui.internal.dialogs.BasicConfigurationDialog.java
License:Open Source License
@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/*from w w w .j a v a2 s. c o m*/ 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() { 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() { public void modifyText(ModifyEvent e) { needsUpdate = true; } }); dontShowAgain = new Button(main, SWT.CHECK); GridDataFactory.fillDefaults().span(2, 1).applyTo(dontShowAgain); dontShowAgain.setText("&Don't show this dialog again"); //$NON-NLS-1$ dontShowAgain.setSelection(true); Link link = new Link(main, SWT.UNDERLINE_LINK); GridDataFactory.fillDefaults().span(2, 1).applyTo(link); link.setText("Open the <a>Git Configuration</a> Preference Page"); //$NON-NLS-1$ link.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { PreferencesUtil .createPreferenceDialogOn(getShell(), GlobalConfigurationPreferencePage.ID, null, null) .open(); } }); applyDialogFont(main); return main; }
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 .ja v a 2 s . co 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 w w w.j a v a2 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(); }