]> source.dussan.org Git - gitblit.git/commitdiff
Fix to GitServlet to allow pushing to symlinked repositories (issue 116)
authorJames Moger <james.moger@gitblit.com>
Tue, 7 Aug 2012 13:43:24 +0000 (09:43 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 7 Aug 2012 13:43:24 +0000 (09:43 -0400)
docs/04_releases.mkd
src/com/gitblit/GitFilter.java
src/com/gitblit/GitServlet.java

index a519175a113c96b6b70f22da6fd57b32a2507fae..f5facc507995d68db0059222b70cc6270bcb3744 100644 (file)
@@ -13,8 +13,9 @@ If you are updating from an earlier release AND you have indexed branches with t
 \r
 - Do not index blobs in submodules (issue 119)\r
 - Restore original user or team object on failure to update (issue 118)\r
+- Fixes to relative path determination in repository search algorithm for symlinks (issue 116)\r
+- Fix to GitServlet to allow pushing to symlinked repositories (issue 116)\r
 - Repository URL uses `X-Forwarded-Proto` and `X-Forwarded-Port`, if available, for reverse proxy configurations (issue 115)\r
-- Fixes to relative path determination in repository searh algorithm for symlinks (issue 116)\r
 - Output real RAW content, not simulated RAW content (issue 114)\r
 - Fixed Lucene charset encoding bug when reindexing a repository (issue 112)\r
 - Fixed null pointer in LdapUserSerivce if account has a null email address (issue 110)\r
index 4ae5b6c26f48c1a73d2f80c4376e08ad96a93819..aa673462bc2d2dc2e30a355c12b7e491d34ab3d3 100644 (file)
@@ -32,11 +32,11 @@ import com.gitblit.utils.StringUtils;
  */\r
 public class GitFilter extends AccessRestrictionFilter {\r
 \r
-       protected final String gitReceivePack = "/git-receive-pack";\r
+       protected static final String gitReceivePack = "/git-receive-pack";\r
 \r
-       protected final String gitUploadPack = "/git-upload-pack";\r
+       protected static final String gitUploadPack = "/git-upload-pack";\r
 \r
-       protected final String[] suffixes = { gitReceivePack, gitUploadPack, "/info/refs", "/HEAD",\r
+       protected static final String[] suffixes = { gitReceivePack, gitUploadPack, "/info/refs", "/HEAD",\r
                        "/objects" };\r
 \r
        /**\r
@@ -45,9 +45,8 @@ public class GitFilter extends AccessRestrictionFilter {
         * @param url\r
         * @return repository name\r
         */\r
-       @Override\r
-       protected String extractRepositoryName(String url) {\r
-               String repository = url;\r
+       public static String getRepositoryName(String value) {\r
+               String repository = value;\r
                // get the repository name from the url by finding a known url suffix\r
                for (String urlSuffix : suffixes) {\r
                        if (repository.indexOf(urlSuffix) > -1) {\r
@@ -57,6 +56,17 @@ public class GitFilter extends AccessRestrictionFilter {
                return repository;\r
        }\r
 \r
+       /**\r
+        * Extract the repository name from the url.\r
+        * \r
+        * @param url\r
+        * @return repository name\r
+        */\r
+       @Override\r
+       protected String extractRepositoryName(String url) {\r
+               return GitFilter.getRepositoryName(url);\r
+       }\r
+\r
        /**\r
         * Analyze the url and returns the action of the request. Return values are\r
         * either "/git-receive-pack" or "/git-upload-pack".\r
index 0b5575bc909085178c85da49138848ebd11db2ed..d81703d02ea748ef31dbb4400fe9a7bd38a6edb3 100644 (file)
@@ -51,7 +51,6 @@ import org.slf4j.LoggerFactory;
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ClientLogger;\r
-import com.gitblit.utils.FileUtils;\r
 import com.gitblit.utils.HttpUtils;\r
 import com.gitblit.utils.StringUtils;\r
 \r
@@ -94,9 +93,16 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
                        @Override\r
                        public ReceivePack create(HttpServletRequest req, Repository db)\r
                                        throws ServiceNotEnabledException, ServiceNotAuthorizedException {\r
-                               ReceivePack rp = super.create(req, db);\r
+                               \r
+                               // determine repository name from request\r
+                               String repositoryName = req.getPathInfo().substring(1);\r
+                               repositoryName = GitFilter.getRepositoryName(repositoryName);\r
+                               \r
                                GitblitReceiveHook hook = new GitblitReceiveHook();\r
+                               hook.repositoryName = repositoryName;\r
                                hook.gitblitUrl = HttpUtils.getGitblitURL(req);\r
+\r
+                               ReceivePack rp = super.create(req, db);\r
                                rp.setPreReceiveHook(hook);\r
                                rp.setPostReceiveHook(hook);\r
                                return rp;\r
@@ -158,6 +164,8 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
 \r
                protected final Logger logger = LoggerFactory.getLogger(GitblitReceiveHook.class);\r
 \r
+               protected String repositoryName;\r
+               \r
                protected String gitblitUrl;\r
 \r
                /**\r
@@ -167,7 +175,7 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
                 */\r
                @Override\r
                public void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {\r
-                       RepositoryModel repository = getRepositoryModel(rp);\r
+                       RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName);\r
                        Set<String> scripts = new LinkedHashSet<String>();\r
                        scripts.addAll(GitBlit.self().getPreReceiveScriptsInherited(repository));\r
                        scripts.addAll(repository.preReceiveScripts);\r
@@ -195,7 +203,7 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
                                logger.info("skipping post-receive hooks, no refs created, updated, or removed");\r
                                return;\r
                        }\r
-                       RepositoryModel repository = getRepositoryModel(rp);\r
+                       RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName);\r
                        Set<String> scripts = new LinkedHashSet<String>();\r
                        scripts.addAll(GitBlit.self().getPostReceiveScriptsInherited(repository));\r
                        scripts.addAll(repository.postReceiveScripts);\r
@@ -206,19 +214,6 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
                        // runNativeScript(rp, "hooks/post-receive", commands);\r
                }\r
 \r
-               /**\r
-                * Returns the RepositoryModel for the repository we are pushing into.\r
-                * \r
-                * @param rp\r
-                * @return a RepositoryModel\r
-                */\r
-               protected RepositoryModel getRepositoryModel(ReceivePack rp) {\r
-                       Repository repository = rp.getRepository();\r
-                       String repositoryName = FileUtils.getRelativePath(GitBlit.getRepositoriesFolder(), repository.getDirectory());\r
-                       RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
-                       return model;\r
-               }\r
-\r
                /**\r
                 * Returns the UserModel for the user pushing the changes.\r
                 * \r