forked from adoptium/aqa-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
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 resolves: adoptium#4846 Signed-off-by: Anna Babu Palathingal <[email protected]>
- Loading branch information
Showing
2 changed files
with
119 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,110 @@ | ||
#!/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 | ||
echo "Deleting $natives_directory..." | ||
rm -r "$natives_directory" | ||
if [ $? -eq 0 ]; then | ||
echo "Directory deleted successfully." | ||
fi | ||
fi | ||
} | ||
|
||
# Function to perform git clone | ||
git_clone() { | ||
echo "Removing test material and git clone again" | ||
rm -rf "$JCK_ROOT_USED" | ||
# Set the working directory before cloning | ||
cd "$(dirname "$JCK_ROOT_USED")" || exit 1 | ||
git clone --single-branch -b "${jck_branch}" "${JCK_GIT_REPO_USED}" "${JCK_ROOT_USED}" | ||
# Check if the clone was successful | ||
if [ $? -eq 0 ]; then | ||
echo "Repository cloned successfully into $JCK_ROOT_USED" | ||
else | ||
echo "Failed to clone repository" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Function to perform hard reset and pull | ||
perform_hard_reset() { | ||
{ #Try block | ||
echo "Performing hard reset..." | ||
# Fetch changes from the remote repository | ||
git fetch "$JCK_GIT_REPO_USED" | ||
# Reset the local branch to match the remote branch | ||
git reset --hard "FETCH_HEAD" | ||
# Simulate a failure (e.g., by using a non-existent branch) | ||
# Clean untracked files and directories | ||
git clean -dfx | ||
} || { | ||
#Catch block | ||
git_clone | ||
} | ||
# 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 | ||
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 | ||
fi | ||
fi | ||
} | ||
|
||
# Function to check for updates | ||
check_and_handle_updates() { | ||
cd "$JCK_ROOT_USED" || exit | ||
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 "Current Working Directory: $(pwd)" | ||
echo "LocalSHA = --$localSHA--" | ||
echo "RemoteSHA = --$remoteSHA--" | ||
# Check if SHA match | ||
if [ "$localSHA" != "$remoteSHA" ]; then | ||
# Update materials | ||
delete_native_dirs | ||
perform_hard_reset | ||
else | ||
# Set the property indicating that local materials are up-to-date | ||
echo "Local JCK materials up-to-date. Skipping update" | ||
# Discard unstaged changes | ||
git reset --hard | ||
# Discard staged changes | ||
git clean -fdx | ||
local_material_uptodate="true" | ||
fi | ||
# If SHA match or update succeeded | ||
echo "Local JCK materials updated" | ||
} | ||
|
||
# Check if JCK materials exist | ||
if [ -d "$JCK_ROOT_USED" ]; then | ||
# 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 | ||
fi | ||
else | ||
# JCK materials don't exist, git clone | ||
git_clone | ||
fi |