Merge pull request #1395 from zhao-li/toggle-able_commit_count

Toggle able commit count
pull/1421/head
Nils Winkler 2019-09-02 08:45:19 +02:00 committed by GitHub
commit 721412aa4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -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.

View File

@ -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}"

View File

@ -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