@@ -4,128 +4,18 @@ module RedmineGitHosting
4
4
module Patches
5
5
module GrackServerPatch
6
6
7
- # Override original *get_git_dir * method because the path is relative
8
- # and accessed via Sudo.
9
- #
10
- def get_git_dir ( path )
7
+ # Override original *get_git * method to set the right path for the repository.
8
+ # Also pass the *@env['REMOTE_USER']* variable to the Git constructor so we
9
+ # can pass it to Gitolite hooks later.
10
+ def get_git ( path )
11
11
path = gitolite_path ( path )
12
- if !directory_exists? ( path )
13
- false
14
- else
15
- path # TODO: check is a valid git directory
16
- end
17
- end
18
-
19
-
20
- # Override original *git_command* method to prefix the command with Sudo and other args.
21
- #
22
- def git_command ( params )
23
- git_command_with_sudo ( params )
12
+ Grack ::Git . new ( @config [ :git_path ] , path , @env [ 'REMOTE_USER' ] )
24
13
end
25
14
26
-
27
- # Override original *capture* method because the original IO.popen().read let zombie process behind.
28
- #
29
- # This method is called :
30
- # * to get repository Git config (http.uploadpack || http.receivepack)
31
- # * to get repository info refs :
32
- # 0087deab8f3d612a47e7e153ed21bbc52a480205035a refs/heads/devel report-status delete-refs side-band-64k quiet ofs-delta agent=git/1.9.1
33
- # * to get repository refs :
34
- # 003f91a7b1dad21020e96d52119c585881c02f2fae45 refs/heads/master
35
- #
36
- # Note : *service_rpc* also calls IO.popen but pass a block !.
37
- # Passing a block to IO.popen auto-close the pipe/thread.
38
- #
39
- def capture ( command )
40
- # Extract Args
41
- cmd = command . shift
42
- args = command
43
-
44
- begin
45
- RedmineGitHosting ::Utils ::Exec . capture ( cmd , args )
46
- rescue => e
47
- logger . error ( 'Problems while getting SmartHttp params' )
48
- end
49
- end
50
-
51
-
52
- # Override original *popen_options* method.
53
- # The original one try to chdir before executing the command by
54
- # passing 'chdir: @dir' option to IO.popen.
55
- # This is wrong as we can't chdir to Gitolite directory.
56
- # Notes : this method is called in *service_rpc* (not overriden)
57
- #
58
- def popen_options
59
- { unsetenv_others : true }
60
- end
61
-
62
-
63
- # Override original *popen_env* method.
64
- # The original one passes useless arg (GL_ID) to IO.popen.
65
- # Notes : this method is called in *service_rpc* (not overriden)
66
- #
67
- def popen_env
68
- { 'PATH' => ENV [ 'PATH' ] }
69
- end
70
-
71
-
72
15
private
73
16
74
-
75
17
def gitolite_path ( path )
76
- File . join ( RedmineGitHosting ::Config . gitolite_global_storage_dir , RedmineGitHosting ::Config . gitolite_redmine_storage_dir , path )
77
- end
78
-
79
-
80
- def directory_exists? ( dir )
81
- RedmineGitHosting ::Commands . sudo_dir_exists? ( dir )
82
- end
83
-
84
-
85
- # We sometimes need to add *--git-dir* arg to Git command otherwise
86
- # Git looks for the repository in the current path.
87
- def git_command_with_sudo ( params )
88
- if command_require_chdir? ( params . last )
89
- git_command_with_chdir . concat ( params )
90
- else
91
- git_command_without_chdir . concat ( params )
92
- end
93
- end
94
-
95
-
96
- def command_require_chdir? ( cmd )
97
- cmd == 'update-server-info' || cmd == 'http.receivepack' || cmd == 'http.uploadpack'
98
- end
99
-
100
-
101
- def git_command_without_chdir
102
- RedmineGitHosting ::Commands . sudo_git_cmd ( smart_http_args )
103
- end
104
-
105
-
106
- def git_command_with_chdir
107
- RedmineGitHosting ::Commands . sudo_git_args_for_repo ( @dir , smart_http_args )
108
- end
109
-
110
-
111
- def smart_http_args
112
- [
113
- 'env' ,
114
- "GL_BINDIR=#{ RedmineGitHosting ::Config . gitolite_bin_dir } " ,
115
- "GL_LIBDIR=#{ RedmineGitHosting ::Config . gitolite_lib_dir } " ,
116
- "GL_REPO=#{ repository_object . gitolite_repository_name } " ,
117
- "GL_USER=#{ @env [ 'REMOTE_USER' ] } "
118
- ]
119
- end
120
-
121
-
122
- def logger
123
- RedmineGitHosting . logger
124
- end
125
-
126
-
127
- def repository_object
128
- @repo ||= Repository ::Xitolite . find_by_path ( @dir , loose : true )
18
+ File . join ( RedmineGitHosting ::Config . gitolite_home_dir , RedmineGitHosting ::Config . gitolite_global_storage_dir , RedmineGitHosting ::Config . gitolite_redmine_storage_dir , path )
129
19
end
130
20
131
21
end
0 commit comments