Method: MGit::Clean#execute

Defined in:
lib/m-git/command/clean.rb

#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