Git Current Remote

Make function definitions consistent. Copy current_branch from plugin and
rename to git_current_branch. Exchange usage of current_branch with
git_current_branch. Add helper function to get the current branch's remote.
Update git_prompts_ahead to use git_current_remote instead of origin. Add
git_prompt_behind.
This commit is contained in:
Andrew Hodges 2011-05-29 12:22:00 -04:00
commit 77f3689b82

View file

@ -5,7 +5,7 @@ function git_prompt_info() {
}
# Checks if working tree is dirty
parse_git_dirty() {
function parse_git_dirty() {
if [[ -n $(git status -s 2> /dev/null) ]]; then
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
else
@ -15,11 +15,17 @@ parse_git_dirty() {
# Checks if there are commits ahead from remote
function git_prompt_ahead() {
if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
if $(echo "$(git log $(git_current_remote)/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
}
function git_prompt_behind() {
if $(echo "$(git log HEAD..$(git_current_remote)/$(git_current_branch) 2> /dev/null)" | grep '^commit' &> /dev/null); then
echo "$ZSH_THEME_GIT_PROMPT_BEHIND"
fi
}
# Formats prompt string for current git commit short SHA
function git_prompt_short_sha() {
SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
@ -31,7 +37,7 @@ function git_prompt_long_sha() {
}
# Get the status of the working tree
git_prompt_status() {
function git_prompt_status() {
INDEX=$(git status --porcelain 2> /dev/null)
STATUS=""
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
@ -60,3 +66,17 @@ git_prompt_status() {
fi
echo $STATUS
}
function git_current_branch() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
function git_current_remote() {
remote=$(git config --get "branch.$(git_current_branch).remote")
if [ -z "$remote" ]; then
echo 'origin'
else
echo "$remote"
fi
}