emacs - 根据提交运行命令

标签 emacs magit

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

我使用 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/

相关文章:

vim - Emacs 和 Vim 的区别

Emacs:有没有办法使用 Emacs 创建交互式脚本?

rebase - 在magit中,我可以交互式地重新建立另一个分支吗?

emacs - magit over 流浪汉 : re-use ssh connection

c++ - 你用 VIM/Emacs/Terminals 开发 C/C++ 吗?这个实用的项目是什么?

macos - 如何使用 Aquamacs 以 root 身份打开文件进行编辑?

shell - 在 Emacs 中使用 z(跳转)来查找目录

git - 如何使用 magit emacs 更改 repo?

git - 关闭 magit-mode 提交格式化

git - 如何在 GNU Emacs 中停用 vc-git?