Get only the precise tag number when getting local version, do not show branch name when on master branch(es)

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner 2022-11-14 20:39:34 +00:00
parent ca04c13315
commit cdbe4c9b86
No known key found for this signature in database
GPG Key ID: 872950F3ECF2B173
2 changed files with 15 additions and 6 deletions

View File

@ -17,7 +17,7 @@ function get_local_branch() {
function get_local_version() {
# Return active version
cd "${1}" 2> /dev/null || return 1
git describe --long --dirty --tags 2> /dev/null || return 1
git describe --tags --always 2> /dev/null || return 1
}
function get_local_hash() {

View File

@ -77,18 +77,27 @@ versionOutput() {
[ "$3" = "-c" ] || [ "$3" = "--current" ] || [ -z "$3" ] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}")
[ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}") && branch=$(getLocalBranch "${1}")
fi
# We do not want to show the branch name when we are on master,
# blank out the variable in this case
if [ "$branch" = "master" ]; then
branch=""
else
branch="$branch "
fi
if [ -n "$current" ] && [ -n "$latest" ]; then
output="${1} version is $branch $current (Latest: $latest)"
output="${1} version is $branch$current (Latest: $latest)"
elif [ -n "$current" ] && [ -z "$latest" ]; then
output="Current ${1} version is $branch $current"
output="Current ${1} version is $branch$current"
elif [ -z "$current" ] && [ -n "$latest" ]; then
output="Latest ${1} version is $latest"
elif [ -n "$curHash" ] && [ -n "$latHash" ]; then
output="Local ${1} hash of branch $branch is $curHash (Remote: $latHash)"
output="Local ${1} hash is $curHash (Remote: $latHash)"
elif [ -n "$curHash" ] && [ -z "$latHash" ]; then
output="Current local ${1} hash of branch $branch is $curHash"
output="Current local ${1} hash is $curHash"
elif [ -z "$curHash" ] && [ -n "$latHash" ]; then
output="Latest remote ${1} hash of branch $branch is $latHash"
output="Latest remote ${1} hash is $latHash"
elif [ -z "$curHash" ] && [ -z "$latHash" ]; then
output="Hashes for ${1} not available"
else