Module: Patches::Git::Lib
- Defined in:
- lib/git_ext.rb
Instance Method Summary collapse
- #clone_without_env(repository, name, opts = {}) ⇒ Object
- #command_without_env(cmd, opts = [], chdir = true, redirect = '', &block) ⇒ Object
- #initialize(*args) ⇒ Object
- #run_command(git_cmd, &block) ⇒ Object
- #track(remote, branch) ⇒ Object
Instance Method Details
#clone_without_env(repository, name, opts = {}) ⇒ Object
| 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | # File 'lib/git_ext.rb', line 41 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) ⇒ Object
| 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | # File 'lib/git_ext.rb', line 64 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 | 
#initialize(*args) ⇒ Object
| 22 23 24 25 | # File 'lib/git_ext.rb', line 22 def initialize(*args) super # @logger = Logger.new(STDOUT) end | 
#run_command(git_cmd, &block) ⇒ Object
| 27 28 29 30 31 32 | # File 'lib/git_ext.rb', line 27 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) ⇒ Object
| 34 35 36 37 38 39 | # File 'lib/git_ext.rb', line 34 def track(remote, branch) arr_opts = [] arr_opts << '-u' arr_opts << "#{remote}/#{branch}" command('branch', arr_opts) end |