diff options
author | Antonio Barone <syntonyze@gmail.com> | 2024-12-09 16:22:18 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2024-12-10 09:21:51 +0000 |
commit | 2b229df06c94fa351ce00227a107835e3b21f5ce (patch) | |
tree | c7a6f3484662f3f4bab0eae5778184769a024c12 | |
parent | 7fedd15c82eda8c8ff694b6e809e83bd64a5ab33 (diff) | |
download | jgit-2b229df06c94fa351ce00227a107835e3b21f5ce.tar.gz jgit-2b229df06c94fa351ce00227a107835e3b21f5ce.zip |
Advertise "agent" capability when using protocol v2
The "agent" capability was not advertised by the server when executing
git-upload-pack over protocol v2.
This, in turn, prevented the clients from advertising its client agent
too, as documented [1]:
"The client may optionally send its own agent string by including the
agent capability with a value Y (in the form agent=Y) in its request to
the server (but it MUST NOT do so if the server did not advertise the
agent capability)."
When using jgit with Gerrit this had the effect of preventing the
logging of the git client agent in the sshd_log.
[1] https://git-scm.com/docs/protocol-v2#_agent
Bug: jgit-118
Change-Id: Ifb6ea65fde020425920338f7dd9cc683fed6a4a4
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java | 12 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java | 1 |
2 files changed, 7 insertions, 6 deletions
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 017104c527..2bd40031cc 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 @@ -502,15 +502,15 @@ public class UploadPackTest { assertThat(hook.capabilitiesRequest, notNullValue()); assertThat(pckIn.readString(), is("version 2")); assertThat( - Arrays.asList(pckIn.readString(), pckIn.readString(), - pckIn.readString()), + Arrays.asList(pckIn.readString(),pckIn.readString(), + pckIn.readString(), pckIn.readString()), // TODO(jonathantanmy) This check is written this way // to make it simple to see that we expect this list of // capabilities, but probably should be loosened to // allow additional commands to be added to the list, // and additional capabilities to be added to existing // commands without requiring test changes. - hasItems("ls-refs", "fetch=shallow", "server-option")); + hasItems("agent=" + UserAgent.get() ,"ls-refs", "fetch=shallow", "server-option")); assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @@ -536,7 +536,7 @@ public class UploadPackTest { lines.add(line); } } - assertThat(lines, containsInAnyOrder("ls-refs", "fetch", "server-option")); + assertThat(lines, containsInAnyOrder("ls-refs", "fetch", "server-option", "agent=" + UserAgent.get())); } private void checkUnadvertisedIfUnallowed(String configSection, @@ -643,9 +643,9 @@ public class UploadPackTest { assertThat(pckIn.readString(), is("version 2")); assertThat( - Arrays.asList(pckIn.readString(), pckIn.readString(), + Arrays.asList(pckIn.readString(),pckIn.readString(), pckIn.readString(), pckIn.readString()), - hasItems("ls-refs", "fetch=shallow", "server-option")); + hasItems("agent="+ UserAgent.get(),"ls-refs", "fetch=shallow", "server-option")); assertTrue(PacketLineIn.isEnd(pckIn.readString())); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 968728de8d..fbea7044f3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1441,6 +1441,7 @@ public class UploadPack implements Closeable { if (transferConfig.isAdvertiseObjectInfo()) { caps.add(COMMAND_OBJECT_INFO); } + caps.add(OPTION_AGENT + "=" + UserAgent.get()); return caps; } |