Skip to content

Instantly share code, notes, and snippets.

@thejan2009
Created August 10, 2017 11:29
Show Gist options
  • Save thejan2009/8b75bc5927167e09126f46ae8d1b6871 to your computer and use it in GitHub Desktop.
Save thejan2009/8b75bc5927167e09126f46ae8d1b6871 to your computer and use it in GitHub Desktop.
;; Protect against accidental pushes to certain branches, eval it after magit initializes.
(with-eval-after-load 'magit
(defadvice magit-git-push
(around my-protect-accidental-magit-git-push)
"Ask the user for confirmation before pushing to certain branches."
(if (member (ad-get-arg 0) '("develop" "master"))
(if (yes-or-no-p (format "Push branch %s to %s?" (ad-get-arg 0) (ad-get-arg 1)))
ad-do-it
(error "Push aborted by user"))
ad-do-it))
(ad-activate 'magit-git-push))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment