268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
# File 'lib/rim/git.rb', line 268
def execute(cmd)
raise "git command has to start with 'git'" unless cmd.start_with? "git "
cmd.slice!("git ")
cmd.gsub!("\n", "")
options = ((!@execute_dir || @execute_dir == ".") ? "" : " -C #{@execute_dir}") \
+ (@work_dir.empty? ? "" : " --work-tree=#{File.expand_path(@work_dir)}") \
+ (@git_dir.empty? ? "" : " --git-dir=#{File.expand_path(@git_dir)}")
cmd = "git#{options} #{cmd} 2>&1"
out = `#{cmd}`
out.force_encoding("binary")
exitstatus = $?.exitstatus
invid = self.class.next_invocation_id.to_s.ljust(4)
@logger.debug "git##{invid} \"#{cmd}\" => #{exitstatus}"
out.split(/\r?\n/).each do |ol|
@logger.debug "git##{invid} out : #{ol}"
end
exception = exitstatus != 0 ? GitException.new(cmd, exitstatus, out) : nil
if block_given?
yield out, exception
elsif exception
raise exception
end
out
end
|