6

I'm using git to maintain a web site located on a remote server. My workflow has been as follows:

  1. Stage and commit changes to the web site (can do with Magit)

  2. ssh to the remote site and pull the changes into the repository that is located there, updating the working tree (cannot do with Magit)

  3. Still in the script at the remote site, run make on the new working tree

  4. Back in emacs, fetch from the remote repository, so that Magit knows things are up to date

Steps 2 and 3 are implemented by a single shell script, but now that I'm addicted to magit, leaving magit to run a shell script seems an enormous imposition. My question is twofold:

  • How can I integrate steps 2, 3, and 4 into a single emacs command? The magit documentation has a section entitled "Plumbing," and there are some hints there, so I might be able to make progress on my own.

  • How can I add the new command as an option to Magit's context-sensitive push menu, which pops up when I use the capital P? This one I have no idea how to do. Can anybody help?

5

For steps 2 and 3, you can just use shell-command and ssh to accomplish this from emacs.

To do 4, you can use magit-fetch-all-no-prune.

You can wrap this into a function like

(defun aec/ssh-make-and-fetch ()
  (interactive)
  (shell-command "ssh me@example.com \"cd project && make\"")
  (magit-fetch-all-no-prune))

Then you can add an action to the push popup with magit-define-popup-action. The push popup is magit-push-popup.

In this example, I'll bind it to the key !

(magit-define-popup-action 'magit-push-popup 
  ?!
  "Make remotely"
  'aec/ssh-make-and-fetch)

To configure this after magit loads, you can use eval-after-load in your init.el (assuming you aren't already using something like use-package).

(eval-after-load "magit"
  '(magit-define-popup-action 'magit-push-popup
     ?! 
     "Make remotely" 
     'aec/ssh-make-and-fetch))
  • I'll have to try to get the information me@example.com and project from the URL of the remote repo in magit, but I can probably figure that out, thanks. – Norman Ramsey Aug 28 '16 at 13:21
  • Where do I add the action magit-define-popup-action? I'd like to run this when the magit package is loaded, but I have not figured out how to do this. – Norman Ramsey Aug 30 '16 at 18:54
  • 1
    @NormanRamsey updated my answer with an example using eval-after-load – Alejandro C. Aug 31 '16 at 15:45
2

This has changed recently with newer versions of Magit which use "Transient" to accomplish this:

(transient-append-suffix 'magit-push "m" '("!" "Make remotely" 'aec/ssh-make-and-fetch))

Reference: https://github.com/magit/magit/wiki/Converting-popup-modifications-to-transient-modifications

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.