Commit a7da211d authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-commit-{amend,extend,reword}: Confirm edit of published commit

parent 39783a7b
......@@ -186,6 +186,12 @@ and change branch related variables."
:group 'magit-commands
:type 'boolean)
(defcustom magit-published-branches '("origin/master")
"List of branches that are considered to be published."
:package-version '(magit . "2.13.0")
:group 'magit-commands
:type '(repeat string))
;;; Branch Popup
(defvar magit-branch-config-variables)
......
......@@ -165,6 +165,7 @@ With a prefix argument, amend to the commit at `HEAD' instead.
"Amend the last commit.
\n(git commit --amend ARGS)"
(interactive (list (magit-commit-arguments)))
(magit-commit-amend-assert)
(magit-run-git-with-editor "commit" "--amend" args))
;;;###autoload
......@@ -180,6 +181,7 @@ to inverse the meaning of the prefix argument. \n(git commit
(not magit-commit-extend-override-date)
magit-commit-extend-override-date)))
(when (setq args (magit-commit-assert args (not override-date)))
(magit-commit-amend-assert)
(let ((process-environment process-environment))
(unless override-date
(push (magit-rev-format "GIT_COMMITTER_DATE=%cD") process-environment))
......@@ -200,6 +202,7 @@ and ignore the option.
(if current-prefix-arg
(not magit-commit-reword-override-date)
magit-commit-reword-override-date)))
(magit-commit-amend-assert)
(let ((process-environment process-environment))
(unless override-date
(push (magit-rev-format "GIT_COMMITTER_DATE=%cD") process-environment))
......@@ -297,6 +300,15 @@ depending on the value of option `magit-commit-squash-confirm'."
(let ((magit-display-buffer-noselect t))
(apply #'magit-diff-staged nil (magit-diff-arguments)))))))
(defun magit-commit-amend-assert (&optional commit)
(--when-let (magit-list-publishing-branches commit)
(let ((m1 "This commit has already been published to ")
(m2 ".\nDo you really want to modify it"))
(magit-confirm 'edit-published
(concat m1 "%s" m2)
(concat m1 "%i public branches" m2)
nil it))))
(defun magit-commit-assert (args &optional strict)
(cond
((or (magit-anything-staged-p)
......
......@@ -1283,6 +1283,10 @@ SORTBY is a key or list of keys to pass to the `--sort' flag of
(defun magit-list-containing-branches (&optional commit arg)
(magit-list-related-branches "--contains" commit arg))
(defun magit-list-publishing-branches (&optional commit)
(--filter (member it magit-published-branches)
(magit-list-containing-branches commit "--remote")))
(defun magit-list-merged-branches (&optional commit arg)
(magit-list-related-branches "--merged" commit arg))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment