summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2015-02-23 13:49:24 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2015-02-24 16:39:19 +0100
commita8fd029a931f35db9f98e4f75530f299a70892eb (patch)
tree6b322847a5159e3a6b3f9a366322ab4b446ea49f /org.eclipse.jgit.test
parenta8743df19c2574bc3481fa5f811499b5960951a8 (diff)
downloadjgit-a8fd029a931f35db9f98e4f75530f299a70892eb.tar.gz
jgit-a8fd029a931f35db9f98e4f75530f299a70892eb.zip
Read user.name and email from environment first
According to [1] user name and email are taken first from the environment variables: GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL In case (some of) these environment variables are not set, the information is taken from the git configuration. JGit doesn not yet support the environment variables GIT_AUTHOR_DATE and GIT_COMMITTER_DATE. [1] https://www.kernel.org/pub/software/scm/git/docs/git-commit-tree.html#_commit_information Bug: 460586 Change-Id: I3ba582b4ae13674cf319652b5b13ebcbb96dd8ec Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java17
1 files changed, 17 insertions, 0 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