For the "Unpulled:" and "Unpushed:" headings, use the real upstream
branch as computed by `git for-each-ref --format=%(upstream) <ref>`
instead of assuming that the upstream branch is "<remote>/<branch>".
---
 magit.el |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/magit.el b/magit.el
index a533c58..b02f6f3 100644
--- a/magit.el
+++ b/magit.el
@@ -348,6 +348,10 @@ Many Magit faces inherit from this one by default."
        (substring head 11)
       nil)))
 
+(defun magit-get-upstream-branch ()
+  (let* ((head (magit-get-ref "HEAD")))
+    (magit-git-string "for-each-ref" "--format=%(upstream:short)" head)))
+
 (defun magit-ref-exists-p (ref)
   (= (magit-git-exit-code "show-ref" "--verify" ref) 0))
 
@@ -1896,17 +1900,17 @@ in log buffer."
   (or magit-marked-commit
       (error "No commit marked")))
 
-(defun magit-insert-unpulled-commits (remote branch)
+(defun magit-insert-unpulled-commits (upstream)
   (magit-git-section 'unpulled
                     "Unpulled commits:" 'magit-wash-log
                     "log" "--pretty=format:* %H %s"
-                    (format "HEAD..%s/%s" remote branch)))
+                    (format "HEAD..%s" upstream)))
 
-(defun magit-insert-unpushed-commits (remote branch)
+(defun magit-insert-unpushed-commits (upstream)
   (magit-git-section 'unpushed
                     "Unpushed commits:" 'magit-wash-log
                     "log" "--pretty=format:* %H %s"
-                    (format "%s/%s..HEAD" remote branch)))
+                    (format "%s..HEAD" upstream)))
 
 (defun magit-insert-unpulled-svn-commits ()
   (magit-git-section 'svn-unpulled
@@ -1927,6 +1931,9 @@ in log buffer."
     (magit-with-section 'status nil
       (let* ((branch (magit-get-current-branch))
             (remote (and branch (magit-get "branch" branch "remote")))
+             (upstream (and remote
+                            (or (magit-get-upstream-branch)
+                                (format "%s/%s" remote branch))))
              (svn-enabled (magit-svn-enabled))
             (head (magit-git-string
                    "log" "--max-count=1" "--abbrev-commit" "--pretty=oneline"))
@@ -1955,8 +1962,8 @@ in log buffer."
        (magit-insert-topics)
        (magit-insert-pending-changes)
        (magit-insert-pending-commits)
-       (when remote
-         (magit-insert-unpulled-commits remote branch))
+       (when upstream
+         (magit-insert-unpulled-commits upstream))
         (when svn-enabled
           (magit-insert-unpulled-svn-commits))
        (let ((staged (or no-commit (magit-anything-staged-p))))
@@ -1964,8 +1971,8 @@ in log buffer."
           (if staged "Unstaged changes:" "Changes:"))
          (if staged
              (magit-insert-staged-changes no-commit)))
-       (when remote
-         (magit-insert-unpushed-commits remote branch))
+       (when upstream
+         (magit-insert-unpushed-commits upstream))
         (when svn-enabled
           (magit-insert-unpushed-svn-commits))))))
 
-- 
1.6.4.392.g13222.dirty

Reply via email to