summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpConfigTest.java33
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java17
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java2
-rw-r--r--pom.xml2
6 files changed, 51 insertions, 12 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpConfigTest.java
index a5f98ee23e..5336dd73c6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpConfigTest.java
@@ -13,7 +13,9 @@ package org.eclipse.jgit.transport;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.util.SystemReader;
import org.junit.Before;
import org.junit.Test;
@@ -96,7 +98,8 @@ public class HttpConfigTest {
@Test
public void testMatchWithInvalidUriInConfig() throws Exception {
config.fromText(
- DEFAULT + "[http \"///\"]\n" + "\tpostBuffer = 1024\n");
+ DEFAULT + "[http \"///#expectedWarning\"]\n"
+ + "\tpostBuffer = 1024\n");
HttpConfig http = new HttpConfig(config,
new URIish("http://example.com/path/repo.git"));
assertEquals(1, http.getPostBuffer());
@@ -104,7 +107,8 @@ public class HttpConfigTest {
@Test
public void testMatchWithInvalidAndValidUriInConfig() throws Exception {
- config.fromText(DEFAULT + "[http \"///\"]\n" + "\tpostBuffer = 1024\n"
+ config.fromText(DEFAULT + "[http \"///#expectedWarning\"]\n"
+ + "\tpostBuffer = 1024\n"
+ "[http \"http://example.com\"]\n" + "\tpostBuffer = 2048\n");
HttpConfig http = new HttpConfig(config,
new URIish("http://example.com/path/repo.git"));
@@ -232,6 +236,31 @@ public class HttpConfigTest {
}
@Test
+ public void testUserAgentEnvOverride() throws Exception {
+ String mockAgent = "jgit-test/5.10.0";
+ SystemReader originalReader = SystemReader.getInstance();
+ SystemReader.setInstance(new MockSystemReader() {
+
+ @Override
+ public String getenv(String variable) {
+ if ("GIT_HTTP_USER_AGENT".equals(variable)) {
+ return mockAgent;
+ }
+ return super.getenv(variable);
+ }
+ });
+ try {
+ config.fromText(DEFAULT + "[http \"http://example.com\"]\n"
+ + "\tuserAgent=DummyAgent/4.0\n");
+ HttpConfig http = new HttpConfig(config,
+ new URIish("http://example.com/"));
+ assertEquals(mockAgent, http.getUserAgent());
+ } finally {
+ SystemReader.setInstance(originalReader);
+ }
+ }
+
+ @Test
public void testUserAgentNonAscii() throws Exception {
config.fromText(DEFAULT + "[http \"http://example.com\"]\n"
+ "\tuserAgent= d ümmy Agent -5.10\n");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
index 55caa64d87..ce546e357e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
@@ -1117,13 +1117,16 @@ public class UploadPackTest {
RevCommit child = remote.commit(remote.tree(remote.file("foo", childBlob)), parent);
remote.update("branch1", child);
- TestRepository<InMemoryRepository> local = new TestRepository<>(client);
- RevBlob localParentBlob = local.blob(commonInBlob + "a");
- RevCommit localParent = local.commit(local.tree(local.file("foo", localParentBlob)));
- RevBlob localChildBlob = local.blob(commonInBlob + "b");
- RevCommit localChild = local.commit(
- local.tree(local.file("foo", localChildBlob)), localParent);
- local.update("branch1", localChild);
+ try (TestRepository<InMemoryRepository> local = new TestRepository<>(
+ client)) {
+ RevBlob localParentBlob = local.blob(commonInBlob + "a");
+ RevCommit localParent = local
+ .commit(local.tree(local.file("foo", localParentBlob)));
+ RevBlob localChildBlob = local.blob(commonInBlob + "b");
+ RevCommit localChild = local.commit(
+ local.tree(local.file("foo", localChildBlob)), localParent);
+ local.update("branch1", localChild);
+ }
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
index 265b71dd2a..d32182864a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java
@@ -580,7 +580,7 @@ public class ObjectDirectory extends FileObjectDatabase {
@Override
void selectObjectRepresentation(PackWriter packer, ObjectToPack otp,
- WindowCursor curs) throws IOException {
+ WindowCursor curs) throws IOException {
selectObjectRepresentation(packer, otp, curs, null);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java
index 58fc250255..dc82f46197 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java
@@ -121,6 +121,8 @@ public class HttpConfig {
}
}).get().intValue();
+ private static final String ENV_HTTP_USER_AGENT = "GIT_HTTP_USER_AGENT"; //$NON-NLS-1$
+
/**
* Config values for http.followRedirect.
*/
@@ -364,6 +366,11 @@ public class HttpConfig {
saveCookies = config.getBoolean(HTTP, match, SAVE_COOKIES_KEY,
saveCookies);
}
+ // Environment overrides config
+ agent = SystemReader.getInstance().getenv(ENV_HTTP_USER_AGENT);
+ if (!StringUtils.isEmptyOrNull(agent)) {
+ userAgent = UserAgent.clean(agent);
+ }
postBuffer = postBufferSize;
sslVerify = sslVerifyFlag;
followRedirects = followRedirectsMode;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java
index 03672f8ba5..04b3eab504 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java
@@ -477,7 +477,7 @@ public class HttpSupport {
i++;
break;
default:
- if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
i++;
break;
}
diff --git a/pom.xml b/pom.xml
index 4231d58796..73ab762236 100644
--- a/pom.xml
+++ b/pom.xml
@@ -172,7 +172,7 @@
<tycho-extras-version>1.7.0</tycho-extras-version>
<gson-version>2.8.2</gson-version>
<bouncycastle-version>1.65</bouncycastle-version>
- <spotbugs-maven-plugin-version>4.0.4</spotbugs-maven-plugin-version>
+ <spotbugs-maven-plugin-version>4.1.3</spotbugs-maven-plugin-version>
<maven-project-info-reports-plugin-version>3.1.1</maven-project-info-reports-plugin-version>
<maven-jxr-plugin-version>3.0.0</maven-jxr-plugin-version>
<maven-surefire-plugin-version>3.0.0-M4</maven-surefire-plugin-version>