2

We use a third party code reviewing tool here at work. All of my colleagues use the provided app to upload their code for review but unfortunately, this requires a few cut and paste actions. Thankfully, there is a command line version that can be used for uploads.

I do the majority of my git workflow in emacs using magit and I was wondering how I could set things up so that when my point was on a particular commit, pressing a certain key-combo would call the command line exe, passing in the commit hash and change text.

Any ideas or pointer on how to go about doing this would be much appreciated.

cristobalito
  • 4,192
  • 1
  • 29
  • 41

1 Answers1

2

Getting the commit hash from the point when you're viewing the log can be done with something like (cribbed from 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}"))))

Then you can add an option to a popup with magit-define-popup-action

(magit-define-popup-action 'magit-run-popup ?a
  "aec/test"
  'aec/commit-test)

Resulting in:

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
Alejandro C.
  • 3,771
  • 15
  • 18