From b59f493863011d5b8a52c4b534b52361e7b35b42 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Tue, 8 Jun 2010 11:48:48 +0100 Subject: [PATCH 1/3] Remote tag back in the buffer list. --- magit.el | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/magit.el b/magit.el index 18bf6368..db5a216f 100644 --- a/magit.el +++ b/magit.el @@ -4041,7 +4041,7 @@ With prefix force the removal even it it hasn't been merged." "Extract details from branch -va output." (string-match (concat "^\\(\\*? \\{1,2\\}\\)" ; current branch marker (maybe) - "\\(remotes/\\)?\\(.+?\\) +" ; is it remote, branch name + "\\(.+?\\) +" ; branch name "\\(?:" "\\([0-9a-fA-F]\\{7\\}\\) " ; sha1 @@ -4052,14 +4052,13 @@ With prefix force the removal even it it hasn't been merged." ) branch-line) (let ((res (list (cons 'current (match-string 1 branch-line)) - (cons 'remote (not (not (match-string 2 branch-line)))) - (cons 'branch (match-string 3 branch-line))))) - (if (match-string 5 branch-line) + (cons 'branch (match-string 2 branch-line))))) + (if (match-string 4 branch-line) (cons (cons 'other-ref (match-string 6 branch-line)) res) (append (list - (cons 'sha1 (match-string 4 branch-line)) - (cons 'msg (match-string 6 branch-line))) + (cons 'sha1 (match-string 3 branch-line)) + (cons 'msg (match-string 5 branch-line))) res)))) (defun magit-show-branches () From 78867ac94d1a2663b808475a9e8e7fe62d3cd05d Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Wed, 9 Jun 2010 21:57:10 +0100 Subject: [PATCH 2/3] `magit-maybe-create-local-tracking-branch' allows for no "refs/" string. --- magit.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magit.el b/magit.el index db5a216f..7d2553af 100644 --- a/magit.el +++ b/magit.el @@ -2582,7 +2582,7 @@ With prefix argument, add remaining untracked files as well. ;;; Branches (defun magit-maybe-create-local-tracking-branch (rev) - (if (string-match "^refs/remotes/\\([^/]+\\)/\\(.+\\)" 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))) @@ -4003,7 +4003,7 @@ Return values: (defun magit-branches-window-checkout () "Check out the branch in the line at point." (interactive) - (magit-run-git "checkout" (magit--branch-name-at-point)) + (magit-checkout (magit--branch-name-at-point)) (save-excursion (magit-show-branches))) From fce3ef1fd09bc74e3baf8a9048f373ac3f9c2653 Mon Sep 17 00:00:00 2001 From: Phil Jackson Date: Wed, 9 Jun 2010 22:50:20 +0100 Subject: [PATCH 3/3] User now asked for the name of a local tracking branch. Sensible default given. [R] --- magit.el | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/magit.el b/magit.el index 7d2553af..4cf79334 100644 --- a/magit.el +++ b/magit.el @@ -2581,15 +2581,30 @@ With prefix argument, add remaining untracked files as well. ;;; Branches +(defun magit-get-tracking-name (remote branch) + "Given a REMOTE and a BRANCH name, ask the user for a local +tracking brach name suggesting a sensible default." + (when (yes-or-no-p + (format "Create local tracking branch for %s? " branch)) + (let* ((default-name (concat remote "-" branch)) + (chosen-name (read-string (format "Call local branch (%s): " default-name) + nil + nil + default-name))) + (when (magit-ref-exists-p (concat "refs/heads/" chosen-name)) + (error "'%s' already exists." chosen-name)) + chosen-name))) + (defun magit-maybe-create-local-tracking-branch (rev) + "Depending on the users wishes, create a tracking branch for +rev... maybe." (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)) + (let* ((remote (match-string 1 rev)) + (branch (match-string 2 rev)) + (tracker-name (magit-get-tracking-name remote branch))) + (when tracker-name + (magit-run-git "checkout" "-b" tracker-name rev) + t)) nil)) (defun magit-checkout (revision)