Redmine与Gitblit联动(二)
如果git仓库在本机上就更方便了,不用迁出直接配置成对应的git仓库地址,如果在仓库另一台机子上,则需要如下操作做一个git mirror
新建一个 gitrespo ,然后将所属用户改成www-data以完成权限设定
然后 git clone –mirror
299 sudo mkdir /gitrespo
300 ll
301 cd /gitrespo/
302 mv /gitrespo/ /gitrepos
303 sudo mv /gitrespo/ /gitrepos
304 ll
305 cd ..
306 ll
307 cd /gitrepos/
308 ll
309 chmod -R 777 ./
310 sudo chmod -R 777 ./
311 sudo chown -R www-data:www-data gitrepos
312 sudo chown -R www-data:www-data ./
313 ll
314 sudo -u www-data -H git clone –mirror git://192.168.8.18/FitPose.git
319 cd FitPose.git/
320 git fetch
以上完成了迁出与git mirror操作,接下来就需要在Redmine上进行配置仓库的地址
修改git源代码的 git adapter.rb 主要是以下这段
def branches return @branches if @branches @branches = [] cmd_args = %w|branch --no-color --verbose --no-abbrev| git_cmd(cmd_args) do |io| io.each_line do |line| branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$') next unless branch_rev bran = GitBranch.new(branch_rev[2]) bran.revision = branch_rev[3] bran.scmid = branch_rev[3] bran.is_default = ( branch_rev[1] == '*' ) @branches << bran end end logger.info "1. fetch --all" cmd_args = %w|fetch --all| git_cmd(cmd_args) do |io| logger.info io.readlines end logger.info "2. reset --hard origin" cmd_args = %w|reset --hard origin| git_cmd(cmd_args) do |io| logger.info io.readlines end @branches.sort! rescue ScmCommandAborted nil end
def git_cmd(args, options = {}, &block) repo_path = root_url || url full_args = ['-C', repo_path + '/..', '--git-dir', repo_path] if self.class.client_version_above?([1, 7, 2]) full_args << '-c' << 'core.quotepath=false' full_args << '-c' << 'log.decorate=no' end full_args += args cmdline = self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' ') logger.info cmdline ret = shellout( cmdline, options, &block ) if $? && $?.exitstatus != 0 raise ScmCommandAborted, "git exited with non-zero status: #{$?.exitstatus}" end logger.info "execute end" ret end private :git_cmd
以下是修改后的 git_adapter.rb
git_adapter.rb
修改替换后,重启redmine即可
342 ./ctlscript.sh restart apache