* Commands that allows working with git repositories
*/
public class GitUtils {
+ private static final String SSH_V2 = "SSH-2.0";
+
/**
* Convert remote URL to JGIT form
*
return res.getStdout().trim();
}
+
+
+ @NotNull
+ public static String getSshClientVersion(@NotNull String originalSshClientVersion, @NotNull String teamcityVersion) {
+ if (!originalSshClientVersion.startsWith(SSH_V2))
+ return originalSshClientVersion;
+ //rfc4253-4.2
+ return SSH_V2 + "-" + teamcityVersion.replace(' ', '-') + originalSshClientVersion.substring(SSH_V2.length());
+ }
}
import jetbrains.buildServer.ssh.VcsRootSshKeyManager;
import jetbrains.buildServer.vcs.VcsException;
import jetbrains.buildServer.vcs.VcsRoot;
+import jetbrains.buildServer.version.ServerVersionHolder;
+import jetbrains.buildServer.version.ServerVersionInfo;
import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.http.apache.HttpClientConnectionFactory;
import org.eclipse.jgit.util.FS;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.*;
private final ServerPluginConfig myConfig;
private final Map<String,String> myJSchOptions;
- private VcsRootSshKeyManager mySshKeyManager;
+ private final VcsRootSshKeyManager mySshKeyManager;
public TransportFactoryImpl(@NotNull ServerPluginConfig config,
@NotNull VcsRootSshKeyManager sshKeyManager) {
protected void configure(OpenSshConfig.Host hc, Session session) {
super.configure(hc, session);
session.setConfig("StrictHostKeyChecking", "no");
+ String teamCityVersion = getTeamCityVersion();
+ if (teamCityVersion != null) {
+ session.setClientVersion(GitUtils.getSshClientVersion(session.getClientVersion(), teamCityVersion));
+ }
}
}
return builder.toString();
}
+ @Nullable
+ private static String getTeamCityVersion() {
+ try {
+ ServerVersionInfo version = ServerVersionHolder.getVersion();
+ return "TeamCity Server " + version.getDisplayVersion();
+ } catch (Exception e) {
+ return null;
+ }
+ }
}
assertEquals("Short name file content doesn't match", content, FileUtil.readText(new File(shortFileName)));
}
+
+ @Test
+ public void ssh_client_version() {
+ then(GitUtils.getSshClientVersion("SSH-1.0", "whatever"))
+ .isEqualTo("SSH-1.0");
+ then(GitUtils.getSshClientVersion("SSH-2.0", "TeamCity Server 2017.2.1"))
+ .isEqualTo("SSH-2.0-TeamCity-Server-2017.2.1");
+ then(GitUtils.getSshClientVersion("SSH-2.0-LIB-VERSION", "TeamCity-Server-2017.2.1"))
+ .isEqualTo("SSH-2.0-TeamCity-Server-2017.2.1-LIB-VERSION");
+ then(GitUtils.getSshClientVersion("SSH-2.0-LIB-VERSION", "TeamCity Server 2017.2.1 EAP"))
+ .isEqualTo("SSH-2.0-TeamCity-Server-2017.2.1-EAP-LIB-VERSION");
+ }
}