Add git auto-merge reporting to prompt command.

This commit is contained in:
Darren 'Tadgy' Austin 2023-10-28 23:05:17 +01:00
commit f0dcdf24f6

41
.bashrc
View file

@ -161,7 +161,7 @@ __git_prompt_command() {
# git config ---local -replace-all --type bool script.DisablePromptPrefetch true # git config ---local -replace-all --type bool script.DisablePromptPrefetch true
# Returns: 0 = Tasks completed successfully. # Returns: 0 = Tasks completed successfully.
# 1 = An error occured. # 1 = An error occured.
local GIT_REPO_INFO LC_ALL="C" NOW SANITISED_REPO local GIT_REPO_INFO LC_ALL="C" NOW REPO_TIMESTAMP SANITISED_REPO TIMESTAMP_VAR
# shellcheck disable=SC2207 # shellcheck disable=SC2207
GIT_REPO_INFO=( $( git rev-parse --is-inside-work-tree --show-toplevel 2>/dev/null) ) || return 1 GIT_REPO_INFO=( $( git rev-parse --is-inside-work-tree --show-toplevel 2>/dev/null) ) || return 1
@ -184,16 +184,41 @@ __git_prompt_command() {
NOW="${NOW/.}" NOW="${NOW/.}"
fi fi
# FIXME: This is unfinished. # Make sure the repo path is usable in a variable.
SANITISED_REPO"${GIT_REPO_INFO[1]//[^[:alnum:]]/_}"
# SANITISED_REPO"${GIT_REPO_INFO[1]//[^[:alnum:]]/_}" # Determine the timestamp variable name depending on bash version.
# if (( BASH_VERSINFO[0] >= 4 )); then if (( BASH_VERSINFO[0] >= 4 )); then
# else TIMESTAMP_VAR="GIT_REPO_TIMESTAMP['$SANITISED_REPO']"
# TIMESTAMP_VAR="GIT_REPO_TIMESTAMP_$SANITISED_REPO" else
# [[ -z "${!TIMESTAMP_VAR}" ]] { # This is going to pollute the environment, but Darwin is a PITA.
# "GIT_REPO_TIMESTAMP_$SANITISED_REPO"= TIMESTAMP_VAR="GIT_REPO_TIMESTAMP_$SANITISED_REPO"
fi
if [[ -n "${!TIMESTAMP_VAR}" ]]; then
# Monitor the git repo.
REPO_TIMESTAMP="$(git config --local --get --type int script.AutoMergeLast)"
(( ${!TIMESTAMP_VAR:-0} < REPO_TIMESTAMP )) && {
# Display message depending on status.
if [[ "$(git config --local --get --type int script.AutoMergeSuccess)" == "true" ]]; then
printf "\\033[1;32m%s" "Git auto-merge succeeded for this repo."
if [[ "${GIT_REPO_INFO[1]}" == "$HOME" ]]; then
printf " %s\\033[39m\\n" "Re-source .bash* files."
else
printf "\\033[39m\\n"
fi
# Update the timestamp in the environment.
declare -g "$TIMESTAMP_VAR"="$NOW"
else
printf "\\033[1;31m%s\\033[39m\\n" "Git auto-merge failed for this repo - correct manually." >&2
fi
} }
else
# Just set the timestamp in the environment.
declare -g "$TIMESTAMP_VAR"="$NOW"
fi
}
return 0 return 0
} }