-
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Removes prestaged jck material and reclones it, if git command fails Signed-off-by: Anna Babu Palathingal <[email protected]>
- Loading branch information
Showing
2 changed files
with
159 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#!/bin/bash | ||
# Now you can use these variables in your script | ||
JCK_ROOT_USED="$1" | ||
JCK_GIT_REPO_USED="$2" | ||
jck_branch="$3" | ||
isZOS="$4" | ||
echo "JCK_ROOT_USED is: $JCK_ROOT_USED" | ||
echo "JCK_GIT_REPO_USED is: $JCK_GIT_REPO_USED" | ||
echo "jck_branch is: $jck_branch" | ||
echo "isZOS is: $isZOS" | ||
|
||
delete_native_dirs() { | ||
natives_directory="${JCK_ROOT_USED}/natives" | ||
# Check if the directory exists | ||
if [ -d "$natives_directory" ]; then | ||
# Print a message indicating deletion | ||
echo "Deleting $natives_directory..." | ||
# Delete the directory and its contents | ||
rm -r "$natives_directory" | ||
# Check if deletion was successful | ||
if [ $? -eq 0 ]; then | ||
echo "Directory deleted successfully." | ||
else | ||
echo "Failed to delete directory: $natives_directory" | ||
fi | ||
else | ||
echo "Directory does not exist: $natives_directory" | ||
fi | ||
} | ||
|
||
# Function to perform git clone | ||
git_clone() { | ||
# Set the target directory for cloning | ||
clone_directory="${JCK_ROOT_USED}" | ||
mkdir -p "$(dirname "$clone_directory")" | ||
# Check if the parent directory was created successfully | ||
if [ $? -eq 0 ]; then | ||
# Change into the parent directory | ||
cd "$(dirname "$clone_directory")" || exit 1 | ||
# Clone the repository into the target directory | ||
git clone --single-branch -b "${jck_branch}" "${JCK_GIT_REPO_USED}" "$(basename "$clone_directory")" | ||
# Check if the clone was successful | ||
if [ $? -eq 0 ]; then | ||
echo "Repository cloned successfully into $clone_directory" | ||
else | ||
echo "Failed to clone repository" | ||
exit 1 | ||
fi | ||
else | ||
echo "Failed to create parent directory: $(dirname "$clone_directory")" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Function to remove test material and git clone | ||
remove_and_clone() { | ||
echo "Removing test material and git clone again" | ||
rm -rf "$JCK_ROOT_USED" | ||
git_clone | ||
} | ||
|
||
# Function to perform hard reset and pull | ||
perform_hard_reset_and_pull() { | ||
echo "Performing hard reset..." | ||
git reset --hard "origin/$jck_branch" || { | ||
echo "Hard reset failed. Removing directory and cloning again." | ||
remove_and_clone | ||
} | ||
|
||
# Clean untracked files and directories | ||
git clean -dfx || { | ||
echo "Failed to clean untracked files and directories." | ||
remove_and_clone | ||
} | ||
|
||
# Pull the latest changes | ||
git pull "$JCK_GIT_REPO_USED" "$jck_branch" || { | ||
echo "Pull failed. Removing directory and cloning again." | ||
remove_and_clone | ||
} | ||
} | ||
|
||
# Function to check for updates | ||
check_and_handle_updates() { | ||
local localSHA=$(git rev-parse HEAD) | ||
localSHATrimmed=$(echo "${localSHA}" | tr -d '[:space:]') | ||
local remoteSHA=$(git ls-remote "$JCK_GIT_REPO_USED" "$jck_branch" | cut -f1) | ||
|
||
echo "LocalSHA = --$localSHA--" | ||
echo "RemoteSHA = --$remoteSHA--" | ||
|
||
# Check if SHA match | ||
if [ "$localSHA" != "$remoteSHA" ]; then | ||
# Update materials | ||
delete_native_dirs | ||
echo message="Updating ${JCK_ROOT_USED} with latest..." | ||
cd "${JCK_ROOT_USED}" || exit | ||
git pull "$JCK_GIT_REPO_USED" "$jck_branch" || { | ||
perform_hard_reset_and_pull | ||
} | ||
else | ||
# Set the property indicating that local materials are up-to-date | ||
echo "Local JCK materials up-to-date. Skipping update" | ||
local_material_uptodate="true" | ||
fi | ||
|
||
# If SHA match or update succeeded | ||
echo "Local JCK materials updated" | ||
|
||
# Check if isZOS property is set | ||
if [ -n "$isZOS" ] && [ "$isZOS" = "true" ]; then | ||
# Check if local-material-uptodate property is set | ||
if [ -n "$local_material_uptodate" ]; then | ||
echo "zOS Local JCK materials up-to-date. Skipping hard reset" | ||
else | ||
# Perform hard reset for z/OS | ||
perform_hard_reset_zos | ||
fi | ||
fi | ||
} | ||
|
||
# Function to perform hard reset for z/OS | ||
perform_hard_reset_zos() { | ||
echo "Performing hard reset of ${JCK_ROOT_USED} using .gitattributes.zos for file conversions..." | ||
rm -rf "${JCK_ROOT_USED}/.git/info" | ||
mkdir -p "${JCK_ROOT_USED}/.git/info" | ||
mv "${JCK_ROOT_USED}/.gitattributes.zos" "${JCK_ROOT_USED}/.git/info/attributes" | ||
git rm --cached -r -q . | ||
git reset --hard | ||
} | ||
|
||
# Check if JCK materials exist | ||
if [ -d "$JCK_ROOT_USED" ]; then | ||
# Change into the directory | ||
cd "$JCK_ROOT_USED" || { | ||
echo "Failed to change directory to $JCK_ROOT_USED" | ||
exit 1 | ||
} | ||
# Check if it's a valid Git repository | ||
if [ -d "$JCK_ROOT_USED/.git" ] || git -C "$JCK_ROOT_USED" rev-parse --is-inside-work-tree &>/dev/null; then | ||
echo "The directory is a valid Git repository." | ||
check_and_handle_updates | ||
else | ||
echo "The directory is not a valid Git repository." | ||
remove_and_clone | ||
fi | ||
else | ||
# JCK materials don't exist, git clone | ||
git_clone || remove_and_clone | ||
fi |