-(defun git-get-top-dir (dir)
- "Retrieve the top-level directory of a git tree."
- (let ((cdup (with-output-to-string
- (with-current-buffer standard-output
- (cd dir)
- (unless (eq 0 (call-process "git" nil t nil
- "rev-parse" "--show-cdup"))
- (error "cannot find top-level git tree for %s." dir))))))
- (expand-file-name (concat (file-name-as-directory dir)
- (car (split-string cdup "\n"))))))
+(unless (fboundp 'git-get-top-dir)
+ (defun git-get-top-dir (dir)
+ "Retrieve the top-level directory of a git tree."
+ (let ((cdup (with-output-to-string
+ (with-current-buffer standard-output
+ (cd dir)
+ (unless (eq 0 (call-process "git" nil t nil
+ "rev-parse" "--show-cdup"))
+ (error "cannot find top-level git tree for %s." dir))))))
+ (expand-file-name (concat (file-name-as-directory dir)
+ (car (split-string cdup "\n")))))))
+
+(defun stgit-refresh-git-status (&optional dir)
+ "If it exists, refresh the `git-status' buffer belonging to
+directory DIR or `default-directory'"
+ (when (and (fboundp 'git-find-status-buffer)
+ (fboundp 'git-refresh-status))
+ (let* ((top-dir (git-get-top-dir (or dir default-directory)))
+ (git-status-buffer (and top-dir (git-find-status-buffer top-dir))))
+ (when git-status-buffer
+ (with-current-buffer git-status-buffer
+ (git-refresh-status))))))