Fix `magit--is-branch-at-point-remote'

This commit is contained in:
Phil Jackson 2010-04-01 01:48:28 +01:00
parent bf49b72cf0
commit f735945848

View file

@ -3568,8 +3568,7 @@ Prefix arg means justify as well."
(delete-window)) (delete-window))
(defun magit--branch-name-from-line (line) (defun magit--branch-name-from-line (line)
"Extract the branch name from one line of 'git branch' output. "Extract the branch name from one line of 'git branch' output."
Will remove the 'remotes/' prefix if it exists."
(get-text-property 0 'branch-name line)) (get-text-property 0 'branch-name line))
(defun magit--branch-name-at-point () (defun magit--branch-name-at-point ()
@ -3593,7 +3592,7 @@ With prefix force the removal even it it hasn't been merged."
(interactive "P") (interactive "P")
(let ((args (list "branch" (let ((args (list "branch"
(if force "-D" "-d") (if force "-D" "-d")
(if (magit--is-branch-at-point-remote) "-r") (when (magit--is-branch-at-point-remote) "-r")
(magit--branch-name-at-point)))) (magit--branch-name-at-point))))
(save-excursion (save-excursion
(apply 'magit-run-git (remq nil args)) (apply 'magit-run-git (remq nil args))
@ -3612,18 +3611,16 @@ With prefix force the removal even it it hasn't been merged."
(magit-show-branches)) (magit-show-branches))
(defvar magit-branches-buffer-name "*magit-branches*") (defvar magit-branches-buffer-name "*magit-branches*")
(defvar magit-number-local-branches nil
"Number of local branches for the branches window")
(defun magit--is-branch-at-point-remote() (defun magit--is-branch-at-point-remote()
"Return t if the branch at point is a remote tracking branch" "Return t if the branch at point is a remote tracking branch"
(> (line-number-at-pos) (or magit-number-local-branches 0))) (get-text-property (point) 'remote))
(defun magit--branch-view-details (branch-line) (defun magit--branch-view-details (branch-line)
"Extract details from branch -va output." "Extract details from branch -va output."
(string-match (concat (string-match (concat
"^\\(\\*? \\{1,2\\}\\)" ; current branch marker (maybe) "^\\(\\*? \\{1,2\\}\\)" ; current branch marker (maybe)
"\\(?:remotes/\\)?\\(.+?\\) +" ; branch name "\\(remotes/\\)?\\(.+?\\) +" ; branch name
"\\(?:" "\\(?:"
"\\([0-9a-fA-F]\\{7\\}\\) " ; sha1 "\\([0-9a-fA-F]\\{7\\}\\) " ; sha1
@ -3634,22 +3631,23 @@ With prefix force the removal even it it hasn't been merged."
) )
branch-line) branch-line)
(let ((res (list (cons 'current (match-string 1 branch-line)) (let ((res (list (cons 'current (match-string 1 branch-line))
(cons 'branch (match-string 2 branch-line))))) (cons 'remote (not (not (match-string 2 branch-line))))
(if (match-string 4 branch-line) (cons 'branch (match-string 3 branch-line)))))
(cons (cons 'other-ref (match-string 5 branch-line)) res) (if (match-string 5 branch-line)
(cons (cons 'other-ref (match-string 6 branch-line)) res)
(append (append
(list (list
(cons 'sha1 (match-string 3 branch-line)) (cons 'sha1 (match-string 4 branch-line))
(cons 'msg (match-string 5 branch-line))) (cons 'msg (match-string 6 branch-line)))
res)))) res))))
(defun magit-show-branches () (defun magit-show-branches ()
"Show all of the current branches in other-window." "Show all of the current branches in other-window."
(interactive) (interactive)
(save-selected-window
(unless (string= (buffer-name) magit-branches-buffer-name) (unless (string= (buffer-name) magit-branches-buffer-name)
(switch-to-buffer-other-window magit-branches-buffer-name)) (switch-to-buffer-other-window magit-branches-buffer-name))
(let ((inhibit-read-only t) (let ((inhibit-read-only t)
(old-point (point))
(branches (mapcar 'magit--branch-view-details (branches (mapcar 'magit--branch-view-details
(magit-git-lines "branch" "-va")))) (magit-git-lines "branch" "-va"))))
(erase-buffer) (erase-buffer)
@ -3666,16 +3664,13 @@ With prefix force the removal even it it hasn't been merged."
(cdr (assoc 'branch b)) (cdr (assoc 'branch b))
(when (assoc 'other-ref b) (when (assoc 'other-ref b)
(concat " (" (cdr (assoc 'other-ref b)) ")"))) (concat " (" (cdr (assoc 'other-ref b)) ")")))
'remote (cdr (assoc 'remote b))
'branch-name (cdr (assoc 'branch b)))) 'branch-name (cdr (assoc 'branch b))))
branches branches
"\n"))) "\n"))
(magit-show-branches-mode) (magit-show-branches-mode)
(set (make-local-variable 'magit-number-local-branches) (goto-char old-point))
(with-temp-buffer (setq buffer-read-only t))
(insert (magit-git-string "branch"))
(line-number-at-pos)))
(setq buffer-read-only t)))
(defvar magit-ediff-file) (defvar magit-ediff-file)
(defvar magit-ediff-windows) (defvar magit-ediff-windows)