lib/tmp-repo.rb in tmp-repo-1.0.0 vs lib/tmp-repo.rb in tmp-repo-1.0.1
- old
+ new
@@ -4,17 +4,23 @@
require 'pathname'
require 'fileutils'
require 'securerandom'
class TmpRepo
+ DEFAULT_GIT_EXECUTABLE = 'git'
+
class GitError < StandardError; end
attr_reader :working_dir
- def initialize
+ def self.random_dir
+ File.join(Dir.tmpdir, SecureRandom.hex(16))
+ end
+
+ def initialize(dir = nil)
@working_dir = Pathname(
- File.join(Dir.tmpdir, SecureRandom.hex(16))
+ dir || self.class.random_dir
)
FileUtils.mkdir_p(working_dir)
git('init')
end
@@ -60,11 +66,11 @@
parse_status(git('status'))
end
def git(command)
in_repo do
- output = `git #{command}`
+ output = `#{git_executable} #{command}`
if $?.exitstatus != 0
raise GitError, output
end
@@ -77,9 +83,13 @@
yield
end
end
private
+
+ def git_executable
+ DEFAULT_GIT_EXECUTABLE
+ end
def parse_status(status_text)
lines = status_text.split("\n")
status_hash = create_status_hash
statuses = possible_statuses_from(status_hash)