diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/gitweb/GitwebServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/gitweb/GitwebServlet.java index 2d981f5a7f..cb9e616cb4 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/gitweb/GitwebServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/gitweb/GitwebServlet.java @@ -238,10 +238,11 @@ class GitwebServlet extends HttpServlet { p.print(" if (( $secure && $ENV{'SERVER_PORT'} != 443)\n"); p.print(" || (!$secure && $ENV{'SERVER_PORT'} != 80)\n"); p.print(" );\n"); - p.print(" $http_url .= qq{$ENV{'GERRIT_CONTEXT_PATH'}};\n"); + p.print(" my $context = $ENV{'GERRIT_CONTEXT_PATH'};\n"); + p.print(" chop($context);\n"); + p.print(" $http_url .= qq{$context};\n"); p.print(" $http_url .= qq{/a}\n"); p.print(" unless $ENV{'GERRIT_ANONYMOUS_READ'};\n"); - p.print(" \n"); p.print(" push @git_base_url_list, $http_url;\n"); p.print("}\n"); @@ -551,7 +552,7 @@ class GitwebServlet extends HttpServlet { env.set("HTTP_" + name.toUpperCase().replace('-', '_'), value); } - env.set("GERRIT_CONTEXT_PATH", req.getContextPath()); + env.set("GERRIT_CONTEXT_PATH", req.getContextPath() + "/"); env.set("GERRIT_PROJECT_NAME", project.getProject().getName()); env.set("GITWEB_PROJECTROOT", diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java index c024a67a6d..0423e5b31c 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Daemon.java @@ -89,6 +89,7 @@ import com.google.gerrit.sshd.SshKeyCacheImpl; import com.google.gerrit.sshd.SshModule; import com.google.gerrit.sshd.commands.DefaultCommandModule; import com.google.gerrit.sshd.commands.IndexCommandsModule; +import com.google.gerrit.sshd.plugin.LfsPluginAuthCommand; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -459,7 +460,8 @@ public class Daemon extends SiteProgram { modules.add(new SshHostKeyModule()); } modules.add(new DefaultCommandModule(slave, - sysInjector.getInstance(DownloadConfig.class))); + sysInjector.getInstance(DownloadConfig.class), + sysInjector.getInstance(LfsPluginAuthCommand.Module.class))); if (!slave && indexType == IndexType.LUCENE) { modules.add(new IndexCommandsModule()); } diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/DefaultCommandModule.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/DefaultCommandModule.java index 62e929750c..c9cdbe05d5 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/DefaultCommandModule.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/DefaultCommandModule.java @@ -27,10 +27,13 @@ import com.google.gerrit.sshd.plugin.LfsPluginAuthCommand; /** Register the commands a Gerrit server supports. */ public class DefaultCommandModule extends CommandModule { private final DownloadConfig downloadConfig; + private final LfsPluginAuthCommand.Module lfsPluginAuthModule; - public DefaultCommandModule(boolean slave, DownloadConfig downloadCfg) { + public DefaultCommandModule(boolean slave, DownloadConfig downloadCfg, + LfsPluginAuthCommand.Module module) { slaveMode = slave; downloadConfig = downloadCfg; + lfsPluginAuthModule = module; } @Override @@ -124,7 +127,7 @@ public class DefaultCommandModule extends CommandModule { alias(logging, "ls", ListLoggingLevelCommand.class); alias(logging, "set", SetLoggingLevelCommand.class); - install(new LfsPluginAuthCommand.Module()); + install(lfsPluginAuthModule); } private boolean sshEnabled() { diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/plugin/LfsPluginAuthCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/plugin/LfsPluginAuthCommand.java index e79f8bbf42..0c8d024f1a 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/plugin/LfsPluginAuthCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/plugin/LfsPluginAuthCommand.java @@ -16,11 +16,13 @@ package com.google.gerrit.sshd.plugin; import com.google.gerrit.extensions.registration.DynamicItem; import com.google.gerrit.server.CurrentUser; +import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.sshd.CommandModule; import com.google.gerrit.sshd.SshCommand; import com.google.inject.Inject; import com.google.inject.Provider; +import org.eclipse.jgit.lib.Config; import org.kohsuke.args4j.Argument; import java.util.ArrayList; @@ -33,10 +35,19 @@ public class LfsPluginAuthCommand extends SshCommand { } public static class Module extends CommandModule { + private final boolean pluginProvided; + + @Inject + Module(@GerritServerConfig Config cfg) { + pluginProvided = cfg.getString("lfs", null, "plugin") != null; + } + @Override protected void configure() { - command("git-lfs-authenticate").to(LfsPluginAuthCommand.class); - DynamicItem.itemOf(binder(), LfsSshPluginAuth.class); + if (pluginProvided) { + command("git-lfs-authenticate").to(LfsPluginAuthCommand.class); + DynamicItem.itemOf(binder(), LfsSshPluginAuth.class); + } } } diff --git a/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java b/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java index 94168f447a..3bdc64eb40 100644 --- a/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java +++ b/gerrit-war/src/main/java/com/google/gerrit/httpd/WebAppInitializer.java @@ -76,6 +76,7 @@ import com.google.gerrit.sshd.SshKeyCacheImpl; import com.google.gerrit.sshd.SshModule; import com.google.gerrit.sshd.commands.DefaultCommandModule; import com.google.gerrit.sshd.commands.IndexCommandsModule; +import com.google.gerrit.sshd.plugin.LfsPluginAuthCommand; import com.google.inject.AbstractModule; import com.google.inject.CreationException; import com.google.inject.Guice; @@ -364,7 +365,8 @@ public class WebAppInitializer extends GuiceServletContextListener modules.add(sysInjector.getInstance(SshModule.class)); modules.add(new SshHostKeyModule()); modules.add(new DefaultCommandModule(false, - sysInjector.getInstance(DownloadConfig.class))); + sysInjector.getInstance(DownloadConfig.class), + sysInjector.getInstance(LfsPluginAuthCommand.Module.class))); if (indexType == IndexType.LUCENE) { modules.add(new IndexCommandsModule()); }