Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- update_git_repo() {
- local path="$1"
- local url="$2"
- local build_command="$3"
- if [ -z "$build_command" ]; then
- echo "Attempted to call update_git_repo without build_command specified"
- return
- fi
- local repo_name=$(basename "$url" .git)
- local last_built_commit="$path_build/last_built_commit_$repo_name.txt"
- if [ ! -d "$path" ]; then
- echo "Cloning repo from $url to $path"
- git clone "$url" "$path"
- echo "Building $url"
- pushd "$path" > /dev/null
- chmod +x "$build_command"
- eval "$build_command"
- popd > /dev/null
- git -C "$path" rev-parse HEAD > "$last_built_commit"
- binaries_dirty=true
- echo
- return
- fi
- git -C "$path" fetch
- local latest_commit_hash=$(git -C "$path" rev-parse '@{u}')
- local last_built_hash=""
- [ -f "$last_built_commit" ] && last_built_hash=$(cat "$last_built_commit")
- if [ "$latest_commit_hash" = "$last_built_hash" ]; then
- echo
- return
- fi
- echo "Build out of date for: $path, updating"
- echo 'Pulling...'
- git -C "$path" pull
- echo "Building $url"
- pushd "$path" > /dev/null
- chmod +x "$build_command"
- eval "$build_command"
- popd > /dev/null
- echo "$latest_commit_hash" > "$last_built_commit"
- binaries_dirty=true
- echo
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement