Commit 45c23052 authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-push-current-set-remote-if-missing: new option

parent 18bef0c5
......@@ -29,12 +29,18 @@ Changes since v2.3.0
are in some way related to branches. The values of these variables
can now be conveniently changed from that popup. #2414
* The fetching, pulling, pushing, and rebasing popups now feature an
action which acts on the push-remote, another which acts on the
upstream, and yet another which acts on any other source or target.
For each of these actions the respective branch is shown in the
popup. If an action isn't currently usable, then it is omitted from
the popup.
* The fetch, pull, push, and rebase popups now feature an action which
acts on the push-remote, another which acts on the upstream, and yet
another which acts on any other source or target. For each of these
actions the respective branch is shown in the popup.
Each of these actions depends on certain Git variables being set.
When they are not set, then the action is omitted from the popup.
The actions in the push popup are displayed even if the respective
variables are unset - they then offer to set these variables before
pushing. Setting `magit-push-current-set-remote-if-missing' to nil
disables this.
Many key bindings were changed for consistency and safety reasons.
Likewise many commands were renamed and their behavior was adjusted.
......
......@@ -3871,10 +3871,20 @@ Also see [[info:gitman#git-push]].
Push the current branch to ~branch.<name>.pushRemote~ or if that
is unset to ~remote.pushDefault~.
When ~magit-push-current-set-remote-if-missing~ is non-nil and the
push-remote is not configured, then read the push-remote from the
user, set it, and then push to it. With a prefix argument the
push-remote can be changed before pushed to it.
- Key: P u, magit-push-current-to-upstream
Push the current branch to its upstream branch.
When ~magit-push-current-set-remote-if-missing~ is non-nil and the
push-remote is not configured, then read the upstram from the
user, set it, and then push to it. With a prefix argument the
push-remote can be changed before pushed to it.
- Key: P e, magit-push-current
Push the current branch to a branch read in the minibuffer.
......@@ -3900,6 +3910,28 @@ Also see [[info:gitman#git-push]].
Push a tag to another repository.
- User Option: magit-push-current-set-remote-if-missing
This option controls whether missing remotes are configured before
pushing.
When ~nil~, then the command ~magit-push-current-to-pushremote~ and
~magit-push-current-to-upstream~ do not appear in the push popup if
the push-remote resp. upstream is not configured. If the user
invokes one of these commands anyway, then it raises an error.
When ~non-nil~, then these commands always appear in the push popup.
But if the required configuration is missing, then they do appear in
a way that indicates that this is the case. If the user invokes one
of them, then it asks for the necessary configuration, stores the
configuration, and then uses it to push a first time.
This option also affects whether the argument ~--set-upstream~ is
available in the popup. If the value is ~non-nil~, then that argument
is redundant. But note that changing the value of this options here
does not take affect immediately, the argument8 will only be added
or removed after restarting Emacs.
** Creating and sending patches
- Key: W, magit-patch-popup
......
......@@ -5454,12 +5454,22 @@ the appropriate infix arguments in a popup buffer.
Push the current branch to @code{branch.<name>.pushRemote} or if that
is unset to @code{remote.pushDefault}.
When @code{magit-push-current-set-remote-if-missing} is non-nil and the
push-remote is not configured, then read the push-remote from the
user, set it, and then push to it. With a prefix argument the
push-remote can be changed before pushed to it.
@kindex P u
@cindex magit-push-current-to-upstream
@item @kbd{P u} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-current-to-upstream})
Push the current branch to its upstream branch.
When @code{magit-push-current-set-remote-if-missing} is non-nil and the
push-remote is not configured, then read the upstram from the
user, set it, and then push to it. With a prefix argument the
push-remote can be changed before pushed to it.
@kindex P e
@cindex magit-push-current
@item @kbd{P e} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-current})
......@@ -5494,8 +5504,32 @@ remote configured for the current branch as default.
@item @kbd{P T} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-tag})
Push a tag to another repository.
@end table
@defopt magit-push-current-set-remote-if-missing
This option controls whether missing remotes are configured before
pushing.
When @code{nil}, then the command @code{magit-push-current-to-pushremote} and
@code{magit-push-current-to-upstream} do not appear in the push popup if
the push-remote resp. upstream is not configured. If the user
invokes one of these commands anyway, then it raises an error.
When @code{non-nil}, then these commands always appear in the push popup.
But if the required configuration is missing, then they do appear in
a way that indicates that this is the case. If the user invokes one
of them, then it asks for the necessary configuration, stores the
configuration, and then uses it to push a first time.
This option also affects whether the argument @code{--set-upstream} is
available in the popup. If the value is @code{non-nil}, then that argument
is redundant. But note that changing the value of this options here
does not take affect immediately, the argument8 will only be added
or removed after restarting Emacs.
@end defopt
@node Creating and sending patches
@section Creating and sending patches
......
......@@ -1108,10 +1108,7 @@ of events shared by all popups and before point is adjusted.")
(insert "\n"))))
(unless (equal item '(""))
(if item
(progn (apply 'insert-button item)
(unless (memq (get-text-property 4 'face (car item))
'(bold nil))
(insert ?\n)))
(apply 'insert-button item)
(insert ?\s)))))
(insert (if (= (char-before) ?\n) "\n" "\n\n")))))))
......
......@@ -221,28 +221,55 @@ Then show the status buffer for the new repository."
;;; Push
(defcustom magit-push-current-set-remote-if-missing t
"Whether to configure missing remotes before pushing.
When nil, then the command `magit-push-current-to-pushremote' and
`magit-push-current-to-upstream' do not appear in the push popup
if the push-remote resp. upstream is not configured. If the user
invokes one of these commands anyway, then it raises an error.
When non-nil, then these commands always appear in the push
popup. But if the required configuration is missing, then they
do appear in a way that indicates that this is the case. If the
user invokes one of them, then it asks for the necessary
configuration, stores the configuration, and then uses it to push
a first time.
This option also affects whether the argument `--set-upstream' is
available in the popup. If the value is t, then that argument is
redundant. But note that changing the value of this options here
does not take affect immediately, the argument will only be added
or removed after restarting Emacs."
:package-version '(magit . "2.4.0")
:group 'magit-commands
:type 'boolean)
;;;###autoload (autoload 'magit-push-popup "magit-remote" nil t)
(magit-define-popup magit-push-popup
"Popup console for push commands."
'magit-commands
:man-page "git-push"
:switches '((?f "Force" "--force-with-lease")
:switches `((?f "Force" "--force-with-lease")
(?h "Disable hooks" "--no-verify")
(?d "Dry run" "--dry-run")
(?u "Set upstream" "--set-upstream"))
,@(and (not magit-push-current-set-remote-if-missing)
'((?u "Set upstream" "--set-upstream"))))
:actions '((lambda ()
(--when-let (magit-get-current-branch)
(concat (propertize "Push " 'face 'magit-popup-heading)
(propertize it 'face 'magit-branch-local)
(propertize " to" 'face 'magit-popup-heading))))
(?p magit-get-push-branch magit-push-current-to-pushremote)
(?u magit-get-upstream-branch magit-push-current-to-upstream)
(?e "elsewhere" magit-push-current)
(?p magit--push-current-to-pushremote-desc
magit-push-current-to-pushremote)
(?u magit--push-current-to-upstream-desc
magit-push-current-to-upstream)
(?e "elsewhere\n" magit-push-current)
"Push"
(?o "another branch" magit-push)
(?T "a tag" magit-push-tag)
(?m "matching branches" magit-push-matching)
(?t "all tags" magit-push-tags))
(?o "another branch" magit-push)
(?T "a tag" magit-push-tag)
(?m "matching branches" magit-push-matching)
(?t "all tags" magit-push-tags))
:max-action-columns 2)
(defun magit-git-push (branch target args)
......@@ -254,28 +281,77 @@ Then show the status buffer for the new repository."
branch target))))
;;;###autoload
(defun magit-push-current-to-pushremote (args)
(defun magit-push-current-to-pushremote (args &optional push-remote)
"Push the current branch to `branch.<name>.pushRemote'.
If that variable is unset, then push to `remote.pushDefault'."
(interactive (list (magit-push-arguments)))
If that variable is unset, then push to `remote.pushDefault'.
When `magit-push-current-set-remote-if-missing' is non-nil and
the push-remote is not configured, then read the push-remote from
the user, set it, and then push to it. With a prefix argument
the push-remote can be changed before pushed to it."
(interactive
(list (magit-push-arguments)
(and (magit--push-current-set-pushremote-p current-prefix-arg)
(magit-read-remote (format "Set push-remote of %s and push there"
(magit-get-current-branch))))))
(--if-let (magit-get-current-branch)
(-if-let (remote (magit-get-push-remote it))
(if (member remote (magit-list-remotes))
(magit-git-push it (concat remote "/" it) args)
(user-error "Remote `%s' doesn't exist" remote))
(user-error "No push-remote is configured for %s" it))
(progn (when push-remote
(magit-call-git "config"
(format "branch.%s.pushRemote"
(magit-get-current-branch))
push-remote))
(-if-let (remote (magit-get-push-remote it))
(if (member remote (magit-list-remotes))
(magit-git-push it (concat remote "/" it) args)
(user-error "Remote `%s' doesn't exist" remote))
(user-error "No push-remote is configured for %s" it)))
(user-error "No branch is checked out")))
(defun magit--push-current-set-pushremote-p (&optional change)
(and (or change magit-push-current-set-remote-if-missing)
(magit-get-current-branch)
(not (magit-get-push-remote))))
(defun magit--push-current-to-pushremote-desc ()
(--if-let (magit-get-push-branch)
(concat (magit-branch-set-face it) "\n")
(and (magit--push-current-set-pushremote-p)
(concat (propertize "@{push}" 'face 'bold)
", after setting that\n"))))
;;;###autoload
(defun magit-push-current-to-upstream (args)
"Push the current branch to its upstream branch."
(interactive (list (magit-push-arguments)))
(defun magit-push-current-to-upstream (args &optional upstream)
"Push the current branch to its upstream branch.
When `magit-push-current-set-remote-if-missing' is non-nil and
the upstream is not configured, then read the upstream from the
user, set it, and then push to it. With a prefix argument the
upstream can be changed before pushed to it."
(interactive
(list (magit-push-arguments)
(and (magit--push-current-set-upstream-p current-prefix-arg)
(magit-read-remote (format "Set upstream of %s and push there"
(magit-get-current-branch))))))
(--if-let (magit-get-current-branch)
(-if-let (target (magit-get-upstream-branch it))
(magit-git-push it target args)
(user-error "No upstream is configured for %s" it))
(progn (when upstream
(magit-call-git "branch" (concat "--set-upstream-to=" upstream)))
(-if-let (target (magit-get-upstream-branch it))
(magit-git-push it target args)
(user-error "No upstream is configured for %s" it)))
(user-error "No branch is checked out")))
(defun magit--push-current-set-upstream-p (&optional change)
(and (or change magit-push-current-set-remote-if-missing)
(magit-get-current-branch)
(not (magit-get-upstream-branch))))
(defun magit--push-current-to-upstream-desc ()
(--if-let (magit-get-upstream-branch)
(concat (magit-branch-set-face it) "\n")
(and (magit--push-current-set-upstream-p)
(concat (propertize "@{upstream}" 'face 'bold)
", after setting that\n"))))
;;;###autoload
(defun magit-push-current (target args)
"Push the current branch to a branch read in the minibuffer."
......
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