From 736d45a75fe9ef8b2465b93c6def8f72060fc2ae Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Wed, 7 Jul 2021 17:08:20 +0200 Subject: [PATCH 1/3] Fix git::get_commit_tag, added git::is_valid_commit --- scripts/core/src/git.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/core/src/git.sh b/scripts/core/src/git.sh index a10c9f018..9839674b1 100755 --- a/scripts/core/src/git.sh +++ b/scripts/core/src/git.sh @@ -42,15 +42,16 @@ git::current_commit_hash() { git rev-parse HEAD "$@" } +git::is_valid_commit() { + local -r commit="${1:-HEAD}" + git::is_in_repo && [[ $(git cat-file -t "$commit") == commit ]] +} + # shellcheck disable=SC2120 git::get_commit_tag() { - local commit - if git::is_in_repo; then - commit="${1:-}" - { [[ -n "$commit" ]] && shift; } || commit="$(git::current_commit_hash)" + local -r commit="${1:-HEAD}" - git show-ref --tags "$@" | grep "$commit" | awk '{print $2}' | sed 's#refs/tags/##' - fi + git::is_in_repo && git::is_valid_commit "$commit" && git tag --points-at "$commit" } git::get_current_latest_tag() { From 35ccbd3f0894f53a81ea3152791d8497b9916fd5 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Wed, 7 Jul 2021 17:23:21 +0200 Subject: [PATCH 2/3] Fixes in git and delete all set +e --- scripts/core/src/git.sh | 13 ++++++++++++- scripts/core/src/update.sh | 2 -- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/core/src/git.sh b/scripts/core/src/git.sh index 9839674b1..ddfbd1a63 100755 --- a/scripts/core/src/git.sh +++ b/scripts/core/src/git.sh @@ -55,7 +55,18 @@ git::get_commit_tag() { } git::get_current_latest_tag() { - git::get_all_local_tags | head -n1 + local version latest + + for version in $(git::get_all_local_tags); do + if + [[ -z "${latest:-}" ]] || + [[ $(platform::semver_compare "$latest" "$version" 2>/dev/null) -eq -1 ]] + then + latest="$version" + fi + done + + echo "$latest" } # shellcheck disable=SC2120 diff --git a/scripts/core/src/update.sh b/scripts/core/src/update.sh index 2bc0e3e29..d59a3bb20 100644 --- a/scripts/core/src/update.sh +++ b/scripts/core/src/update.sh @@ -65,7 +65,6 @@ update::check_if_is_stable_update() { # shellcheck disable=SC2120 update::update_sloth_repository() { local current_directory current_branch update_submodules return_code - set +e # Defaults values that are needed here current_directory="$(pwd)" @@ -120,7 +119,6 @@ update::check_consistency_with_sloth_version() { update::update_local_sloth_module() { local current_sloth_hash local_sloth_version remote_sloth_minor remote_sloth_tag - set +e # Avoid crash if any function fail current_sloth_hash="$(git::get_local_HEAD_hash)" local_sloth_version="$(git::sloth_repository_exec git::get_commit_tag)" From 5e674e4546aeadf8d88fcd93fd2e6b39e54783d3 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Wed, 7 Jul 2021 17:24:24 +0200 Subject: [PATCH 3/3] Applied linter --- scripts/core/src/git.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/core/src/git.sh b/scripts/core/src/git.sh index ddfbd1a63..8c47d7840 100755 --- a/scripts/core/src/git.sh +++ b/scripts/core/src/git.sh @@ -60,7 +60,7 @@ git::get_current_latest_tag() { for version in $(git::get_all_local_tags); do if [[ -z "${latest:-}" ]] || - [[ $(platform::semver_compare "$latest" "$version" 2>/dev/null) -eq -1 ]] + [[ $(platform::semver_compare "$latest" "$version" 2> /dev/null) -eq -1 ]] then latest="$version" fi