Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation and Linux Makefile improvements #1023

Merged
Merged
Prev Previous commit
Next Next commit
Refactor git_check function to be far more readable
jordancarlin committed Oct 20, 2024
commit 871bae19249344dfee26254ac7b870b1d10b7b37
29 changes: 25 additions & 4 deletions bin/wally-tool-chain-install.sh
Original file line number Diff line number Diff line change
@@ -55,16 +55,37 @@ error() {
}

# Check if a git repository exists, is up to date, and has been installed
# Clones the repository if it doesn't exist
# clones the repository if it doesn't exist
# $1: repo name
# $2: repo url to clone from
# $3: file to check if already installed
# $4: upstream branch, optional, default is master
git_check() {
local repo=$1
local url=$2
local check=$3
local branch="${4:-master}"
if [[ ((! -e $repo) && ($(git clone "$url") || true)) || ($(cd "$repo"; git fetch; git rev-parse HEAD) != $(cd "$repo"; git rev-parse origin/"$branch")) || (! -e $check) ]]; then
return 0

# Clone repo if it doesn't exist
if [[ ! -e $repo ]]; then
git clone "$url"
fi

# Get the current HEAD commit hash and the remote branch commit hash
cd "$repo"
git fetch
local local_head=$(git rev-parse HEAD)
local remote_head=$(git rev-parse origin/"$branch")

# Check if the git repository is not up to date or the specified file does not exist
if [[ "$local_head" != "$remote_head" ]]; then
echo "$repo is not up to date"
true
elif [[ ! -e $check ]]; then
echo "$check does not exist"
true
else
return 1
false
fi
}