Offer to create tracking branches when switching to a remote branch.
* magit.el (magit-ref-exists-p): New. (magit-maybe-create-localtracking-branch): New. (magit-checkout): Use it.
This commit is contained in:
parent
2d5aff1b87
commit
e2fdbc2d01
1 changed files with 16 additions and 1 deletions
17
magit.el
17
magit.el
|
@ -303,6 +303,9 @@ Many Magit faces inherit from this one by default."
|
|||
(substring head 11)
|
||||
nil)))
|
||||
|
||||
(defun magit-ref-exists-p (ref)
|
||||
(magit-git-exit-code "show-ref" "--verify" "--quiet" ref))
|
||||
|
||||
(defun magit-read-top-dir ()
|
||||
(file-name-as-directory
|
||||
(read-directory-name "Git repository: "
|
||||
|
@ -1944,10 +1947,22 @@ in log buffer."
|
|||
|
||||
;;; Branches
|
||||
|
||||
(defun magit-maybe-create-localtracking-branch (rev)
|
||||
(if (string-match "^refs/remotes/\\(.*\\)/\\([^/]*\\)" rev)
|
||||
(let ((remote (match-string 1 rev))
|
||||
(branch (match-string 2 rev)))
|
||||
(when (and (not (magit-ref-exists-p (concat "refs/heads/" branch)))
|
||||
(yes-or-no-p
|
||||
(format "Create local tracking branch for %s? " branch)))
|
||||
(magit-run-git "checkout" "-b" branch rev)
|
||||
t))
|
||||
nil))
|
||||
|
||||
(defun magit-checkout (rev)
|
||||
(interactive (list (magit-read-rev "Switch to" (magit-default-rev))))
|
||||
(if rev
|
||||
(magit-run-git "checkout" (magit-rev-to-git rev))))
|
||||
(if (not (magit-maybe-create-localtracking-branch rev))
|
||||
(magit-run-git "checkout" (magit-rev-to-git rev)))))
|
||||
|
||||
(defun magit-read-create-branch-args ()
|
||||
(let* ((cur-branch (magit-get-current-branch))
|
||||
|
|
Loading…
Reference in a new issue