implement gitstatusd support

This commit is contained in:
Markus Krause
2019-10-06 12:33:12 +02:00
committed by Noah Gorny
parent e0dba93561
commit 83fdc89ec1
4 changed files with 105 additions and 27 deletions

View File

@@ -9,11 +9,19 @@ function _git-symbolic-ref {
# same commit. _git-branch is used to explicitly choose the checked-out
# branch.
function _git-branch {
git symbolic-ref -q --short HEAD 2> /dev/null || return 1
if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then
test -n "${VCS_STATUS_LOCAL_BRANCH}" && echo "${VCS_STATUS_LOCAL_BRANCH}" || return 1
else
git symbolic-ref -q --short HEAD 2> /dev/null || return 1
fi
}
function _git-tag {
git describe --tags --exact-match 2> /dev/null
if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then
test -n "${VCS_STATUS_TAG}" && echo "${VCS_STATUS_TAG}"
else
git describe --tags --exact-match 2> /dev/null
fi
}
function _git-commit-description {
@@ -21,12 +29,20 @@ function _git-commit-description {
}
function _git-short-sha {
git rev-parse --short HEAD
if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then
echo ${VCS_STATUS_COMMIT:0:7}
else
git rev-parse --short HEAD
fi
}
# Try the checked-out branch first to avoid collision with branches pointing to the same ref.
function _git-friendly-ref {
if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then
_git-branch || _git-tag || _git-short-sha # there is no tag based describe output in gitstatusd
else
_git-branch || _git-tag || _git-commit-description || _git-short-sha
fi
}
function _git-num-remotes {
@@ -101,29 +117,51 @@ function _git-status-counts {
}
function _git-remote-info {
[[ "$(_git-upstream)" == "" ]] && return || true
[[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true || true
local same_branch_name=
[[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && same_branch_name=true
if ([[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]] && [[ "$(_git-num-remotes)" -ge 2 ]]) ||
[[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]]; then
if [[ "${same_branch_name}" != "true" ]]; then
remote_info="\$(_git-upstream)"
else
remote_info="$(_git-upstream-remote)"
if [[ "${SCM_GIT_GITSTATUSD_RAN}" == "true" ]]; then # prompt handling only, reimplement because patching the routine below gets ugly
[[ "${VCS_STATUS_REMOTE_NAME}" == "" ]] && return || true
[[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && local same_branch_name=true || true
local same_branch_name=
[[ "${VCS_STATUS_LOCAL_BRANCH}" == "${VCS_STATUS_REMOTE_BRANCH}" ]] && same_branch_name=true
if [[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]] || [[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]]; then # no multiple remote support in gitstatusd
if [[ "${same_branch_name}" != "true" ]]; then
remote_info="\${VCS_STATUS_REMOTE_NAME}"
else
remote_info="${VCS_STATUS_REMOTE_NAME}/${VCS_STATUS_REMOTE_BRANCH}"
fi
elif [[ ${same_branch_name} != "true" ]]; then
remote_info="\${VCS_STATUS_REMOTE_BRANCH}"
fi
elif [[ ${same_branch_name} != "true" ]]; then
remote_info="\$(_git-upstream-branch)"
fi
if [[ -n "${remote_info}" ]];then
local branch_prefix
if _git-upstream-branch-gone; then
branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX}"
else
branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}"
if [[ -n "${remote_info}" ]];then
local branch_prefix
branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}" # no support for gone remote branches in gitstatusd
echo "${branch_prefix}${remote_info}"
fi
else
[[ "$(_git-upstream)" == "" ]] && return || true
[[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true || true
local same_branch_name=
[[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && same_branch_name=true
if ([[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]] && [[ "$(_git-num-remotes)" -ge 2 ]]) ||
[[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]]; then
if [[ "${same_branch_name}" != "true" ]]; then
remote_info="\$(_git-upstream)"
else
remote_info="$(_git-upstream-remote)"
fi
elif [[ ${same_branch_name} != "true" ]]; then
remote_info="\$(_git-upstream-branch)"
fi
if [[ -n "${remote_info}" ]];then
local branch_prefix
if _git-upstream-branch-gone; then
branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX}"
else
branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}"
fi
echo "${branch_prefix}${remote_info}"
fi
echo "${branch_prefix}${remote_info}"
fi
}