Example usage for org.eclipse.jgit.lib ConfigConstants CONFIG_GERRIT_SECTION

List of usage examples for org.eclipse.jgit.lib ConfigConstants CONFIG_GERRIT_SECTION

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ConfigConstants CONFIG_GERRIT_SECTION.

Prototype

String CONFIG_GERRIT_SECTION

To view the source code for org.eclipse.jgit.lib ConfigConstants CONFIG_GERRIT_SECTION.

Click Source Link

Document

The "gerrit" section

Usage

From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java

License:Open Source License

@Override
public Revision commit(CommitRequest request) throws GitException {
    try {/*from w  ww  . jav a 2s .  c o m*/
        String message = request.getMessage();
        GitUser committer = getUser();
        if (message == null) {
            throw new GitException("Message wasn't set");
        }
        if (committer == null) {
            throw new GitException("Committer can't be null");
        }
        String committerName = committer.getName();
        String committerEmail = committer.getEmail();
        if (committerName == null || committerEmail == null) {
            throw new GitException("Git user name and (or) email wasn't set",
                    ErrorCodes.NO_COMMITTER_NAME_OR_EMAIL_DEFINED);
        }
        if (!repository.getRepositoryState().canCommit()) {
            Revision rev = newDto(Revision.class);
            rev.setMessage(String.format(MESSAGE_COMMIT_NOT_POSSIBLE,
                    repository.getRepositoryState().getDescription()));
            return rev;
        }

        if (request.isAmend() && !repository.getRepositoryState().canAmend()) {
            Revision rev = newDto(Revision.class);
            rev.setMessage(String.format(MESSAGE_AMEND_NOT_POSSIBLE,
                    repository.getRepositoryState().getDescription()));
            return rev;
        }

        CommitCommand commitCommand = getGit().commit().setCommitter(committerName, committerEmail)
                .setAuthor(committerName, committerEmail).setMessage(message).setAll(request.isAll())
                .setAmend(request.isAmend());

        // Check if repository is configured with Gerrit Support
        String gerritSupportConfigValue = repository.getConfig().getString(
                ConfigConstants.CONFIG_GERRIT_SECTION, null, ConfigConstants.CONFIG_KEY_CREATECHANGEID);
        boolean isGerritSupportConfigured = gerritSupportConfigValue != null
                ? Boolean.valueOf(gerritSupportConfigValue)
                : false;
        commitCommand.setInsertChangeId(isGerritSupportConfigured);
        RevCommit result = commitCommand.call();
        GitUser gitUser = newDto(GitUser.class).withName(committerName).withEmail(committerEmail);

        return newDto(Revision.class).withBranch(getCurrentBranch()).withId(result.getId().getName())
                .withMessage(result.getFullMessage())
                .withCommitTime(MILLISECONDS.convert(result.getCommitTime(), SECONDS)).withCommitter(gitUser);
    } catch (GitAPIException exception) {
        throw new GitException(exception.getMessage(), exception);
    }
}

From source file:org.eclipse.egit.core.internal.gerrit.GerritUtil.java

License:Open Source License

/**
 * @param config/*  w  w  w . ja v  a2 s .  c o m*/
 * @return true if there if "create change ID" is configured
 */
public static boolean getCreateChangeId(Config config) {
    return config.getBoolean(ConfigConstants.CONFIG_GERRIT_SECTION, ConfigConstants.CONFIG_KEY_CREATECHANGEID,
            false);
}

From source file:org.eclipse.egit.core.internal.gerrit.GerritUtil.java

License:Open Source License

/**
 * Set the "create change ID" configuration
 *
 * @param config//from  w  ww  .  ja  v  a 2s.c  o m
 */
public static void setCreateChangeId(Config config) {
    config.setBoolean(ConfigConstants.CONFIG_GERRIT_SECTION, null, ConfigConstants.CONFIG_KEY_CREATECHANGEID,
            true);
}

From source file:org.eclipse.egit.core.internal.gerrit.GerritUtil.java

License:Open Source License

/**
 * If the repository is not bare and looks like it might be a Gerrit
 * repository, try to configure it such that EGit's Gerrit support is
 * enabled./* w  w  w . ja va  2  s.  c om*/
 *
 * @param repository
 *            to try to configure
 */
