Fixed some AI introduced bugs.

This commit is contained in:
Llewellyn van der Merwe 2023-02-14 13:15:46 +02:00
parent 1cd39a8480
commit 7e872210f9
Signed by: Llewellyn
GPG Key ID: A9201372263741E7

View File

@ -188,23 +188,22 @@ setNewRepository() {
setExistingRepository() {
# Notifies the user that the existing repository is being updated.
_echo "[info] Update ($VDM_REPO_NAME) existing repository"
# Checks if there are any changes in the repository.
if [[ -z $(git status --porcelain) ]]; then
# If there are no changes, inform the user.
if [[ -z $(git status --porcelain) ]]; then # ALTERNATIVE: if git diff-index --quiet HEAD --; then
_echo "[info] No changes found in ($VDM_REPO_NAME v$VDM_VERSION) repository"
else
# set repository user details
setUserDetails
# If there are changes, create a commit message.
commit_msg="update"
if ! [ "$(git tag -l "v$VDM_VERSION")" ]; then
commit_msg="$commit_msg - v$VDM_VERSION"
if [ "$(git tag -l "v$VDM_VERSION")" ]; then
setGitCommit "$VDM_VERSION" "update" || return 4
else
setGitCommit "$VDM_VERSION" "update - v$VDM_VERSION" || return 4
fi
# Creates a commit with the message and returns an error code of 4 if unsuccessful.
setGitCommit "$VDM_VERSION" "$commit_msg" || return 4
# Pushes the changes and returns an error code of 1 if unsuccessful.
setPushChanges || return 1
@ -271,9 +270,8 @@ setNewFiles() {
# 4 - if an error occurs during the creation of a commit
setGitInit() {
# Checks if the current directory is a Git repository.
if git rev-parse --git-dir > /dev/null 2>&1; then
# If it is, checks if there are any changes in the repository.
if git diff-index --quiet HEAD --; then
if [ -d ".git" ]; then
if [[ -z $(git status --porcelain) ]]; then # ALTERNATIVE: if git diff-index --quiet HEAD --; then
# If there are no changes, inform the user.
_echo "[info] No changes found in repository"
else
@ -295,6 +293,9 @@ setGitInit() {
# If the current directory is not a Git repository, initialize it.
git init >/dev/null 2>&1 || return 4
# set repository user details
setUserDetails
# Check if there is a version number.
if [ -z "$VDM_VERSION" ]; then
# If there is no version number, create a commit with the "first commit" message.
@ -329,7 +330,7 @@ setGitInit() {
#
# Returns:
# None
setUserDetails () {
function setUserDetails () {
# Set Git author name
if [ -n "${GIT_AUTHOR_NAME+x}" ]; then
git config user.name "${GIT_AUTHOR_NAME}"
@ -378,21 +379,18 @@ setGitCommit() {
git add . >/dev/null 2>&1 || return 1
# Makes a Git commit with the specified commit message.
if ! git commit -am"$2" >/dev/null 2>&1; then
# Return an error code of 1 if the commit was unsuccessful.
return 1
fi
git commit -am"$2" >/dev/null 2>&1 || return 1
# If a version number is provided, create a new Git tag for the commit.
if [ -n "$1" ]; then
# Check if the tag already exists.
if ! git tag -l "v$1" >/dev/null 2>&1; then
if [ "$(git tag -l "v$1")" ]; then
# Return 0 if the function has completed successfully.
return 0
else
# If the tag does not exist, create it.
if ! git tag "v$1" >/dev/null 2>&1; then
# Return an error code of 1 if the tag creation was unsuccessful.
return 1
fi
# Return an error code of 1 if the tag creation was unsuccessful.
git tag "v$1" >/dev/null 2>&1 || return 1
# Notify the user that the tag was added.
_echo "[info] Added v$1 tag"
fi
@ -483,7 +481,8 @@ getPackageDetails() {
find . -type f -name '*.xml' > tmp
# Loop through the list of XML files.
while IFS= read -r file; do
while IFS= read -r file
do
# Skip XML files named config.xml, access.xml, or default.xml.
if [[ "$file" == *"config.xml" ]] || [[ "$file" == *"access.xml" ]] || [[ "$file" == *"default.xml" ]]; then
continue
@ -526,7 +525,7 @@ getPackageDetails() {
unset e
done < tmp
# Remove the tmp file.
# Clear variables for each loop.
rm tmp
# Set the path of the repository for the package.
@ -550,8 +549,8 @@ getPackageDetails() {
# Check if an environment file exists for the package.
env_file="${VDM_ZIP_DIR}/${folder_name}/.${PROGRAM_CODE}"
# If the environment file exists, get the repository name from the file.
if [ -f "${env_file}" ]; then
# If the environment file exists, get the repository name from the file.
env_name=$( grep "repo_name=" "${env_file}" | cut -d'=' -f2)
fi
@ -717,7 +716,7 @@ function getVersionNumberByFile() {
# The modified string.
function rightStrip() {
# Trim the specified pattern from the end of the string.
# Usage: rightStrip "string" "pattern"
printf '%s\n' "${1%%$2}"
}
@ -735,6 +734,7 @@ function rightStrip() {
# Returns:
# The modified string with the pattern removed from the start
function leftStrip() {
# Usage: leftStrip "string" "pattern"
printf '%s\n' "${1##$2}"
}
@ -747,7 +747,7 @@ function leftStrip() {
# Returns:
# 0 if the unzip operation was successful, 1 if the unzip operation was unsuccessful
function _unzip() {
# Set some locals
# Set some locals.
local zip_name="${1}"
local folder_name="${2}"