lib/minigit.rb in minigit-0.0.3 vs lib/minigit.rb in minigit-0.0.4

- old
+ new

@@ -18,20 +18,28 @@ def git(*args) _myself.git(*args) end + def [](arg) + _myself[arg] + end + + def []=(key, value) + _myself[key] = value + end + protected def _myself @myself ||= self.new end end class GitError < RuntimeError attr_reader :command, :status, :info - def initialize(command, status, info={}) + def initialize(command=[], status=nil, info={}) @status = status.dup rescue status.to_s @command = command @info = info super("Failed to run git #{command.join(' ')}: #{@status}") end @@ -112,13 +120,14 @@ end rv end def capturing - @capturing ||= Capturing.new(:git_command => @git_command, - :git_dir => @git_dir, - :git_work_tree => @git_work_tree) + @capturing ||= Capturing.new( + :git_command => @git_command, + :git_dir => @git_dir, + :git_work_tree => @git_work_tree) end def noncapturing self end @@ -133,14 +142,31 @@ def capturing self end def noncapturing - @noncapturing ||= MiniGit.new(:git_command => @git_command, - :git_dir => @git_dir, - :git_work_tree => @git_work_tree) + @noncapturing ||= MiniGit.new( + :git_command => @git_command, + :git_dir => @git_dir, + :git_work_tree => @git_work_tree) end end + + def [](arg) + begin + self.capturing.config(arg).strip + rescue MiniGit::GitError + nil + end + end + + def []=(key, value) + begin + self.noncapturing.config(key, value) + rescue MiniGit::GitError + nil + end + end private def with_git_env dir, work_tree = ENV['GIT_DIR'], ENV['GIT_WORK_TREE']