From a9aa01c58fb459d79472e7c5c05e4ca841d88e82 Mon Sep 17 00:00:00 2001 From: Omar Al-Ithawi Date: Wed, 5 Jun 2024 17:00:26 +0300 Subject: [PATCH] fix: support Apple Git Ensure atlas reads `git --version` correctly when the output is ``` git version 2.39.3 (Apple Git-146) ``` --- atlas | 2 +- spec/minimum_git_version_spec.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/atlas b/atlas index 82c2187..b214cfc 100755 --- a/atlas +++ b/atlas @@ -451,7 +451,7 @@ display_pull_params() { check_git_version() { MINIMUM_GIT_VERSION="2.25.0" # The `git sparse-checkout` subcommand was introduced in 2.25.0 - GIT_VERSION=$(git --version | grep 'git version' | sed -e 's/git version //g') + GIT_VERSION=$(git --version | grep 'git version' | sed -e 's/ .Apple Git-.*//gI' | sed -e 's/git version //g') # Check if GIT_VERSION is a valid version number if ! echo "$GIT_VERSION" | grep -Eq '^[0-9]+(\.[0-9]+){1,3}$'; diff --git a/spec/minimum_git_version_spec.sh b/spec/minimum_git_version_spec.sh index 1ce66f5..e3e7422 100644 --- a/spec/minimum_git_version_spec.sh +++ b/spec/minimum_git_version_spec.sh @@ -28,6 +28,35 @@ Describe 'Works on version 2.25.0' End +Describe 'Works on Apple git 2.39.3 / Apple Git-146' + git() { + echo 'git version 2.39.3 (Apple Git-146)' + } + + Include ./atlas + + It 'Works' + When call check_git_version + The status should be success + End +End + + +Describe 'Fails on Apple git 2.19.3 / Apple Git-50' + git() { + echo 'git version 2.19.3 (Apple Git-50)' + } + + Include ./atlas + + It 'Detect the version correctly and fails' + When call check_git_version + The output should equal 'Git version 2.19.3 is not supported. Please upgrade to 2.25.0 or higher.' + The status should be failure + End +End + + Describe 'Require git version 2.25.0 at least' git() { echo "git version 2.20.1"