From e3b636e7fa2a823cfe90ea75e88034a60f7e59e6 Mon Sep 17 00:00:00 2001 From: David Ostrovsky <david@ostrovsky.org> Date: Thu, 10 Apr 2014 18:58:07 -0400 Subject: [PATCH] SSHD: Add support for git pack commands --- src/main/java/com/gitblit/git/GitblitReceivePackFactory.java | 27 ++++++++++++++++++++++----- 1 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java index bdf9b1a..9911258 100644 --- a/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java +++ b/src/main/java/com/gitblit/git/GitblitReceivePackFactory.java @@ -31,6 +31,7 @@ import com.gitblit.manager.IGitblit; import com.gitblit.models.RepositoryModel; import com.gitblit.models.UserModel; +import com.gitblit.transport.ssh.SshSession; import com.gitblit.utils.HttpUtils; import com.gitblit.utils.StringUtils; @@ -63,7 +64,6 @@ String repositoryName = ""; String origin = ""; String gitblitUrl = ""; - String repositoryUrl = ""; int timeout = 0; if (req instanceof HttpServletRequest) { @@ -72,7 +72,6 @@ repositoryName = request.getAttribute("gitblitRepositoryName").toString(); origin = request.getRemoteHost(); gitblitUrl = HttpUtils.getGitblitURL(request); - repositoryUrl = request.getRequestURI(); // determine pushing user String username = request.getRemoteUser(); @@ -90,6 +89,13 @@ // set timeout from Git daemon timeout = client.getDaemon().getTimeout(); + } else if (req instanceof SshSession) { + // SSH request is always authenticated + SshSession s = (SshSession) req; + repositoryName = s.getRepositoryName(); + origin = s.getRemoteAddress().toString(); + String username = s.getRemoteUser(); + user = gitblit.getUserModel(username); } boolean allowAnonymousPushes = settings.getBoolean(Keys.git.allowAnonymousPushes, false); @@ -98,11 +104,22 @@ throw new ServiceNotEnabledException(); } + String url = settings.getString(Keys.web.canonicalUrl, null); + if (StringUtils.isEmpty(url)) { + url = gitblitUrl; + } + final RepositoryModel repository = gitblit.getRepositoryModel(repositoryName); - final GitblitReceivePack rp = new GitblitReceivePack(gitblit, db, repository, user); - rp.setGitblitUrl(gitblitUrl); - rp.setRepositoryUrl(repositoryUrl); + // Determine which receive pack to use for pushes + final GitblitReceivePack rp; + if (gitblit.getTicketService().isAcceptingNewPatchsets(repository)) { + rp = new PatchsetReceivePack(gitblit, db, repository, user); + } else { + rp = new GitblitReceivePack(gitblit, db, repository, user); + } + + rp.setGitblitUrl(url); rp.setRefLogIdent(new PersonIdent(user.username, user.username + "@" + origin)); rp.setTimeout(timeout); -- Gitblit v1.9.1