From 920c3b3a3c8e2acbd59a99bf42e7c9ac02f1cf1e Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 24 Mar 2010 15:42:55 +0100 Subject: [PATCH] Guess the remote branch name from the branch's "merge" config item If you have a local tracking branch, e.g. called 'test', and the remote branch name is different than test (e.g. 'somwhere/master') then the commands for retrieving the unpulled and unpushed commits was calling "git log test..somwehere/test" which may or may not exist. --- magit.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/magit.el b/magit.el index f64c9fb2..7df878c2 100644 --- a/magit.el +++ b/magit.el @@ -2186,6 +2186,13 @@ must return a string which will represent the log line.") "log" "--pretty=format:* %H %s" (format "%s..HEAD" (magit-get-svn-ref use-cache)))) +(defun magit-remote-branch-for (local-branch) + "Guess the remote branch name that LOCAL-BRANCH is tracking." + (let ((merge (magit-get "branch" local-branch "merge"))) + (save-match-data + (if (and merge (string-match "^refs/heads/\\(.+\\)" merge)) + (match-string 1 merge))))) + ;;; Status (defun magit-remote-string (remote svn-info) @@ -2201,6 +2208,7 @@ must return a string which will represent the log line.") (magit-with-section 'status nil (let* ((branch (magit-get-current-branch)) (remote (and branch (magit-get "branch" branch "remote"))) + (remote-branch (or (and branch (magit-remote-branch-for branch)) branch)) (svn-info (magit-get-svn-ref-info)) (remote-string (magit-remote-string remote svn-info)) (head (magit-git-string @@ -2231,7 +2239,7 @@ must return a string which will represent the log line.") (magit-insert-pending-changes) (magit-insert-pending-commits) (when remote - (magit-insert-unpulled-commits remote branch)) + (magit-insert-unpulled-commits remote remote-branch)) (when svn-info (magit-insert-unpulled-svn-commits t)) (let ((staged (or no-commit (magit-anything-staged-p)))) @@ -2240,7 +2248,7 @@ must return a string which will represent the log line.") (if staged (magit-insert-staged-changes no-commit))) (when remote - (magit-insert-unpushed-commits remote branch)) + (magit-insert-unpushed-commits remote remote-branch)) (when svn-info (magit-insert-unpushed-svn-commits t))))))