ericpaulbishop / redmine_git_hosting

A ChiliProject/Redmine plugin which makes configuring your own git hosting easy.
186 stars 37 forks source link

smart http using lighttpd and gitolite #144

Closed jchnkl closed 12 years ago

jchnkl commented 12 years ago

Hi,

I'm not quite sure if I got it right, but as I understand it I have to set up smart http using git-http-backend. Long story short, pulling works using a wrapper script which calls sudo -u git -E git-http-backend. However, I'm not able to push to the url in question, since lighttpd seems to mess up the http headers so that git falls back to webdav which obviously won't work.

Since gitolite also supports smart http one could add the login name to the gitolite user list and use that for pushing. At least when I tried it that way it worked. However, the usernames I added by hand were removed by the plugin.

Is there anything else I could try?

kubitron commented 12 years ago

The smartHTTP functionality is built into the plugin, i.e. it goes through redmine/rails, not through git-http-backend or gitolite. Once you have installed the plugin, you shouldn't have to do anything else.

The top of the repositories page shows the http link that you would use for this functionality...

jchnkl commented 12 years ago

Oh snap.. Wasted two days fiddling with git-http-backend and/or gl-auth-command. Now it turns out it's as easy as snipping with my fingers.. Works like a charm thanks for your reply!

I've got two other (minor) issues though: I'm using usernames in the form "user@host" so the url looks something like "http://user@host@redminehost.com/..". Obviously git doesn't handle this correctly. This can be resolved by replacing the @ in the login with "%40": "http://user%40host@redminehost.com/..". It would be great if that would happen automatically.

The other issue I had was that I had to install a soft link from ${REDMINEROOT}/vendor/plugins/redmine_git_hosting/assets to ${REDMINEROOT}/public/plugin_assets

Thanks again and best wishes!

kubitron commented 12 years ago

A couple of things. (1) If you have a bunch of users, I'd suggest using my version of the plugin since it is more stable.

https://github.com/kubitron/redmine_git_hosting/

(2) as for the "@" in the username, I believe that you need to do what you already did, namely use the "%40", since the username is parsed by parts of the system before redmine takes control. I have a similar problem on one of my sites and have been planning to alter the URL box to at least be correct (replace the @ with %40) so that users know what they need to do. I'll do that sometime soon and post to my master branch.

(3) You shouldn't make that link. Redmine copies those assets from the plugins directories into the public/plugin_assets directory at every reboot of the service. Thus, public/plugin_assets always contains copies of files from various plugin source trees.

jchnkl commented 12 years ago

Hi,

sorry, I didn't realize that you roll your own version. After looking at the github generated fork graph it seems to me that yours is even the initial version. I wonder why it says "fork from ericpaulbishop" then..

However, installed it and it runs just fine, thanks a lot!

I didn't have to make that link again (although the plugin_assets directory was missing), but I had to change ownership to www-data:www-data since Debian installs redmine in /usr/share/redmine as root:root.

Concerning the username issue: I have a (very) quick fix here. Please forgive me for posting this here, but I'm not too much into github and it's a two-liner anyway..

diff --git a/app/views/projects/_git_urls.erb b/app/views/projects/_git_urls.erb
index fa9c438..b2ba668 100644
--- a/app/views/projects/_git_urls.erb
+++ b/app/views/projects/_git_urls.erb
@@ -14,7 +14,7 @@
                        guSshURL = "<%= GitHosting.git_access_url(project)+'.git' %>";
                        guHttpURL = "<%= GitHosting.http_access_url(project)+'.git' %>";
                        guProjectIsPublic= <%= project.is_public.to_s %> ;
-                       guUser= "<%= User.current.login %>";
+                       guUser= "<%= User.current.login.sub("@", "%40") %>";
                        guUserIsCommitter= <%= User.current.allowed_to?(:commit_access, project) ? "true" : "false" %> ;
                        guGitUser="<%= Setting.plugin_redmine_git_hosting['gitUser'] %>";
                        guGitServer="<%= Setting.plugin_redmine_git_hosting['gitServer'] %>";
diff --git a/app/views/repositories/_git_urls.erb b/app/views/repositories/_git_urls.erb
index d1666a6..f4693da 100644
--- a/app/views/repositories/_git_urls.erb
+++ b/app/views/repositories/_git_urls.erb
@@ -14,7 +14,7 @@
                        guSshURL = "<%= GitHosting.git_access_url(project)+'.git' %>";
                        guHttpURL = "<%= GitHosting.http_access_url(project)+'.git' %>";
                        guProjectIsPublic= <%= project.is_public.to_s %> ;
-                       guUser= "<%= User.current.login %>";
+                       guUser= "<%= User.current.login.sub("@", "%40") %>";
                        guUserIsCommitter= <%= User.current.allowed_to?(:commit_access, project) ? "true" : "false" %> ;
                        guGitUser="<%= Setting.plugin_redmine_git_hosting['gitUser'] %>";
                        guGitServer="<%= Setting.plugin_redmine_git_hosting['gitServer'] %>";
kubitron commented 12 years ago

I'm certainly not the original writer. I've just updated things for reliability over the last couple of months because I needed a stable base for my users.

Your patch is essentially what I was going to do (although I was actually going to use functions to make the resulting login html-safe, in case there were other illegal characters).

An alternative, which I was considering (since "%40" is a bit ugly) was to support an authentication substitution such as:

foo@bar.com@baz.com => foo_bar.com@baz.com

This would require altercation of the smart authentication code (which is easily doable).

Comments?

jchnkl commented 12 years ago

According to [1] "%40" is the official url encoding for an @. That will give you best compatibility and work always (who knows, maybe there's some internal git parsing..) What's more you will get in trouble with usernames which have an underscore (_) in it like: "John_the_best_coder". You'd have to do some pretty elaborate guessing to figure out the host part of this username. But enough of my objections, you're the boss. :)

[1] http://www.w3schools.com/tags/ref_urlencode.asp

kubitron commented 12 years ago

Yup. I'm familiar with [1]. If I allowed a translation, it would be selectable with some sort of option.

It is true that some guessing would be involved, but that would actually be a regular expression that could benefit from some caching.... Probably not worth it, but who knows...

kubitron commented 12 years ago

Ok. I've pushed a slightly more general fix than you suggested to my master repo:

https://github.com/kubitron/redmine_git_hosting/

Give it a shot.

kubitron commented 12 years ago

p.s. I'm going to close this bug out, since the original question was resolved. IF you decide to use my master branch, please post future bugs there. (I may or may not keep responding here on this project page).

kubitron commented 12 years ago

Oops. Guess you have to close this one out. Why don't you do that?

jchnkl commented 12 years ago

Hi,

just wanted to give you the possibility to reply. :) Your solution looks indeed very good, I didn't know that there's a js function for this. For the moment I'm sticking to your master branch and will certainly report any issues there.

Thanks again for your great help and closing this now.