New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception loading if repository folder contains symlinks to repositories #412

Closed
gitblit opened this Issue Aug 12, 2015 · 13 comments

Comments

Projects
None yet
2 participants
@gitblit
Owner

gitblit commented Aug 12, 2015

Originally reported on Google Code with ID 116

Steps:
1. Create a folder Repos
2. In Repos create a symlink to an existing git repository
3. Point.git.repositoriesFolder to Repos in gitplit.properties
4. Try to view the repositories in the browser

GitBlit Version 1.0.0

Stacktrace:
ERROR Can't instantiate page using constructor public com.gitblit.wicket.pages.RepositoriesPage()
org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor
public com.gitblit.wicket.pages.RepositoriesPage()
        at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:212)
        at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:57)
        at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:298)
        at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:320)
        at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:234)
        at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
        at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1279)
        at org.apache.wicket.RequestCycle.step(RequestCycle.java:1358)
        at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1465)
        at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
        at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
        at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:476)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:225)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:937)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:871)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
        at org.eclipse.jetty.server.Server.handle(Server.java:346)
        at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:589)
        at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1048)
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:601)
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
        at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)
        at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
        at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:192)
        ... 32 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at java.lang.String.charAt(String.java:694)
        at com.gitblit.utils.StringUtils.getRelativePath(StringUtils.java:316)
        at com.gitblit.utils.FileUtils.getRelativePath(FileUtils.java:229)
        at com.gitblit.utils.JGitUtils.getRepositoryList(JGitUtils.java:319)
        at com.gitblit.utils.JGitUtils.getRepositoryList(JGitUtils.java:286)
        at com.gitblit.GitBlit.getRepositoryList(GitBlit.java:743)
        at com.gitblit.GitBlit.getRepositoryModels(GitBlit.java:804)
        at com.gitblit.wicket.pages.RootPage.getRepositoryFilterItems(RootPage.java:234)
        at com.gitblit.wicket.pages.RepositoriesPage.addDropDownMenus(RepositoriesPage.java:101)
        at com.gitblit.wicket.pages.RootPage.setupPage(RootPage.java:115)
        at com.gitblit.wicket.pages.RepositoriesPage.setup(RepositoriesPage.java:63)
        at com.gitblit.wicket.pages.RepositoriesPage.<init>(RepositoriesPage.java:49)
        ... 37 more

Reported by andrejs.jermakovics on 2012-07-25 14:58:04

@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner

Reported by James.Moger on 2012-07-25 21:49:53

  • Status changed: Accepted
  • Labels added: Milestone-1.0.1
Owner

gitblit commented Aug 12, 2015

Reported by James.Moger on 2012-07-25 21:49:53

  • Status changed: Accepted
  • Labels added: Milestone-1.0.1
@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
I believe this is fixed on master.  I have updated the demo site with the latest snapshot
and created symlinks to existing repositories.  You are welcome to build from source
to determine if I have fixed your issue.

Reported by James.Moger on 2012-08-02 01:31:33

  • Status changed: Queued
Owner

gitblit commented Aug 12, 2015

I believe this is fixed on master.  I have updated the demo site with the latest snapshot
and created symlinks to existing repositories.  You are welcome to build from source
to determine if I have fixed your issue.

Reported by James.Moger on 2012-08-02 01:31:33

  • Status changed: Queued
@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
Indeed, repository listing now works in master however there's an exception pushing
changes to a symlinked repo. Works for non-symlinked:
java.lang.NullPointerException
        at org.eclipse.jgit.transport.resolver.FileResolver.isUnreasonableName(FileResolver.java:237)
        at org.eclipse.jgit.transport.resolver.FileResolver.open(FileResolver.java:96)
        at com.gitblit.GitBlit.getRepository(GitBlit.java:771)
        at com.gitblit.GitBlit.getRepository(GitBlit.java:758)
        at com.gitblit.GitBlit.getRepositoryModel(GitBlit.java:863)
        at com.gitblit.GitServlet$GitblitReceiveHook.getRepositoryModel(GitServlet.java:218)
        at com.gitblit.GitServlet$GitblitReceiveHook.onPreReceive(GitServlet.java:170)
        at org.eclipse.jgit.transport.ReceivePack.service(ReceivePack.java:179)
        at org.eclipse.jgit.transport.ReceivePack.receive(ReceivePack.java:142)
        at org.eclipse.jgit.http.server.ReceivePackServlet.doPost(ReceivePackServlet.java:174)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
        at org.eclipse.jgit.http.server.glue.UrlPipeline$Chain.doFilter(UrlPipeline.java:237)
        at org.eclipse.jgit.http.server.ReceivePackServlet$Factory.doFilter(ReceivePackServlet.java:139)
        at org.eclipse.jgit.http.server.glue.UrlPipeline$Chain.doFilter(UrlPipeline.java:235)
        at org.eclipse.jgit.http.server.RepositoryFilter.doFilter(RepositoryFilter.java:151)
        at org.eclipse.jgit.http.server.glue.UrlPipeline$Chain.doFilter(UrlPipeline.java:235)
        at org.eclipse.jgit.http.server.NoCacheFilter.doFilter(NoCacheFilter.java:80)
        at org.eclipse.jgit.http.server.glue.UrlPipeline$Chain.doFilter(UrlPipeline.java:235)
        at org.eclipse.jgit.http.server.glue.UrlPipeline.service(UrlPipeline.java:215)
        at org.eclipse.jgit.http.server.glue.SuffixPipeline.service(SuffixPipeline.java:101)
        at org.eclipse.jgit.http.server.glue.MetaFilter.doFilter(MetaFilter.java:163)
        at org.eclipse.jgit.http.server.glue.MetaServlet.service(MetaServlet.java:133)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1352)
        at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:294)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323)
        at com.gitblit.AccessRestrictionFilter.doFilter(AccessRestrictionFilter.java:184)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323)
    ...

Reported by andrejs.jermakovics on 2012-08-07 08:45:23

Owner

gitblit commented Aug 12, 2015

Indeed, repository listing now works in master however there's an exception pushing
changes to a symlinked repo. Works for non-symlinked:
java.lang.NullPointerException
        at org.eclipse.jgit.transport.resolver.FileResolver.isUnreasonableName(FileResolver.java:237)
        at org.eclipse.jgit.transport.resolver.FileResolver.open(FileResolver.java:96)
        at com.gitblit.GitBlit.getRepository(GitBlit.java:771)
        at com.gitblit.GitBlit.getRepository(GitBlit.java:758)
        at com.gitblit.GitBlit.getRepositoryModel(GitBlit.java:863)
        at com.gitblit.GitServlet$GitblitReceiveHook.getRepositoryModel(GitServlet.java:218)
        at com.gitblit.GitServlet$GitblitReceiveHook.onPreReceive(GitServlet.java:170)
        at org.eclipse.jgit.transport.ReceivePack.service(ReceivePack.java:179)
        at org.eclipse.jgit.transport.ReceivePack.receive(ReceivePack.java:142)
        at org.eclipse.jgit.http.server.ReceivePackServlet.doPost(ReceivePackServlet.java:174)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
        at org.eclipse.jgit.http.server.glue.UrlPipeline$Chain.doFilter(UrlPipeline.java:237)
        at org.eclipse.jgit.http.server.ReceivePackServlet$Factory.doFilter(ReceivePackServlet.java:139)
        at org.eclipse.jgit.http.server.glue.UrlPipeline$Chain.doFilter(UrlPipeline.java:235)
        at org.eclipse.jgit.http.server.RepositoryFilter.doFilter(RepositoryFilter.java:151)
        at org.eclipse.jgit.http.server.glue.UrlPipeline$Chain.doFilter(UrlPipeline.java:235)
        at org.eclipse.jgit.http.server.NoCacheFilter.doFilter(NoCacheFilter.java:80)
        at org.eclipse.jgit.http.server.glue.UrlPipeline$Chain.doFilter(UrlPipeline.java:235)
        at org.eclipse.jgit.http.server.glue.UrlPipeline.service(UrlPipeline.java:215)
        at org.eclipse.jgit.http.server.glue.SuffixPipeline.service(SuffixPipeline.java:101)
        at org.eclipse.jgit.http.server.glue.MetaFilter.doFilter(MetaFilter.java:163)
        at org.eclipse.jgit.http.server.glue.MetaServlet.service(MetaServlet.java:133)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:538)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1352)
        at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:294)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323)
        at com.gitblit.AccessRestrictionFilter.doFilter(AccessRestrictionFilter.java:184)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323)
    ...

