Example usage for org.eclipse.jgit.lib Constants GIT_CONFIG_NOSYSTEM_KEY

List of usage examples for org.eclipse.jgit.lib Constants GIT_CONFIG_NOSYSTEM_KEY

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants GIT_CONFIG_NOSYSTEM_KEY.

Prototype

String GIT_CONFIG_NOSYSTEM_KEY

To view the source code for org.eclipse.jgit.lib Constants GIT_CONFIG_NOSYSTEM_KEY.

Click Source Link

Document

The environment variable that blocks use of the system config file

Usage

From source file:com.genuitec.eclipse.gerrit.tools.utils.RepositoryUtils.java

License:Open Source License

public static String getUserId(Repository repository) {
    StoredConfig config;/* ww w  .  j  a  v a 2  s.c om*/
    if (repository == null) {
        if (StringUtils.isEmptyOrNull(SystemReader.getInstance().getenv(Constants.GIT_CONFIG_NOSYSTEM_KEY))) {
            config = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED);
        } else {
            config = new FileBasedConfig(null, FS.DETECTED) {
                public void load() {
                    // empty, do not load
                }

                public boolean isOutdated() {
                    // regular class would bomb here
                    return false;
                }
            };
        }
        try {
            config.load();
            config = SystemReader.getInstance().openUserConfig(config, FS.DETECTED);
            config.load();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    } else {
        config = repository.getConfig();
    }
    String email = config.getString("user", null, "email"); //$NON-NLS-1$ //$NON-NLS-2$
    if (email != null) {
        int ind = email.indexOf('@');
        if (ind > 0) {
            return email.substring(0, ind);
        }
    }
    return null;
}