Commit 14c7b138 authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-branch-rename: Ask before renaming on remote

On Github at least doing so would close an associated pull-request
permanently.  This would be annoying if the user actually wanted to
do the equivalent of:

  git checkout -b feature-r2 feature
  ...redo feature better...
  git branch -m feature feature-r1
  git branch -m feature-r2 feature
  git push --force origin feature feature-r1

This happened with #3622.
parent 8506935a
......@@ -743,16 +743,19 @@ the remote."
(fboundp 'forge--forge-remote-p)
(forge--forge-remote-p remote))))
(let ((old-target (magit-get-push-branch old t))
(new-target (magit-get-push-branch new t)))
(when (and old-target (not new-target))
(new-target (magit-get-push-branch new t))
(remote (magit-get-push-remote new)))
(when (and old-target
(not new-target)
(magit-y-or-n-p (format "Also rename %S to %S on %S"
old new remote)))
;; Rename on (i.e. within) the remote, but only if the
;; destination ref doesn't exist yet. If that ref already
;; exists, then it probably is of some value and we better
;; not touch it. Ignore what the local ref points at,
;; i.e. if the local and the remote ref didn't point at
;; the same commit before the rename then keep it that way.
(magit-call-git "push" "-v"
(magit-get-push-remote new)
(magit-call-git "push" "-v" remote
(format "%s:refs/heads/%s" old-target new)
(format ":refs/heads/%s" old)))))))
(magit-branch-unset-pushRemote old)
......
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