module Patches::Git::Lib
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/ext/git_ext.rb, line 22 def initialize(*args) super # @logger = Logger.new(STDOUT) end
Public Instance Methods
clone_without_env(repository, name, opts = {})
click to toggle source
# File lib/ext/git_ext.rb, line 47 def clone_without_env(repository, name, opts = {}) @path = opts[:path] || '.' clone_dir = opts[:path] ? File.join(@path, name) : name arr_opts = [] arr_opts << '--bare' if opts[:bare] arr_opts << '--branch' << opts[:branch] if opts[:branch] arr_opts << '--depth' << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0 arr_opts << '--config' << opts[:gitl_config] if opts[:gitl_config] arr_opts << '--origin' << opts[:remote] || opts[:origin] if opts[:remote] || opts[:origin] arr_opts << '--recursive' if opts[:recursive] arr_opts << "--mirror" if opts[:mirror] arr_opts << '--' arr_opts << repository arr_opts << clone_dir command_without_env('clone', arr_opts) (opts[:bare] or opts[:mirror]) ? {:repository => clone_dir} : {:working_directory => clone_dir} end
command_without_env(cmd, opts = [], chdir = true, redirect = '', &block)
click to toggle source
# File lib/ext/git_ext.rb, line 70 def command_without_env(cmd, opts = [], chdir = true, redirect = '', &block) global_opts = [] global_opts << "--git-dir=#{@git_dir}" if !@git_dir.nil? global_opts << "--work-tree=#{@git_work_dir}" if !@git_work_dir.nil? opts = [opts].flatten.map {|s| escape(s) }.join(' ') global_opts = global_opts.flatten.map {|s| escape(s) }.join(' ') git_cmd = "#{::Git::Base.config.binary_path} #{global_opts} #{cmd} #{opts} #{redirect} 2>&1" output = nil command_thread = nil; exitstatus = nil command_thread = Thread.new do output = run_command(git_cmd, &block) exitstatus = $?.exitstatus end command_thread.join if @logger @logger.info(git_cmd) @logger.debug(output) end if exitstatus > 1 || (exitstatus == 1 && output != '') raise Git::GitExecuteError.new(git_cmd + ':' + output.to_s) end return output end
ls_files(location=nil)
click to toggle source
Calls superclass method
# File lib/ext/git_ext.rb, line 27 def ls_files(location=nil) #git bug, git diff-files结果不对,先执行git status后正确 command_lines("status") super end
run_command(git_cmd, &block)
click to toggle source
# File lib/ext/git_ext.rb, line 33 def run_command(git_cmd, &block) git_cmd = git_cmd.gsub(/2>&1$/, '') return IO.popen(git_cmd, &block) if block_given? `#{git_cmd}`.chomp end
track(remote, branch)
click to toggle source
# File lib/ext/git_ext.rb, line 40 def track(remote, branch) arr_opts = [] arr_opts << '-u' arr_opts << "#{remote}/#{branch}" command('branch', arr_opts) end