Reported by andrejs.jermakovics on 2012-08-07 08:45:23

@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
I'll setup a test to debug pushing.  In the meantime, perhaps you could inject something
like the following @ line 217 of com.gitblit.GitServlet:

try {
  System.out.println(GitBlit.getRepositoriesFolder());
  System.out.println(GitBlit.getRepositoriesFolder().getCanonicalPath());
  System.out.println(repository.getDirectory());
} catch (IOException e) {
  e.printStackTrace();
}

And then push.  The code is attempting to find the model class for the repository from
it's filesystem path.  This is the reverse of what we usually do, map a model class
to a directory.

Reported by James.Moger on 2012-08-07 12:36:46

  • Status changed: Started
Owner

gitblit commented Aug 12, 2015

I'll setup a test to debug pushing.  In the meantime, perhaps you could inject something
like the following @ line 217 of com.gitblit.GitServlet:

try {
  System.out.println(GitBlit.getRepositoriesFolder());
  System.out.println(GitBlit.getRepositoriesFolder().getCanonicalPath());
  System.out.println(repository.getDirectory());
} catch (IOException e) {
  e.printStackTrace();
}

And then push.  The code is attempting to find the model class for the repository from
it's filesystem path.  This is the reverse of what we usually do, map a model class
to a directory.

Reported by James.Moger on 2012-08-07 12:36:46

  • Status changed: Started
@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
Tried it and the output for these calls appears correct:
  GitBlit.getRepositoriesFolder(): /srv/git
  GitBlit.getRepositoriesFolder().getCanonicalPath(): /srv/git
  repository.getDirectory(): /home/gitdaemon/test

But 'repositoryName' becomes null on this line and that seems to cause the problem:
  String repositoryName = FileUtils.getRelativePath(...)

Notes: '/srv/git' is my git repository folder. It has a symlink called 'test' that
points to '/home/gitdaemon/test'

Reported by andrejs.jermakovics on 2012-08-07 12:55:44

Owner

gitblit commented Aug 12, 2015

Tried it and the output for these calls appears correct:
  GitBlit.getRepositoriesFolder(): /srv/git
  GitBlit.getRepositoriesFolder().getCanonicalPath(): /srv/git
  repository.getDirectory(): /home/gitdaemon/test

But 'repositoryName' becomes null on this line and that seems to cause the problem:
  String repositoryName = FileUtils.getRelativePath(...)

Notes: '/srv/git' is my git repository folder. It has a symlink called 'test' that
points to '/home/gitdaemon/test'

Reported by andrejs.jermakovics on 2012-08-07 12:55:44

@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
Yup.  I just thought of that kinda of layout while I was out for a few minutes.  My
current push design is a complete failure for symlinks.  My code tries to find a relationship
between those two paths and there is none for already resolved symlinks.

This will require a different design to get the repository model or perhaps I can cache
the model earlier during the request.  This wasn't a great design anyways - but it
worked within the constraints of JGit.

I'll let you know when I have code for you to test.

Reported by James.Moger on 2012-08-07 13:05:32

Owner

gitblit commented Aug 12, 2015

Yup.  I just thought of that kinda of layout while I was out for a few minutes.  My
current push design is a complete failure for symlinks.  My code tries to find a relationship
between those two paths and there is none for already resolved symlinks.

