Class: Pindo::Command::Repo::Subgit

Inherits:
Pindo::Command::Repo show all
Defined in:
lib/pindo/command/repo/subgit.rb

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pindo::Command

command_name, #initialize_options, run, use_cache?

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Constructor Details

#initialize(argv) ⇒ Subgit

Returns a new instance of Subgit.



42
43
44
45
46
47
48
# File 'lib/pindo/command/repo/subgit.rb', line 42

def initialize(argv)

    @force = argv.flag?('force', false)

    super(argv)
    @additional_args = argv.remainder!
end

Class Method Details

.optionsObject



34
35
36
37
38
# File 'lib/pindo/command/repo/subgit.rb', line 34

def self.options
  [
    ['--force', '强制重新初始化子模块(覆盖本地修改)'],
  ].concat(super)
end

Instance Method Details

#runObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/pindo/command/repo/subgit.rb', line 59

def run

    puts "\n"
    puts "=" * 60
    puts "Git 子模块更新".center(60)
    puts "=" * 60
    puts "当前目录: #{Dir.pwd}"
    puts "强制模式: #{@force ? '' : ''}"
    puts "=" * 60
    puts "\n"

    # 调用 GitHandler 的子模块更新方法
    result = Pindo::GitHandler.update_submodules(
      local_repo_dir: Dir.pwd,
      force: @force
    )

    if result
      puts "\n"
      puts "✅ 子模块更新成功完成!".green
      puts "\n"
    else
      puts "\n"
      puts "⚠️  当前仓库没有配置子模块".yellow
      puts "\n"
    end

end

#validate!Object



50
51
52
53
54
55
56
57
# File 'lib/pindo/command/repo/subgit.rb', line 50

def validate!
    super

    # 验证当前目录是否是 Git 仓库
    unless Pindo::GitHandler.is_git_directory?(local_repo_dir: Dir.pwd)
      raise Informative, "当前目录不是有效的 Git 仓库!请在 Git 仓库根目录下执行此命令。"
    end
end