运行 基于提交的命令

Run a command based on a commit

我们在工作中使用第三方代码审查工具。我所有的同事都使用提供的应用程序上传他们的代码以供审查,但不幸的是,这需要一些剪切和粘贴操作。幸运的是,有一个命令行版本可以用于上传。

我在 emacs 中使用 magit 完成我的大部分 git 工作流程,我想知道如何进行设置,以便当我的观点针对特定提交时,按下某个组合键将调用命令行 exe,传递提交哈希和更改文本。

任何有关如何执行此操作的想法或指示将不胜感激。

从查看日志时获取提交哈希可以通过类似的方式完成(摘自magit-show-commit in magit-diff.el):

(defun aec/commit-test (rev &optional args files module)
  "Visit the revision at point in another buffer.
If there is no revision at point or with a prefix argument prompt
for a revision."
  (interactive
   (let* ((mcommit (magit-section-when module-commit))
          (atpoint (or (and (bound-and-true-p magit-blame-mode)
                            (magit-blame-chunk-get :hash))
                       mcommit
                       (magit-branch-or-commit-at-point)
                       (magit-tag-at-point))))
     (nconc (cons (or (and (not current-prefix-arg) atpoint)
                      (magit-read-branch-or-commit "Show commit" atpoint))
                  (magit-show-commit--arguments))
            (and mcommit (list (magit-section-parent-value
                                (magit-current-section)))))))
  (message (magit-rev-parse (concat rev "^{commit}"))))

然后您可以使用 magit-define-popup-action

向弹出窗口添加一个选项
(magit-define-popup-action 'magit-run-popup ?a
  "aec/test"
  'aec/commit-test)

导致:

Actions
 ! Git Subcommand (in topdir)    k Gitk
 p Git Subcommand (in pwd)       s Shell command (in topdir)
 b Gitk --branches               S Shell command (in pwd)
 g Git Gui                       a aec/test