Class: MGit::Commit
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- MGit::Commit
- Defined in:
- lib/m-git/command/commit.rb
Overview
follow git commit eg: mgit commit -m ‘Just for fun’
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
.description ⇒ Object
74 75 76 |
# File 'lib/m-git/command/commit.rb', line 74 def self.description "将修改记录到版本库。" end |
.usage ⇒ Object
78 79 80 |
# File 'lib/m-git/command/commit.rb', line 78 def self.usage "mgit commit [<git-commit-option>] [(--mrepo|--el-mrepo) <repo>...] [--help]" end |
Instance Method Details
#enable_repo_selection ⇒ Object
70 71 72 |
# File 'lib/m-git/command/commit.rb', line 70 def enable_repo_selection true end |
#execute(argv) ⇒ Object
21 22 23 24 25 26 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 65 66 67 68 |
# File 'lib/m-git/command/commit.rb', line 21 def execute(argv) Workspace.check_branch_consistency Output.puts_start_cmd do_repos = [] remind_repos = [] do_nothing_repos = [] Output.("检查各仓库状态...") Workspace.serial_enumerate_with_progress(all_repos) { |repo| if repo.status_checker.status == Repo::Status::GIT_REPO_STATUS[:dirty] index_dirty_mask = Repo::Status::GIT_REPO_STATUS_DIRTY_ZONE[:index] # 仅在暂存区有未提交的改动时执行 if repo.status_checker.dirty_zone & index_dirty_mask == index_dirty_mask do_repos.push(repo) else remind_repos.push(repo.name) end else do_nothing_repos.push(repo.name) end } Output.("检查完成!\n") if remind_repos.length > 0 && !Output.continue_with_interact_repos?(remind_repos, "以上仓库暂存区无可提交内容,仅存在工作区改动或未跟踪文件,若需要提交这些改动请先add到暂存区。是否跳过并继续?") Output. return end if do_repos.length != 0 if argv.git_opts.include?('-m ') || !Output.continue_with_user_remind?("未添加\"-m\"参数,请使用如[ mgit commit -m \"my log\" ]的形式提交。是否取消执行并重新输入(若确实有意执行该指令请忽略本提示)?") # commit前调用hook HooksManager.execute_mgit_pre_exec_hook(argv.cmd, argv.pure_opts, do_repos.map { |e| e.config }) msg = ",另有#{do_nothing_repos.length}个仓库暂存区无待提交内容,无须执行" if do_nothing_repos.length > 0 Output.puts_remind_block(do_repos.map { |repo| repo.name }, "开始commit以上仓库#{msg}...") _, error_repos = Workspace.execute_git_cmd_with_repos(argv.cmd, argv.git_opts, do_repos) Output.puts_succeed_cmd(argv.absolute_cmd) if error_repos.length == 0 else Output. return end else Output.("所有仓库均无改动,无须执行!") end end |