The following functions are available from the branch list (which in
turn is made read-only):
- Checking out the branch in the current line
- Deleting the branch in the current line (prefix forces deletion even
if not merged into current branch)
- Manual and automatic merges of the branch in the current line into
the current branch
- Quitting the branch list
---
magit.el | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/magit.el b/magit.el
index 692ed5d..3839091 100644
--- a/magit.el
+++ b/magit.el
@@ -3420,14 +3420,79 @@ Prefix arg means justify as well."
(if old-editor
(setenv "GIT_EDITOR" old-editor)))))
+(define-derived-mode magit-show-branches-mode text-mode "Magit Branches"
+ (use-local-map magit-show-branches-map))
+
+(defvar magit-show-branches-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "b") 'magit-branches-window-checkout)
+ (define-key map (kbd "k") 'magit-remove-branch)
+ (define-key map (kbd "m") 'magit-branches-window-manual-merge)
+ (define-key map (kbd "M") 'magit-branches-window-automatic-merge)
+ (define-key map (kbd "$") 'magit-display-process)
+ (define-key map (kbd "q") 'magit-quit-branches-window)
+ (define-key map (kbd "V") 'magit-show-branches)
+ map))
+
+(defun magit-quit-branches-window ()
+ "Bury the branches buffer and delete its window."
+ (interactive)
+ (quit-window t)
+ (delete-window))
+
+(defun magit--branch-name-at-point ()
+ "Get the branch name in the line at point."
+ (save-excursion
+ (save-match-data
+ (beginning-of-line)
+ (if (not (looking-at "^\s*\\*?\s*\\([^\s]+\\)"))
+ (error "No branch found in current line")
+ (match-string 1)))))
+
+(defun magit-branches-window-checkout ()
+ "Checks out the branch in the line at point."
+ (interactive)
+ (magit-run-git "checkout" (magit--branch-name-at-point))
+ (save-excursion
+ (magit-show-branches)))
+
+(defun magit-remove-branch (&optional force)
+ "Removes the branch in the line at point. With prefix force the
+removal even it it hasn't been merged."
+ (interactive "P")
+ (let ((args (list "branch"
+ (if force "-D" "-d")
+ (magit--branch-name-at-point))))
+ (save-excursion
+ (apply 'magit-run-git args)
+ (magit-show-branches))))
+
+(defun magit-branches-window-manual-merge ()
+ "Merges the branch at point manually."
+ (interactive)
+ (magit-manual-merge (magit--branch-name-at-point))
+ (magit-show-branches))
+
+(defun magit-branches-window-automatic-merge ()
+ "Merges the branch at point automatically."
+ (interactive)
+ (magit-automatic-merge (magit--branch-name-at-point))
+ (magit-show-branches))
+
+(defvar magit-branches-buffer-name "*magit-branches*")
+
(defun magit-show-branches ()
"Show all of the current branches in other-window."
(interactive)
(save-selected-window
- (switch-to-buffer-other-window "*magit-branches*")
- (erase-buffer)
- (insert (magit-git-string "branch" "-va"))
- (insert "\n")))
+ (if (not (string= (buffer-name) magit-branches-buffer-name))
+ (switch-to-buffer-other-window magit-branches-buffer-name))
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (insert (magit-git-string "branch" "-va"))
+ (insert "\n"))
+ (magit-show-branches-mode)
+ (setq buffer-read-only t)))
(defvar magit-ediff-file)
(defvar magit-ediff-windows)
--
1.6.3.3
To unsubscribe from this group, send email to magit+unsubscribegooglegroups.com
or reply to this email with the words "REMOVE ME" as the subject.