class GitThin::Config

Public Class Methods

new(argv) click to toggle source
Calls superclass method GitThin::Thin::new
# File lib/git-thin/command/thin_config.rb, line 149
def initialize(argv)
    super
    @pwd = Dir.pwd
    @types = []
    @configs = {}
    @source_root = argv.option('source_root')
    @store = argv.flag?('store')
    @list = argv.flag?('list')
    @current = argv.flag?('current')
    @reset = argv.flag?('reset')
    @check = argv.flag?('check')

    if not @source_root
        run_shell 'git rev-parse --show-toplevel',false ,LOGNone do |out,err,status|
            if status == 0
                @source_root = out[0].strip
            end
        end

        if not File.exist? @source_root+'/.git'
            UI.puts "git repository not found"
            exit 1
        end
    else
        if @source_root[-1] == '/'
            @source_root = @source_root[0..-2 ]
        end
    end
    if not Dir.exist? @source_root
        @source_root = nil
        return
    end
    if FileTest.exist? @source_root+'/.thinconfig'
        run_shell "git config -lf #{@source_root}/.thinconfig",true ,true do |out,err,status|
            @configs = ThinConfig.prase_config out
        end
    end
    @types =ThinConfig.prase_type_config  argv,@configs
end
options() click to toggle source
Calls superclass method
# File lib/git-thin/command/thin_config.rb, line 139
def self.options
    [
      ['--source_root', 'Specify the warehouse address manually if necessary.'],
      ['--store', 'Store config to lfs'],
      ['--list', 'List the configs supported by the locally repository, (configured by.thinconfig) '],
      ['--current', 'Displays the current configuration'],
      ['--reset', 'Reset config to thin and lfs'],
      ['--check', 'Check the integrity of the config'],
    ].concat(super)
end

Public Instance Methods

check() click to toggle source
# File lib/git-thin/command/thin_config.rb, line 279
def check
    lfs_files = []
    run_shell "git lfs ls-files",false ,LOGNone do |outs,errs,status|
        if status
            for line in outs
                line[13..-2]
                lfs_files.push line[13..-2]
            end
        end
    end
    unmatch_files = []
    for lfs_file in lfs_files

        if match_config(lfs_file).nil?
            unmatch_files.push lfs_file
        end
    end
    if unmatch_files.length > 0
        logN 'The following LFS files are not configured:'
        for unmatch_file in unmatch_files
            logW unmatch_file
        end
    else
        logN 'All LFS files are configured'
    end
end
current() click to toggle source
# File lib/git-thin/command/thin_config.rb, line 245
def current

    types = ThinConfig::prase_pwd_config(@configs,@source_root,@pwd)
    if types.length == 0
        types.push ThinConfig::DEFAULT
    end
    for type in types
        config = @configs[type]
        if type == ThinConfig::DEFAULT
            git_config
            config = @git_configs[ThinConfig::DEFAULT]
        end
        if config
            logN "name:#{type}  lfs:#{config.getValue('lfs')}"
        end
    end
end
git_config() click to toggle source
# File lib/git-thin/command/thin_config.rb, line 194
def git_config
    if not @git_configs
        run_shell 'git config -l',true ,true do |outs,errs,status|
            @git_configs = ThinConfig.prase_config outs
        end
    end
end
list() click to toggle source
# File lib/git-thin/command/thin_config.rb, line 222
def list
    logN 'List the configs supported by the locally repository: '
    git_config
    config = @git_configs[ThinConfig::DEFAULT]
    if config
        log = "name:#{config.name}"
        for key in config.keys
            log += " #{key}:#{config.getValue key}"
        end
        logN log
    end
    for config in @configs.values
        log = "name:#{config.name}"
        for key in config.keys
            log += " #{key}:#{config.getValue key}"
        end
        logN log
    end
end
match_config(match_file) click to toggle source
# File lib/git-thin/command/thin_config.rb, line 263
def match_config(match_file)
    for config in @configs.values
        lfs = config.getValue 'lfs'
        if lfs
            lfs = lfs.map do|file|
                file.strip
            end
            for lf in lfs
                if match_file.index(lf) == 0
                    return config
                end
            end
        end
    end
    return nil
end
reset() click to toggle source
# File lib/git-thin/command/thin_config.rb, line 241
def reset
    run_shell "git config --unset thin.#{ThinConfig::DEFAULT} ",true ,true
    run_shell "git config --unset lfs.fetchinclude ",true ,true
end
run() click to toggle source
# File lib/git-thin/command/thin_config.rb, line 305
def run
    Dir.chdir @source_root
    if @list
        list
    elsif @reset
        reset
    elsif @current
        current
    elsif @check
        check
    else
        values = run_config
        if values.length > 0
            logN "git config thin.#{ThinConfig::DEFAULT} "+values.join(",")
        else
            logW "not match analyze config"
        end
    end
    Dir.chdir @pwd
end
run_config() click to toggle source
# File lib/git-thin/command/thin_config.rb, line 201
def run_config
    values=[]
    for type in @types
        config = @configs[type]
        if type == ThinConfig::DEFAULT
            git_config
            config = @git_configs[ThinConfig::DEFAULT]
        end
        if config
            values.push config.getValue('lfs')
        end
    end
    if values.length > 0
        run_shell "git config thin.#{ThinConfig::DEFAULT} "+values.join(','),true ,true
        if @store
            run_shell "git config lfs.fetchinclude "+values.join(',')
        end
    end
    return values
end
validate!() click to toggle source
Calls superclass method
# File lib/git-thin/command/thin_config.rb, line 189
def validate!
    super
    help! 'validate SOURCE_ROOT is required' unless @source_root
end