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();
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations