Commit a8a247c7 authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-set-all: new function

Replacing the over-specialized `magit-remote-config--set'.
parent cad57860
...@@ -1813,5 +1813,16 @@ the reference is used. The first regexp submatch becomes the ...@@ -1813,5 +1813,16 @@ the reference is used. The first regexp submatch becomes the
(gv-define-setter magit-get (val &rest keys) (gv-define-setter magit-get (val &rest keys)
`(magit-set ,val ,@keys)) `(magit-set ,val ,@keys))
(defun magit-set-all (values &rest keys)
"Set all values of the Git variable specified by KEYS to VALUES."
(let ((arg (and (or (string-prefix-p "--" (car keys))
(null (car keys)))
(pop keys)))
(var (mapconcat 'identity keys ".")))
(when (magit-get var)
(magit-call-git "config" arg "--unset-all" var))
(dolist (v values)
(magit-call-git "config" arg "--add" var v))))
(provide 'magit-git) (provide 'magit-git)
;;; magit-git.el ends here ;;; magit-git.el ends here
...@@ -263,7 +263,8 @@ Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"." ...@@ -263,7 +263,8 @@ Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"."
(defun magit-set-remote*fetch (remote values) (defun magit-set-remote*fetch (remote values)
"Set the variable `fetch' for the remote named REMOTE to VALUES." "Set the variable `fetch' for the remote named REMOTE to VALUES."
(interactive (magit-remote-config--read-args "fetch" "Fetch specs: ")) (interactive (magit-remote-config--read-args "fetch" "Fetch specs: "))
(magit-remote-config--set remote "fetch" values)) (magit-set-all values "remote" remote "fetch")
(magit-refresh))
(defun magit-set-remote*pushurl (remote urls) (defun magit-set-remote*pushurl (remote urls)
"Set the variable `pushurl' for the remote named REMOTE to URLS." "Set the variable `pushurl' for the remote named REMOTE to URLS."
...@@ -273,7 +274,8 @@ Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"." ...@@ -273,7 +274,8 @@ Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"."
(defun magit-set-remote*push (remote values) (defun magit-set-remote*push (remote values)
"Set the variable `push' for the remote named REMOTE to VALUES." "Set the variable `push' for the remote named REMOTE to VALUES."
(interactive (magit-remote-config--read-args "push" "Push specs: ")) (interactive (magit-remote-config--read-args "push" "Push specs: "))
(magit-remote-config--set remote "push" values)) (magit-set-all values "remote" remote "push")
(magit-refresh))
(defun magit-cycle-remote*tagOpt (remote) (defun magit-cycle-remote*tagOpt (remote)
(interactive (list (magit-remote-config--remote))) (interactive (list (magit-remote-config--remote)))
...@@ -310,14 +312,6 @@ Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"." ...@@ -310,14 +312,6 @@ Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"."
prompt nil nil nil prompt nil nil nil
(and value (mapconcat #'identity value ","))))))) (and value (mapconcat #'identity value ",")))))))
(defun magit-remote-config--set (remote var values)
(setq var (format "remote.%s.%s" remote var))
(when (magit-get var)
(magit-call-git "config" "--unset-all" var))
(dolist (v values)
(magit-call-git "config" "--add" var v))
(magit-refresh))
(defun magit-remote-config--set-url (remote var values &optional arg) (defun magit-remote-config--set-url (remote var values &optional arg)
(let ((old (magit-get-all "remote" remote var))) (let ((old (magit-get-all "remote" remote var)))
(dolist (v (-difference values old)) (dolist (v (-difference values 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