Method: Git::Base#with_temp_index

Defined in:
lib/git/base.rb

#with_temp_index(&blk) ⇒ Object



453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/git/base.rb', line 453

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