Skip to content

Commit

Permalink
allow pushing to an arbitrary branch
Browse files Browse the repository at this point in the history
before that, the only way to
$ git push <remote> <branch1>:<branch2>
was to have it configured as
$ git config branch.<branch1>.merge <branch2>

Otherwise it would simply run
$ git push <remote> <branch>

(<branch> being a shortcut for <branch>:<branch>)

Now a double C-u before pushing will allow pushing to a specified branch
  • Loading branch information
sigma committed Dec 22, 2011
1 parent 3915a96 commit 1eeaf17
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions magit.el
Expand Up @@ -1224,6 +1224,20 @@ DEF is the default value, and defaults to the value of `magit-get-current-branch
nil nil nil nil def)))
(if (string= reply "") nil reply)))

(defun magit-read-remote-branch (remote &optional prompt default)
(let* ((prompt (or prompt (format "Remote branch (in %s): " remote)))
(branches (delete nil
(mapcar
(lambda (b)
(and (not (string-match " -> " b))
(string-match (format "^ *%s/\\(.*\\)$"
remote) b)
(match-string 1 b)))
(magit-git-lines "branch" "-r"))))
(reply (magit-completing-read prompt branches
nil nil nil nil default)))
(if (string= reply "") nil reply)))

;;; Sections

;; A buffer in magit-mode is organized into hierarchical sections.
Expand Down Expand Up @@ -3952,10 +3966,14 @@ typing and automatically refreshes the status buffer."
(branch-remote (magit-get-remote branch))
(push-remote (if (or current-prefix-arg
(not branch-remote))
(magit-read-remote (format "Push %s to: " branch)
(magit-read-remote (format "Push %s to remote: "
branch)
branch-remote)
branch-remote))
(ref-branch (magit-get "branch" branch "merge")))
(ref-branch (or (and (>= (prefix-numeric-value current-prefix-arg) 16)
(magit-read-remote-branch
push-remote (format "Push %s as branch: " branch)))
(magit-get "branch" branch "merge"))))
(if (and (not ref-branch)
(eq magit-set-upstream-on-push 'refuse))
(error "Not pushing since no upstream has been set.")
Expand Down

0 comments on commit 1eeaf17

Please sign in to comment.