aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2015-02-25 12:01:40 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2015-02-25 12:01:43 -0500
commit1adac455507af79624063698a7bb9282b0769efd (patch)
tree0bf80ba076b095f9d57c094b7f0a1ad081ae591b
parent57644f23a1481cb6be0e3e9515b62ff1be028f78 (diff)
parenta8fd029a931f35db9f98e4f75530f299a70892eb (diff)
downloadjgit-1adac455507af79624063698a7bb9282b0769efd.tar.gz
jgit-1adac455507af79624063698a7bb9282b0769efd.zip
Merge "Read user.name and email from environment first" into stable-3.7
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java17
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java17
2 files changed, 26 insertions, 8 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index 69926f915d..db31fd34cd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
@@ -186,6 +186,9 @@ public class ConfigTest {
assertFalse(localConfig.get(UserConfig.KEY).isAuthorEmailImplicit());
// the values are defined in the global configuration
+ // first clear environment variables since they would override
+ // configuration files
+ mockSystemReader.clearProperties();
userGitConfig.setString("user", null, "name", "global username");
userGitConfig.setString("user", null, "email", "author@globalemail");
authorName = localConfig.get(UserConfig.KEY).getAuthorName();
@@ -211,6 +214,20 @@ public class ConfigTest {
assertEquals("author@localemail", authorEmail);
assertFalse(localConfig.get(UserConfig.KEY).isCommitterNameImplicit());
assertFalse(localConfig.get(UserConfig.KEY).isCommitterEmailImplicit());
+
+ // also git environment variables are defined
+ mockSystemReader.setProperty(Constants.GIT_AUTHOR_NAME_KEY,
+ "git author name");
+ mockSystemReader.setProperty(Constants.GIT_AUTHOR_EMAIL_KEY,
+ "author@email");
+ localConfig.setString("user", null, "name", "local username");
+ localConfig.setString("user", null, "email", "author@localemail");
+ authorName = localConfig.get(UserConfig.KEY).getAuthorName();
+ authorEmail = localConfig.get(UserConfig.KEY).getAuthorEmail();
+ assertEquals("git author name", authorName);
+ assertEquals("author@email", authorEmail);
+ assertFalse(localConfig.get(UserConfig.KEY).isAuthorNameImplicit());
+ assertFalse(localConfig.get(UserConfig.KEY).isAuthorEmailImplicit());
}
@Test
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java
index 60ac6f176d..b8d236c1da 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java
@@ -172,12 +172,13 @@ public class UserConfig {
}
private static String getNameInternal(Config rc, String envKey) {
- // try to get the user name from the local and global configurations.
- String username = rc.getString("user", null, "name"); //$NON-NLS-1$ //$NON-NLS-2$
+ // try to get the user name for the system property GIT_XXX_NAME
+ String username = system().getenv(envKey);
if (username == null) {
- // try to get the user name for the system property GIT_XXX_NAME
- username = system().getenv(envKey);
+ // try to get the user name from the local and global
+ // configurations.
+ username = rc.getString("user", null, "name"); //$NON-NLS-1$ //$NON-NLS-2$
}
return stripInvalidCharacters(username);
@@ -196,12 +197,12 @@ public class UserConfig {
}
private static String getEmailInternal(Config rc, String envKey) {
- // try to get the email from the local and global configurations.
- String email = rc.getString("user", null, "email"); //$NON-NLS-1$ //$NON-NLS-2$
+ // try to get the email for the system property GIT_XXX_EMAIL
+ String email = system().getenv(envKey);
if (email == null) {
- // try to get the email for the system property GIT_XXX_EMAIL
- email = system().getenv(envKey);
+ // try to get the email from the local and global configurations.
+ email = rc.getString("user", null, "email"); //$NON-NLS-1$ //$NON-NLS-2$
}
return stripInvalidCharacters(email);