Method: Git::Base#with_temp_index

Defined in:
lib/git/base.rb

#with_temp_index(&blk) ⇒ Object



464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/git/base.rb', line 464

def with_temp_index &blk
  # Workaround for JRUBY, since they handle the TempFile path different.
  # MUST be improved to be safer and OS independent. 
  if RUBY_PLATFORM == 'java'
    temp_path = "/tmp/temp-index-#{(0...15).map{ ('a'..'z').to_a[rand(26)] }.join}"
  else
    tempfile = Tempfile.new('temp-index')
    temp_path = tempfile.path
    tempfile.close
    tempfile.unlink
  end

  with_index(temp_path, &blk)
end