Commit 28617613 authored by Jonas Bernoulli's avatar Jonas Bernoulli

Support setting some variable from the remote popup

parent a6dcd97a
......@@ -52,6 +52,9 @@ Changes since v2.11.0
* Added new command `magit-rebase-remove-commit' to the rebase popup.
* The remote popup can now be used to set various remote releated
variables. #3165
Fixes since v2.11.0
-------------------
......
......@@ -7,7 +7,7 @@
#+TEXINFO_DIR_CATEGORY: Emacs
#+TEXINFO_DIR_TITLE: Magit: (magit).
#+TEXINFO_DIR_DESC: Using Git from Emacs with Magit.
#+SUBTITLE: for version 2.11.0 (2.11.0-125-g31cc5fe5+1)
#+SUBTITLE: for version 2.11.0 (2.11.0-132-ga6dcd97a+1)
#+BIND: ox-texinfo+-before-export-hook ox-texinfo+-update-version-strings
#+TEXINFO_DEFFN: t
......@@ -22,7 +22,7 @@ directly from within Emacs. While many fine Git clients exist, only
Magit and Git itself deserve to be called porcelains.
#+BEGIN_QUOTE
This manual is for Magit version 2.11.0 (2.11.0-125-g31cc5fe5+1).
This manual is for Magit version 2.11.0 (2.11.0-132-ga6dcd97a+1).
Copyright (C) 2015-2017 Jonas Bernoulli <jonas@bernoul.li>
......@@ -4746,6 +4746,12 @@ Also see [[man:git-stash]]
* Transferring
** Remotes
*** The Remote Popup
The popup ~magit-remote-popup~ is used to add remotes and to make
changes to existing remotes. This popup only deals with remotes
themselves, not with branches or the transfer of commits. Those
features are available from separate popups.
Also see [[man:git-remote]]
......@@ -4754,6 +4760,22 @@ Also see [[man:git-remote]]
This prefix command shows the following suffix commands along with
the appropriate infix arguments in a popup buffer.
- User Option: magit-remote-popup-show-variables
This option controls whether the ~magit-remote-popup~ shows remote
related Git variables. When set to nil, no variables are displayed
directly in this popup, and the sub-popup ~magit-remote-config-popup~
has to be used instead to view and change remote related variables.
- Key: M C, magit-remote-config-popup
This command shows remote related variables in a separate popup. By
default this asks the user for which remote the variables should be
shown. When ~magit-remote-popup-show-variables~ is ~nil~, then it shows
the variables for the upstream of the current branch or "origin" it
that branch has no remote upstream. To select another remote use a
prefix argument.
- Key: M a, magit-remote-add
Add a remote and fetch it. The remote name and url are read in the
......@@ -4783,6 +4805,49 @@ Also see [[man:git-remote]]
is a string, then set without asking, provided that the name of the added
remote is equal to that string and the variable isn't already set.
*** The Remote Config Popup
- Command: magit-remote-config-popup
This prefix command shows the following remote-related Git variables
in a popup buffer. The values can be changed from that buffer.
This popup is a sub-popup of the ~magit-remote-popup~ in which "C" is
bound to this popup.
The following variables are used to configure a specific remote. The
values are being displayed for the upstream remote of the current
branch. To change the value for another remote invoke
~magit-remote-config-popup~ with a prefix argument.
- Variable: remote.NAME.url
This variable specifies the url of the remote named NAME. It can
have multiple values.
- Variable: remote.NAME.fetch
The refspec used when fetching from the remote named NAME. It can
have multiple values.
- Variable: remote.NAME.pushurl
This variable specifies the url used for fetching from the remote
named NAME. If it is not specified, then ~remote.NAME.url~ is used
instead. It can have multiple values.
- Variable: remote.NAME.push
The refspec used when pushing to the remote named NAME. It can
have multiple values.
- Variable: remote.NAME.tagOpts
This variable specifies what tags are fetched by default. If the
value is ~--no-tags~ then no tags are fetched. If the value is
~--tags~, then all tags are fetched. If this variable has not value,
then only tags are fetched that are reachable from fetched branches.
** Fetching
For information about the differences between the /upstream/ and the
......
......@@ -30,7 +30,7 @@ General Public License for more details.
@finalout
@titlepage
@title Magit User Manual
@subtitle for version 2.11.0 (2.11.0-125-g31cc5fe5+1)
@subtitle for version 2.11.0 (2.11.0-132-ga6dcd97a+1)
@author Jonas Bernoulli
@page
@vskip 0pt plus 1filll
......@@ -52,7 +52,7 @@ directly from within Emacs. While many fine Git clients exist, only
Magit and Git itself deserve to be called porcelains.
@quotation
This manual is for Magit version 2.11.0 (2.11.0-125-g31cc5fe5+1).
This manual is for Magit version 2.11.0 (2.11.0-132-ga6dcd97a+1).
Copyright (C) 2015-2017 Jonas Bernoulli <jonas@@bernoul.li>
......@@ -234,7 +234,10 @@ Transferring
* Creating and Sending Patches::
* Applying Patches::
Remotes
* The Remote Popup::
* The Remote Config Popup::
Miscellaneous
......@@ -6492,6 +6495,19 @@ is shown, then this specifies how much space is used to do so.
@node Remotes
@section Remotes
@menu
* The Remote Popup::
* The Remote Config Popup::
@end menu
@node The Remote Popup
@subsection The Remote Popup
The popup @code{magit-remote-popup} is used to add remotes and to make
changes to existing remotes. This popup only deals with remotes
themselves, not with branches or the transfer of commits. Those
features are available from separate popups.
Also see
@ifinfo
@ref{git-remote,,,gitman,}.
......@@ -6513,6 +6529,28 @@ the git-remote(1) manpage.
This prefix command shows the following suffix commands along with
the appropriate infix arguments in a popup buffer.
@end table
@defopt magit-remote-popup-show-variables
This option controls whether the @code{magit-remote-popup} shows remote
related Git variables. When set to nil, no variables are displayed
directly in this popup, and the sub-popup @code{magit-remote-config-popup}
has to be used instead to view and change remote related variables.
@end defopt
@table @asis
@kindex M C
@cindex magit-remote-config-popup
@item @kbd{M C} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-config-popup})
This command shows remote related variables in a separate popup. By
default this asks the user for which remote the variables should be
shown. When @code{magit-remote-popup-show-variables} is @code{nil}, then it shows
the variables for the upstream of the current branch or "origin" it
that branch has no remote upstream. To select another remote use a
prefix argument.
@kindex M a
@cindex magit-remote-add
@item @kbd{M a} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-add})
......@@ -6553,6 +6591,57 @@ is a string, then set without asking, provided that the name of the added
remote is equal to that string and the variable isn't already set.
@end defopt
@node The Remote Config Popup
@subsection The Remote Config Popup
@cindex magit-remote-config-popup
@deffn Command magit-remote-config-popup
This prefix command shows the following remote-related Git variables
in a popup buffer. The values can be changed from that buffer.
This popup is a sub-popup of the @code{magit-remote-popup} in which "C" is
bound to this popup.
@end deffn
The following variables are used to configure a specific remote. The
values are being displayed for the upstream remote of the current
branch. To change the value for another remote invoke
@code{magit-remote-config-popup} with a prefix argument.
@defvar remote.NAME.url
This variable specifies the url of the remote named NAME. It can
have multiple values.
@end defvar
@defvar remote.NAME.fetch
The refspec used when fetching from the remote named NAME. It can
have multiple values.
@end defvar
@defvar remote.NAME.pushurl
This variable specifies the url used for fetching from the remote
named NAME. If it is not specified, then @code{remote.NAME.url} is used
instead. It can have multiple values.
@end defvar
@defvar remote.NAME.push
The refspec used when pushing to the remote named NAME. It can
have multiple values.
@end defvar
@defvar remote.NAME.tagOpts
This variable specifies what tags are fetched by default. If the
value is @code{--no-tags} then no tags are fetched. If the value is
@code{--tags}, then all tags are fetched. If this variable has not value,
then only tags are fetched that are reachable from fetched branches.
@end defvar
@node Fetching
@section Fetching
......
......@@ -101,19 +101,33 @@ variable isn't already set."
(string :tag "set if named")
(const :tag "don't set")))
(defcustom magit-remote-popup-show-variables t
"Whether the `magit-remote-popup' shows Git variables.
When set to nil, no variables are displayed directly in this
popup, instead the sub-popup `magit-remote-config-popup' has
to be used to view and change remote related variables."
:package-version '(magit . "2.12.0")
:group 'magit-commands
:type 'boolean)
;;;; Popup
(defvar magit-remote-config-variables)
;;;###autoload (autoload 'magit-remote-popup "magit-remote" nil t)
(magit-define-popup magit-remote-popup
"Popup console for remote commands."
:man-page "git-remote"
:default-arguments '("-f")
:variables (lambda ()
(and magit-remote-popup-show-variables
magit-remote-config-variables))
:switches '("Switches for add"
(?f "Fetch after add" "-f"))
:actions '((?a "Add" magit-remote-add)
(?r "Rename" magit-remote-rename)
(?k "Remove" magit-remote-remove)
(?u "Set url" magit-remote-set-url)))
:actions '((?a "Add" magit-remote-add)
(?r "Rename" magit-remote-rename)
(?k "Remove" magit-remote-remove)
(?C "Configure..." magit-remote-config-popup)))
;;;; Commands
......@@ -148,15 +162,6 @@ variable isn't already set."
(unless (string= old new)
(magit-run-git "remote" "rename" old new)))
;;;###autoload
(defun magit-remote-set-url (remote url)
"Change the url of the remote named REMOTE to URL."
(interactive
(let ((remote (magit-read-remote "Set url of remote")))
(list remote (magit-read-url
"Url" (magit-get "remote" remote "url")))))
(magit-run-git "remote" "set-url" remote url))
;;;###autoload
(defun magit-remote-remove (remote)
"Delete the remote named REMOTE."
......@@ -185,6 +190,157 @@ Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"."
(interactive (list (magit-read-remote "Unset HEAD for remote")))
(magit-run-git "remote" "set-head" remote "--delete"))
;;;; Config Popup
(defvar magit-remote-config--remote nil)
;;;###autoload
(defun magit-remote-config-popup (remote)
"Popup console for setting remote variables."
(interactive
(list (if (or current-prefix-arg
(and (eq magit-current-popup 'magit-remote-popup)
magit-remote-popup-show-variables))
(magit-read-remote "Configure remote")
(magit-remote-config--remote-1))))
(let ((magit-remote-config--remote remote))
(magit-invoke-popup 'magit-remote-config-popup nil nil)))
(defvar magit-remote-config-variables
'((lambda ()
(concat
(propertize "Configure " 'face 'magit-popup-heading)
(propertize (magit-remote-config--remote) 'face 'magit-branch-remote)))
(?u "remote.%s.url"
magit-set-remote*url
magit-format-remote*url)
(?U "remote.%s.fetch"
magit-set-remote*fetch
magit-format-remote*fetch)
(?s "remote.%s.pushurl"
magit-set-remote*pushurl
magit-format-remote*pushurl)
(?S "remote.%s.push"
magit-set-remote*push
magit-format-remote*push)
(?O "remote.%s.tagOpt"
magit-cycle-remote*tagOpt
magit-format-remote*tagOpt)))
(defvar magit-remote-config-popup
`(:man-page "git-remote"
:variables ,magit-remote-config-variables
:setup-function magit-remote-config-popup-setup))
(defun magit-remote-config-popup-setup (val def)
(magit-popup-default-setup val def)
(setq-local magit-remote-config--remote magit-remote-config--remote))
(defun magit-remote-config--remote (&optional prompt)
(if prompt
(or (and (not current-prefix-arg)
(or magit-remote-config--remote
(magit-remote-config--remote-1)))
(magit-read-remote prompt))
(or magit-remote-config--remote
(magit-remote-config--remote-1)
"<name>")))
(defun magit-remote-config--remote-1 ()
(let ((remote (magit-get-upstream-remote)))
(if (or (not remote)
(equal remote "."))
(and (magit-remote-p "origin") "origin")
remote)))
;;;; Config Commands and Inserters
(defun magit-set-remote*url (remote urls)
"Set the variable `url' for the remote named REMOTE to URLS."
(interactive (magit-remote-config--read-args "url" "Urls: "))
(magit-remote-config--set-url remote "url" urls))
(defun magit-set-remote*fetch (remote values)
"Set the variable `fetch' for the remote named REMOTE to VALUES."
(interactive (magit-remote-config--read-args "fetch" "Fetch specs: "))
(magit-remote-config--set remote "fetch" values))
(defun magit-set-remote*pushurl (remote urls)
"Set the variable `pushurl' for the remote named REMOTE to URLS."
(interactive (magit-remote-config--read-args "pushurl" "Urls: "))
(magit-remote-config--set-url remote "pushurl" urls "--push"))
(defun magit-set-remote*push (remote values)
"Set the variable `push' for the remote named REMOTE to VALUES."
(interactive (magit-remote-config--read-args "push" "Push specs: "))
(magit-remote-config--set remote "push" values))
(defun magit-cycle-remote*tagOpt (remote)
(interactive (list (magit-remote-config--remote)))
(magit-popup-set-variable (format "remote.%s.tagOpts" remote)
'("--no-tags" "--tags") nil))
(defun magit-format-remote*url ()
(magit-remote-config--format-variable "url"))
(defun magit-format-remote*fetch ()
(magit-remote-config--format-variable "fetch"))
(defun magit-format-remote*pushurl ()
(magit-remote-config--format-variable "pushurl"))
(defun magit-format-remote*push ()
(magit-remote-config--format-variable "push"))
(defun magit-format-remote*tagOpt ()
(magit-popup-format-variable (format "remote.%s.tagOpts"
(magit-remote-config--remote))
'("--no-tags" "--tags") nil nil 22))
(defun magit-remote-config--read-args (var prompt)
(let* ((remote (magit-remote-config--remote (format "Set `%s' of remote" var)))
(value (magit-get-all "remote" remote var)))
(list remote
(mapcar (lambda (url)
(if (string-prefix-p "~" url)
(expand-file-name url)
url))
(completing-read-multiple
prompt nil nil nil
(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)
(let ((old (magit-get-all "remote" remote var)))
(dolist (v (-difference values old))
(magit-call-git "remote" "set-url" arg "--add" remote v))
(dolist (v (-difference old values))
(magit-call-git "remote" "set-url" arg "--delete" remote
(concat "^" (regexp-quote v) "$"))))
(magit-refresh))
(defun magit-remote-config--format-variable (variable)
(let* ((remote (magit-remote-config--remote))
(var (format "remote.%s.%s" remote variable)))
(concat var (make-string (max 1 (- 8 (length variable))) ?\s)
(-if-let (values (magit-get-all var))
(concat
(propertize (car values) 'face 'magit-popup-option-value)
(mapconcat
(lambda (value)
(concat "\n" (make-string 25 ?\s)
(propertize value
'face 'magit-popup-option-value)))
(cdr values) ""))
(propertize "unset" 'face 'magit-popup-disabled-argument)))))
;;; Fetch
;;;###autoload (autoload 'magit-fetch-popup "magit-remote" nil t)
......
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