This will require a different design to get the repository model or perhaps I can cache
the model earlier during the request.  This wasn't a great design anyways - but it
worked within the constraints of JGit.

I'll let you know when I have code for you to test.

Reported by James.Moger on 2012-08-07 13:05:32

@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
I tried a small workaround and it seems to solve the issue. In GitblitReceiveHook:
        protected RepositoryModel getRepositoryModel(ReceivePack rp) {
            Repository repository = rp.getRepository();
            return GitBlit.self().getRepositoryModel(repository.getDirectory().getName(), repository);
        }

I added the GitBlit.getRepositoryModel method that takes a repository and does not
look it up.


Reported by andrejs.jermakovics on 2012-08-07 13:40:13

Owner

gitblit commented Aug 12, 2015

I tried a small workaround and it seems to solve the issue. In GitblitReceiveHook:
        protected RepositoryModel getRepositoryModel(ReceivePack rp) {
            Repository repository = rp.getRepository();
            return GitBlit.self().getRepositoryModel(repository.getDirectory().getName(), repository);
        }

I added the GitBlit.getRepositoryModel method that takes a repository and does not
look it up.


Reported by andrejs.jermakovics on 2012-08-07 13:40:13

@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
Ah that would work too.  I just pushed a change which I'd like you to try out.

Reported by James.Moger on 2012-08-07 13:46:31

Owner

gitblit commented Aug 12, 2015

Ah that would work too.  I just pushed a change which I'd like you to try out.

Reported by James.Moger on 2012-08-07 13:46:31

@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
I like your change because it is smaller, but we lose the repository name which is Gitblit's
id for the repo.  This can affect the push hooks which is the main reason we need to
grab the "real" model.  My change determines the repo name from the request and caches
it for re-use in the hooks.  This means that data and downstream behavior is identical
to current release.

Reported by James.Moger on 2012-08-07 13:51:34

Owner

gitblit commented Aug 12, 2015

I like your change because it is smaller, but we lose the repository name which is Gitblit's
id for the repo.  This can affect the push hooks which is the main reason we need to
grab the "real" model.  My change determines the repo name from the request and caches
it for re-use in the hooks.  This means that data and downstream behavior is identical
to current release.

Reported by James.Moger on 2012-08-07 13:51:34

@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
Yepp, push works with the latest fix. We're not using any hooks though so I can't tell
if those are working.
Thanks.

Reported by andrejs.jermakovics on 2012-08-07 14:05:04

Owner

gitblit commented Aug 12, 2015

Yepp, push works with the latest fix. We're not using any hooks though so I can't tell
if those are working.
Thanks.

Reported by andrejs.jermakovics on 2012-08-07 14:05:04

@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
Hook unit tests pass, so I am confident they are working.

Reported by James.Moger on 2012-08-07 14:06:48

  • Status changed: Queued
Owner

gitblit commented Aug 12, 2015

Hook unit tests pass, so I am confident they are working.

Reported by James.Moger on 2012-08-07 14:06:48

  • Status changed: Queued
@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner

Reported by James.Moger on 2012-08-20 02:06:35

  • Labels added: Milestone-1.1.0
  • Labels removed: Milestone-1.0.1
Owner

gitblit commented Aug 12, 2015

Reported by James.Moger on 2012-08-20 02:06:35

  • Labels added: Milestone-1.1.0
  • Labels removed: Milestone-1.0.1
@gitblit

This comment has been minimized.

Show comment
Hide comment
@gitblit

gitblit Aug 12, 2015

Owner
Fix/change released in 1.1.0.

Reported by James.Moger on 2012-08-25 12:20:42

  • Status changed: Fixed
Owner

gitblit commented Aug 12, 2015

Fix/change released in 1.1.0.

Reported by James.Moger on 2012-08-25 12:20:42

  • Status changed: Fixed

@gitblit gitblit closed this Aug 12, 2015

@fzs fzs modified the milestone: 1.1.0 Dec 13, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment