我们在工作中使用第三方代码审查工具。我的所有同事都使用提供的应用程序上传他们的代码以供审核,但不幸的是,这需要一些剪切和粘贴操作。值得庆幸的是,有一个可用于上传的命令行版本。
我使用 magit 在 emacs 中完成大部分 git 工作流程,我想知道如何进行设置,以便当我的观点位于特定提交时,按某个组合键将调用命令行 exe,传递在提交哈希中并更改文本。
任何有关如何执行此操作的想法或指示将不胜感激。
最佳答案
可以通过以下方式从查看日志时获取提交哈希(抄袭自 magit-diff.el 中的 magit-show-commit
):
(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
关于emacs - 根据提交运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44175225/