load a local config file

This commit is contained in:
Josh Holtrop 2018-02-27 21:04:33 -05:00
parent 67beb1dece
commit 0330206e55
2 changed files with 36 additions and 2 deletions

View File

@ -1,8 +1,15 @@
require "open3"
module Svi
class Application
def initialize
@config = Config.new
@svn_info = {}
@config = Config.new(self)
end
def wc_info
svn_info(".")
end
def checkout(url)
@ -70,5 +77,20 @@ module Svi
0
end
private
def svn_info(path)
@svn_info[path] ||= begin
info = {}
stdout, stderr, status = Open3.capture3("svn", "info", path)
stdout.lines.each do |line|
if line =~ /^(.*?):\s(.*)$/
info[$1] = $2
end
end
info
end
end
end
end

View File

@ -1,10 +1,12 @@
module Svi
class Config
def initialize
def initialize(application)
@application = application
@ignores = []
load_global_config
load_local_config
end
# Get the ignore patterns.
@ -31,5 +33,15 @@ module Svi
end
end
def load_local_config
if wcrp = @application.wc_info["Working Copy Root Path"]
local_config_path = "#{wcrp}/.svn/svi/config"
if File.exists?(local_config_path)
local_config = File.read(local_config_path)
instance_eval(local_config, local_config_path, 1)
end
end
end
end
end