Module: GitThin::Action

Includes:
GitThinUtils
Included in:
Checkout, Fetch, Pull
Defined in:
lib/git-thin/command/action.rb

Constant Summary

Constants included from GitThinUtils

GitThinUtils::LOGA, GitThinUtils::LOGC, GitThinUtils::LOGN, GitThinUtils::LOGNone, GitThinUtils::LOGPRUNE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GitThinUtils

#logC, #logE, #logInner, #logN, #logP, #logW, #print_console, #run_shell, #set_progress

Class Method Details

.argumentsObject



11
12
13
14
15
# File 'lib/git-thin/command/action.rb', line 11

def self.arguments
    [
        CLAide::Argument.new('TYPE', false )
    ]
end

.description(action) ⇒ Object



8
9
10
# File 'lib/git-thin/command/action.rb', line 8

def self.description(action)
    'Consider thin strategy when performing a '+action+' action '
end

.optionsObject



20
21
22
23
24
25
# File 'lib/git-thin/command/action.rb', line 20

def self.options
    [
      ['--source_root', 'Specify the warehouse address manually if necessary.'],
    ].concat(super)

end

.summary(action) ⇒ Object



16
17
18
# File 'lib/git-thin/command/action.rb', line 16

def self.summary(action)
    'Consider thin strategy when performing a '+action+' action '
end

Instance Method Details

#runObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/git-thin/command/action.rb', line 95

def run
    old_config = ''
    run_shell "git -C #{@source_root} config --get lfs.fetchinclude",true ,!@verbose do|outs,errs,status|
        if status == 0 && outs.length > 0
            old_config = outs[0].strip
        end
    end
    run_config
    shell_ret = 0
    run_shell "git -C #{@source_root} #{@action} "+@argv_remainder.join(' '),true ,LOGPRUNE|LOGC do |outs,errs,status|
        shell_ret = status
    end
    run_shell "git -C #{@source_root} lfs #{@action} "+@argv_remainder.join(' '),true ,LOGPRUNE|LOGC
    if old_config.strip == ''
        run_shell 'git config --unset lfs.fetchinclude' ,true ,true

    else
        run_shell 'git config lfs.fetchinclude '+old_config ,true ,true
    end
    if shell_ret != 0
        exit(shell_ret+100)
    end
end

#run_configObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/git-thin/command/action.rb', line 74

def run_config
    values=[]
    for type in @types
        config = @configs[type]
        if type == ThinConfig::DEFAULT &&  !config
            run_shell 'git config -l',true ,true do |outs,errs,status|
                g_configs = ThinConfig.prase_config outs
                config = g_configs[ThinConfig::DEFAULT]
            end
        end
        if config
            value = config.getValue('lfs')
            values.push value
            logN "[thin] platform:#{type} lfs:#{value}",false
        end
    end
    logN "\n",false
    run_shell 'git config lfs.fetchinclude '+values.join(',') ,true ,true
    return values
end

#setup(argv, action) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/git-thin/command/action.rb', line 27

def setup(argv,action)
    @pwd = Dir.pwd
    @action = action
    @types = []
    @configs = {}
    @source_root = argv.option('source_root')
    @verbose = argv.flag?('verbose',false )
    if @verbose
        @verbose = LOGC|LOGN
    end
    if not @source_root
        run_shell 'git rev-parse --show-toplevel',false ,LOGNone do |out,err,status|
            if status == 0 && out.length > 0
                @source_root = out[0].strip
            end
        end

        if !@source_root ||  !File.exist?(@source_root+'/.git')
            logE "git repository not found"
            exit 1
        end
    else
        if @source_root[-1] == '/'
            @source_root = @source_root[0..-2 ]
        end
    end
    if !@source_root || !Dir.exist?(@source_root)
        @source_root = nil
        return
    end
    if FileTest.exist? @source_root+'/.thinconfig'
        run_shell "git config -lf #{@source_root}/.thinconfig",true ,LOGNone do |out,err,status|
            @configs = ThinConfig.prase_config out
        end
    end
    @types =ThinConfig.prase_type_config  argv,@configs,@source_root,@pwd
    @argv_remainder = argv.remainder!
end

#source_rootObject



65
66
67
# File 'lib/git-thin/command/action.rb', line 65

def source_root

end

#validate!Object



69
70
71
72
# File 'lib/git-thin/command/action.rb', line 69

def validate!
    super
    help! 'validate SOURCE_ROOT is required' unless @source_root
end