public static void tryToAutoConfigureForGerrit(@NonNull Repository repository) {
    if (repository.isBare()) {
        return;
    }
    StoredConfig config = repository.getConfig();
    boolean isGerrit = false;
    boolean changed = false;
    try {
        for (RemoteConfig remote : RemoteConfig.getAllRemoteConfigs(config)) {
            if (isGerritPush(remote)) {
                isGerrit = true;
                if (configureFetchNotes(remote)) {
                    changed = true;
                    remote.update(config);
                }
            }
        }
    } catch (URISyntaxException ignored) {
        // Ignore it here -- we're just trying to set up Gerrit support.
    }
    if (isGerrit) {
        if (config.getString(ConfigConstants.CONFIG_GERRIT_SECTION, null,
                ConfigConstants.CONFIG_KEY_CREATECHANGEID) != null) {
            // Already configured.
        } else {
            setCreateChangeId(config);
            changed = true;
        }
        if (changed) {
            try {
                config.save();
            } catch (IOException e) {
                Activator.logError(
                        MessageFormat.format(CoreText.GerritUtil_ConfigSaveError, repository.getDirectory()),
                        e);
            }
        }
    }
}

From source file:org.eclipse.egit.core.op.SetChangeIdTask.java

License:Open Source License

public void execute(Repository repository, IProgressMonitor monitor) throws CoreException {
    try {//from ww  w.  j a v  a2  s.  co  m
        repository.getConfig().setBoolean(ConfigConstants.CONFIG_GERRIT_SECTION, null,
                ConfigConstants.CONFIG_KEY_CREATECHANGEID, createchangeid);
        repository.getConfig().save();
    } catch (IOException e) {
        throw new CoreException(Activator.error(e.getMessage(), e));
    }
}

From source file:org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent.java

License:Open Source License

/**
 * Sets the defaults for change id and signed off
 *//*from  w w  w .j  av a  2 s  . c om*/
public void setDefaults() {
    createChangeId = repository.getConfig().getBoolean(ConfigConstants.CONFIG_GERRIT_SECTION,
            ConfigConstants.CONFIG_KEY_CREATECHANGEID, false);
    signedOff = org.eclipse.egit.ui.Activator.getDefault().getPreferenceStore()
            .getBoolean(UIPreferences.COMMIT_DIALOG_SIGNED_OFF_BY);
}

From source file:org.eclipse.egit.ui.internal.gerrit.ConfigureGerritWizard.java

License:Open Source License

private void configureCreateChangeId() {
    config.setBoolean(ConfigConstants.CONFIG_GERRIT_SECTION, null, ConfigConstants.CONFIG_KEY_CREATECHANGEID,
            true);
}

From source file:org.eclipse.egit.ui.internal.staging.StagingView.java

License:Open Source License

private boolean userEnteredCommmitMessage() {
    if (commitMessageComponent.getRepository() == null)
        return false;
    String message = commitMessageComponent.getCommitMessage().replace(UIText.StagingView_headCommitChanged,
            ""); //$NON-NLS-1$
    if (message == null || message.trim().length() == 0)
        return false;

    String chIdLine = "Change-Id: I" + ObjectId.zeroId().name(); //$NON-NLS-1$

    if (currentRepository.getConfig().getBoolean(ConfigConstants.CONFIG_GERRIT_SECTION,
            ConfigConstants.CONFIG_KEY_CREATECHANGEID, false) && commitMessageComponent.getCreateChangeId()) {
        if (message.trim().equals(chIdLine))
            return false;

        // change id was added automatically, but ther is more in the
        // message; strip the id, and check for the signed-off-by tag
        message = message.replace(chIdLine, ""); //$NON-NLS-1$
    }// w w  w.  ja v a 2  s.  c o  m

    if (org.eclipse.egit.ui.Activator.getDefault().getPreferenceStore()
            .getBoolean(UIPreferences.COMMIT_DIALOG_SIGNED_OFF_BY) && commitMessageComponent.isSignedOff()
            && message.trim().equals(Constants.SIGNED_OFF_BY_TAG + commitMessageComponent.getCommitter()))
        return false;

    return true;
}

From source file:org.eclipse.mylyn.internal.gerrit.ui.egit.GerritRepositorySearchPage.java

License:Open Source License

private void addCreateGerritChangeIdConfig(GitRepositoryInfo gitRepositoryInfo) {
    gitRepositoryInfo.addRepositoryConfigProperty(ConfigConstants.CONFIG_GERRIT_SECTION, null,
            ConfigConstants.CONFIG_KEY_CREATECHANGEID, ConfigConstants.CONFIG_KEY_TRUE);
}