diff --git a/README.md b/README.md index 13a991da..92b6465d 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,19 @@ Set `SCM_GIT_SHOW_STASH_INFO` to 'false' to **don't show** it: * `export SCM_GIT_SHOW_STASH_INFO=false` +### Ahead/Behind Count + +When displaying information regarding whether or not the local branch is ahead or behind it's remote counterpart, you can opt to display the number of commits ahead/behind. +This is useful if you only care whether or not you are ahead or behind and do not care how far ahead/behind you are. + +Set `SCM_GIT_SHOW_COMMIT_COUNT` to 'true' (the default value) to **show** the count of commits ahead/behind: + +* `export SCM_GIT_SHOW_COMMIT_COUNT=true` + +Set `SCM_GIT_SHOW_COMMIT_COUNT` to 'false' to **don't show** it: + +* `export SCM_GIT_SHOW_COMMIT_COUNT=false` + ### Git user In some environments, it is useful to know the value of the current git user, which is used to mark all new commits. diff --git a/test/themes/base.theme.git.bats b/test/themes/base.theme.git.bats index 997b1a59..940121cc 100644 --- a/test/themes/base.theme.git.bats +++ b/test/themes/base.theme.git.bats @@ -72,6 +72,8 @@ setup_repo_with_upstream() { git clone "$remote" clone cd clone + SCM_GIT_SHOW_COMMIT_COUNT=true + git_prompt_vars assert_equal "$SCM_BRANCH" "${pre}" @@ -148,6 +150,7 @@ setup_repo_with_upstream() { pushd "${repo}" SCM_GIT_SHOW_REMOTE_INFO=true + SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars assert_equal "$SCM_BRANCH" "${pre}my-remote${post}" @@ -168,6 +171,7 @@ setup_repo_with_upstream() { pushd "${repo}" SCM_GIT_SHOW_REMOTE_INFO=auto + SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars assert_equal "$SCM_BRANCH" "${pre}${post}" @@ -204,6 +208,7 @@ setup_repo_with_upstream() { git remote add third-remote "$(mktemp -d)" SCM_GIT_SHOW_REMOTE_INFO=false + SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars assert_equal "$SCM_BRANCH" "${pre}${post}" @@ -225,6 +230,7 @@ setup_repo_with_upstream() { pushd "${repo}" SCM_GIT_SHOW_REMOTE_INFO=true + SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars assert_equal "$SCM_BRANCH" "${pre} → my-remote${post}" diff --git a/themes/base.theme.bash b/themes/base.theme.bash index e172dd0c..8d90f043 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -33,6 +33,7 @@ SCM_GIT_IGNORE_UNTRACKED=${SCM_GIT_IGNORE_UNTRACKED:=false} SCM_GIT_SHOW_CURRENT_USER=${SCM_GIT_SHOW_CURRENT_USER:=false} SCM_GIT_SHOW_MINIMAL_INFO=${SCM_GIT_SHOW_MINIMAL_INFO:=false} SCM_GIT_SHOW_STASH_INFO=${SCM_GIT_SHOW_STASH_INFO:=true} +SCM_GIT_SHOW_COMMIT_COUNT=${SCM_GIT_SHOW_COMMIT_COUNT:=true} SCM_GIT='git' SCM_GIT_CHAR='±' @@ -186,8 +187,14 @@ function git_prompt_vars { fi IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)" - [[ "${commits_ahead}" -gt 0 ]] && SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_AHEAD_CHAR}${commits_ahead}" - [[ "${commits_behind}" -gt 0 ]] && SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_BEHIND_CHAR}${commits_behind}" + if [[ "${commits_ahead}" -gt 0 ]]; then + SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_AHEAD_CHAR}" + [[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_ahead}" + fi + if [[ "${commits_behind}" -gt 0 ]]; then + SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_BEHIND_CHAR}" + [[ "${SCM_GIT_SHOW_COMMIT_COUNT}" = "true" ]] && SCM_BRANCH+="${commits_behind}" + fi if [[ "${SCM_GIT_SHOW_STASH_INFO}" = "true" ]]; then local stash_count