Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Tip of the day: vcs_info git: ahead/behind the upstream branch indication



The following vcs_info hook adds an indication of whether the currently
checked out branch is ahead or behind its upstream branch:

    # Add up/down arrows after branch name, if there are changes to pull/to push
    zstyle ':vcs_info:git+post-backend:*' hooks git-post-backend-updown
    +vi-git-post-backend-updown() {
      git rev-parse @{upstream} >/dev/null 2>&1 || return
      local -a x; x=( $(git rev-list --left-right --count HEAD...@{upstream} ) )
      hook_com[branch]+="%f" # end coloring
      (( x[2] )) && hook_com[branch]+="↓"
      (( x[1] )) && hook_com[branch]+="↑"
      return 0
    }

For example:

    ### Behind upstream (after 'git fetch')
     (git)-[master↓]-                                                               
    % 

    ### Ahead of upstream (before 'git push')
     (git)-[master↑]-                                                               
    % 

    ### Diverged (each of upstream and local branch has commits the other doesn't have; a rebase/force-push situation)
     (git)-[master↓↑]-                                                               
    % 



Messages sorted by: Reverse Date, Date, Thread, Author