Commit ddda6088 authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-set-upstream-branch: New function

parent dd3de8c3
......@@ -562,7 +562,7 @@ that is being reset."
(user-error "Abort")
(magit-reset-hard to)
(when (and set-upstream (magit-branch-p to))
(magit-set-branch*merge/remote branch to)))
(magit-set-upstream-branch branch to)))
(magit-branch-create branch to args)))
......@@ -920,14 +920,8 @@ already set. When nil, then always unset."
(let ((branch (magit-branch-config-branch "Change upstream of branch")))
(list branch (and (not (magit-get-upstream-branch branch))
(magit-read-upstream-branch branch)))))
(if upstream
(pcase-let ((`(,remote . ,merge) (magit-split-branch-name upstream)))
(setf (magit-get (format "branch.%s.remote" branch)) remote)
(setf (magit-get (format "branch.%s.merge" branch))
(concat "refs/heads/" merge)))
(magit-call-git "branch" "--unset-upstream" branch))
(when (called-interactively-p 'any)
(magit-set-upstream-branch branch upstream)
(defun magit-format-branch*merge/remote ()
(let* ((branch (magit-branch-config-branch))
......@@ -1189,6 +1189,14 @@ The amount of time spent searching is limited by
((string-prefix-p "refs/heads/" merge)
(concat "refs/remotes/" remote "/" (substring merge 11))))))))
(defun magit-set-upstream-branch (branch upstream)
(if upstream
(pcase-let ((`(,remote . ,merge) upstream))
(setf (magit-get (format "branch.%s.remote" branch)) remote)
(setf (magit-get (format "branch.%s.merge" branch))
(concat "refs/heads/" merge)))
(magit-call-git "branch" "--unset-upstream" branch)))
(defun magit-get-upstream-branch (&optional branch verify)
(and (or branch (setq branch (magit-get-current-branch)))
(when-let ((remote (magit-get "branch" branch "remote"))
......@@ -798,7 +798,7 @@ upstream can be changed before pushed to it."
(--if-let (magit-get-current-branch)
(when upstream
(magit-set-branch*merge/remote it upstream))
(magit-set-upstream-branch it upstream))
(if-let ((target (magit-get-upstream-branch it)))
(magit-git-push it target args)
(user-error "No upstream is configured for %s" it)))
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