Class: MGit::Clean

Inherits:
BaseCommand show all
Defined in:
lib/m-git/command/clean.rb

Overview

follow git combinatorial command eg: git add . && git reset –hard

Constant Summary

Constants inherited from BaseCommand

BaseCommand::HIGH_PRIORITY_OPT_LIST, BaseCommand::SELECTABLE_OPT_LIST

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

#all_repos, cmd, #exec_light_repos, #generate_config_repo, inherited, #initialize, #locked_repos, #run

Constructor Details

This class inherits a constructor from MGit::BaseCommand

Class Method Details

.descriptionObject



54
55
56
# File 'lib/m-git/command/clean.rb', line 54

def self.description
  "强制清空暂存区和工作区,相当于对指定或所有仓库执行\"git add . && git reset --hard\"操作"
end

.usageObject



58
59
60
# File 'lib/m-git/command/clean.rb', line 58

def self.usage
  "mgit clean [(-m|-e) <repo>...] [-h]"
end

Instance Method Details

#enable_repo_selectionObject



46
47
48
# File 'lib/m-git/command/clean.rb', line 46

def enable_repo_selection
  true
end

#enable_short_basic_optionObject



50
51
52
# File 'lib/m-git/command/clean.rb', line 50

def enable_short_basic_option
  true
end

#execute(argv) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/m-git/command/clean.rb', line 11

def execute(argv)

  Output.puts_start_cmd

  # 清除中间态
  OperationProgressManager::PROGRESS_TYPE.each { |type, type_value|
    if OperationProgressManager.is_in_progress?(Workspace.root, type_value)
      Output.puts_processing_message("清除#{type.to_s}中间态...")
      OperationProgressManager.remove_progress(Workspace.root, type_value)
      Output.puts_success_message("清除成功!")
    end
  }

  do_repos = []
  all_repos.each { |repo|
    do_repos.push(repo) if repo.status_checker.status != Repo::Status::GIT_REPO_STATUS[:clean]
  }

  if do_repos.length > 0
    Workspace.check_branch_consistency
    Output.puts_processing_message("正在将改动加入暂存区...")
    _, error_repos1 = Workspace.execute_git_cmd_with_repos('add', '.', do_repos)
    Output.puts_processing_message("正在重置...")
    _, error_repos2 = Workspace.execute_git_cmd_with_repos('reset', '--hard', do_repos)
    Output.puts_succeed_cmd(argv.absolute_cmd) if error_repos1.length + error_repos2.length == 0
  else
    Output.puts_success_message("所有仓库均无改动,无须执行。")
  end

end

#validate(argv) ⇒ Object



42
43
44
# File 'lib/m-git/command/clean.rb', line 42

def validate(argv)
  Foundation.help!("输入非法参数:#{argv.git_opts}。请通过\"mgit #{argv.cmd} --help\"查看用法。") if argv.git_opts.length > 0
end