2024-06-24 16:09:48 +00:00
|
|
|
#! /bin/bash
|
2024-06-25 13:52:05 +00:00
|
|
|
#importer driglibash
|
2024-07-11 12:04:25 +00:00
|
|
|
echo "<execution of test_git_update.sh>"
|
|
|
|
|
2024-07-17 09:54:29 +00:00
|
|
|
#Variables definitions
|
2024-07-16 12:41:30 +00:00
|
|
|
REPO_NAME="performance_testing"
|
2024-07-17 09:54:29 +00:00
|
|
|
REMOTE="https://git.jean-cloud.net/eleonore/performance_testing.git"
|
2024-07-11 12:04:25 +00:00
|
|
|
WITH_SUBMODULE="true"
|
2024-07-15 13:44:03 +00:00
|
|
|
FILENAMES=("sample0" "sample1 sample3") #we do not check for all files
|
2024-07-15 16:15:21 +00:00
|
|
|
FILENAMES_TAG=("sample0 sample1 sample4")
|
2024-07-15 13:44:03 +00:00
|
|
|
FILENAMES_BRANCH=("sample0 sample1 sample2") #we do not check for all files, especially not those specific to the branch.
|
2024-07-16 12:41:30 +00:00
|
|
|
FILE_ON_BRANCH_ONLY="sample2"
|
|
|
|
FILE_ON_TAG_ONLY="sample4"
|
|
|
|
FILE_ON_MAIN_ONLY="sample3"
|
|
|
|
FILE_TO_BE_DELETED="sample0"
|
|
|
|
FILE_TO_BE_CREATED="new_file"
|
|
|
|
FILE_TO_BE_MODIFIED=$FILE_TO_BE_CREATED
|
|
|
|
TAG_NAME="tagging_point"
|
|
|
|
TAG_FLAG="tag_flag"
|
|
|
|
BRANCH_NAME="secondary"
|
|
|
|
TMP_CLONE_DIR="tmp_local_clone"
|
|
|
|
TMP_EXISTING_DIR="tmp_existing_dir"
|
|
|
|
TMP_EXISTING_FILE="tmp_existing_file"
|
2024-07-11 12:04:25 +00:00
|
|
|
|
|
|
|
Help()
|
|
|
|
{
|
|
|
|
echo "
|
|
|
|
NAME
|
|
|
|
test_git_update.sh
|
|
|
|
SYNOPSIS
|
|
|
|
test_git_update.sh [-a] [-h] [-n number]
|
|
|
|
OPTIONS
|
|
|
|
-a excutes all the tests.
|
|
|
|
-n number executes test number
|
|
|
|
-h prints the help.
|
2024-07-12 08:10:04 +00:00
|
|
|
DESCRIPTION
|
|
|
|
Tests on the initial cloning
|
|
|
|
TEST0: git cloned in an empty directory
|
|
|
|
TEST1: git cloned in an empty directory with tag
|
|
|
|
TEST2: git cloned in an empty directory with branch
|
2024-07-12 16:30:57 +00:00
|
|
|
TEST3: git cloned in an existing directory
|
2024-07-16 12:41:30 +00:00
|
|
|
TEST4: git updated fast-forward on main
|
|
|
|
TEST5: git updated with underlying conflict on main
|
|
|
|
TEST6: git updated, switching to another branch, deleting and adding files in the process
|
|
|
|
TEST7: git updated, switching to a tag, deleting and adding files in the process
|
|
|
|
TEST8: git updated, before and after changing a tag, deleting and adding files in the process
|
2024-07-12 08:10:04 +00:00
|
|
|
"
|
2024-07-11 12:04:25 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 09:54:29 +00:00
|
|
|
#output function
|
|
|
|
section(){
|
|
|
|
echo "------------------------------ $1 ------------------------------"
|
|
|
|
}
|
2024-07-16 12:41:30 +00:00
|
|
|
#check functions
|
2024-07-11 12:04:25 +00:00
|
|
|
cloning_check(){
|
2024-07-12 15:17:29 +00:00
|
|
|
local input=("$@")
|
|
|
|
local repo_name=${input[0]}
|
|
|
|
local FILENAMES=${input[@]:1}
|
|
|
|
if [[ -d "./$repo_name" ]]; then
|
|
|
|
echo "into $repo_name"
|
|
|
|
cloning_result=0
|
|
|
|
for FILE in ${FILENAMES[@]}
|
|
|
|
do
|
|
|
|
if [ -f "./$repo_name/$FILE" ]; then
|
|
|
|
echo "the file $FILE has correctly been imported"
|
|
|
|
else
|
|
|
|
echo "the file $FILE could not be imported"
|
|
|
|
cloning_result=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
cloning_result=1
|
|
|
|
echo "the directory $repo_name could not be created"
|
|
|
|
fi
|
2024-07-11 12:04:25 +00:00
|
|
|
}
|
2024-06-24 16:09:48 +00:00
|
|
|
|
2024-07-11 12:04:25 +00:00
|
|
|
history_check(){
|
2024-07-12 15:17:29 +00:00
|
|
|
local repo_name=$1
|
|
|
|
cd $repo_name
|
2024-07-11 12:04:25 +00:00
|
|
|
history_result=0
|
2024-07-15 16:15:21 +00:00
|
|
|
if [ $(git log | grep "Date" | wc -l) -gt 1 ]; then
|
2024-07-11 12:04:25 +00:00
|
|
|
echo "Several commits have been saved"
|
|
|
|
history_result=1
|
2024-07-15 16:15:21 +00:00
|
|
|
elif [ $(git log | grep "Date" | wc -l) = 1 ]; then
|
2024-07-11 12:04:25 +00:00
|
|
|
echo "Only the last commit has been saved"
|
|
|
|
else
|
|
|
|
history_result=1
|
|
|
|
echo "Cloning error, incoherent git log"
|
|
|
|
fi
|
|
|
|
cd ..
|
|
|
|
}
|
2024-06-24 16:09:48 +00:00
|
|
|
|
2024-07-11 16:31:19 +00:00
|
|
|
tag_check(){
|
2024-07-12 15:17:29 +00:00
|
|
|
local repo_name=$1
|
|
|
|
cd $repo_name
|
2024-07-12 16:49:24 +00:00
|
|
|
git branch > res
|
|
|
|
if [ $(grep "no branch" res | wc -l) = 1 ]; then
|
2024-07-12 07:54:26 +00:00
|
|
|
echo "The tag instruction has been respected"
|
2024-07-11 16:31:19 +00:00
|
|
|
tag_result=0
|
|
|
|
else
|
2024-07-12 07:54:26 +00:00
|
|
|
echo "The tag instruction has not been respected"
|
2024-07-15 12:32:55 +00:00
|
|
|
tag_result=1
|
2024-07-11 16:31:19 +00:00
|
|
|
fi
|
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
2024-07-12 08:10:04 +00:00
|
|
|
branch_check(){
|
2024-07-12 15:17:29 +00:00
|
|
|
local repo_name=$1
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $repo_name
|
2024-07-12 16:49:24 +00:00
|
|
|
git branch > res
|
2024-07-12 08:10:04 +00:00
|
|
|
if [ $(grep $BRANCH_NAME res | wc -l) = 1 ];then
|
|
|
|
echo "The branch instruction has been respected"
|
|
|
|
branch_result=0
|
|
|
|
else
|
|
|
|
branch_result=1
|
|
|
|
echo "The branch instruction has not been respected"
|
|
|
|
fi
|
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
2024-07-16 12:41:30 +00:00
|
|
|
existing_check(){
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $TMP_EXISTING_DIR
|
2024-07-16 12:41:30 +00:00
|
|
|
if [ -f $TMP_EXISTING_FILE ]; then
|
|
|
|
echo "The preexisting non-conflicting file is still here."
|
|
|
|
existing_result=0
|
2024-07-17 09:54:29 +00:00
|
|
|
cd ..
|
2024-07-16 12:41:30 +00:00
|
|
|
conflict_check $TMP_EXISTING_DIR
|
|
|
|
existing_result=conflict_result
|
|
|
|
else
|
|
|
|
echo "The preexisting non-conflicting file has been deleted."
|
2024-07-17 09:54:29 +00:00
|
|
|
cd ..
|
2024-07-16 12:41:30 +00:00
|
|
|
existing_result=1
|
|
|
|
fi
|
2024-07-15 16:15:21 +00:00
|
|
|
}
|
|
|
|
|
2024-07-15 12:32:55 +00:00
|
|
|
modification_check(){
|
2024-07-16 12:41:30 +00:00
|
|
|
local repo_name=$1
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $repo_name
|
2024-07-15 16:15:21 +00:00
|
|
|
if [ -f $FILE_TO_BE_CREATED ]; then
|
2024-07-15 12:32:55 +00:00
|
|
|
echo "The new file has been imported."
|
|
|
|
modification_result=0
|
|
|
|
|
|
|
|
else
|
|
|
|
echo "The new file has not been imported."
|
|
|
|
modification_result="1"
|
|
|
|
fi
|
2024-07-15 16:15:21 +00:00
|
|
|
if [ -f "$FILE_TO_BE_DELETED" ]; then
|
|
|
|
echo "$FILE_TO_BE_DELETED has not been deleted."
|
2024-07-15 12:32:55 +00:00
|
|
|
modification_result="1"
|
|
|
|
else
|
2024-07-15 16:15:21 +00:00
|
|
|
echo "$FILE_TO_BE_DELETED has been deleted."
|
2024-07-15 12:32:55 +00:00
|
|
|
fi
|
2024-07-17 09:54:29 +00:00
|
|
|
cd ..
|
2024-07-15 12:32:55 +00:00
|
|
|
}
|
|
|
|
|
2024-07-16 12:41:30 +00:00
|
|
|
switching_branch_check(){
|
|
|
|
local repo_name=$1
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $repo_name
|
2024-07-15 13:44:03 +00:00
|
|
|
if [ -f $FILE_ON_BRANCH_ONLY ]; then
|
|
|
|
echo "The files of the branch $BRANCH_NAME are present."
|
2024-07-16 12:41:30 +00:00
|
|
|
branch_switching_result=0
|
2024-07-15 16:15:21 +00:00
|
|
|
if [ -f $FILE_ON_MAIN_ONLY ]; then
|
|
|
|
echo "The files of the branch main are present."
|
2024-07-16 12:41:30 +00:00
|
|
|
branch_switching_result=1
|
2024-07-15 16:15:21 +00:00
|
|
|
else
|
|
|
|
echo "The files of the branch main are absent."
|
2024-07-16 12:41:30 +00:00
|
|
|
branch_switching_result=0
|
2024-07-15 16:15:21 +00:00
|
|
|
fi
|
2024-07-15 13:44:03 +00:00
|
|
|
else
|
|
|
|
echo "The files of the branch $BRANCH_NAME are absent."
|
2024-07-16 12:41:30 +00:00
|
|
|
branch_switching_result=1
|
2024-07-15 13:44:03 +00:00
|
|
|
fi
|
2024-07-16 12:41:30 +00:00
|
|
|
cd ..
|
2024-07-15 16:15:21 +00:00
|
|
|
}
|
|
|
|
|
2024-07-16 12:41:30 +00:00
|
|
|
switching_tag_check(){
|
|
|
|
local repo_name=$1
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $repo_name
|
2024-07-15 16:15:21 +00:00
|
|
|
if [ -f $FILE_ON_TAG_ONLY ]; then
|
|
|
|
echo "The files of the tag $TAG_NAME are present."
|
2024-07-16 12:41:30 +00:00
|
|
|
tag_switching_result=0
|
2024-07-15 16:15:21 +00:00
|
|
|
if [ -f $FILE_ON_MAIN_ONLY ]; then
|
|
|
|
echo "The files of the last commit on main are present."
|
2024-07-16 12:41:30 +00:00
|
|
|
tag_switching_result=1
|
2024-07-15 16:15:21 +00:00
|
|
|
else
|
|
|
|
echo "The files of the last commit in main are absent."
|
2024-07-16 12:41:30 +00:00
|
|
|
tag_switching_result=0
|
2024-07-15 16:15:21 +00:00
|
|
|
fi
|
2024-07-15 13:44:03 +00:00
|
|
|
else
|
2024-07-15 16:15:21 +00:00
|
|
|
echo "The files of the tag $TAG_NAME are absent."
|
2024-07-16 12:41:30 +00:00
|
|
|
tag_switching_result=1
|
2024-07-15 16:15:21 +00:00
|
|
|
fi
|
2024-07-17 09:54:29 +00:00
|
|
|
cd ..
|
2024-07-15 16:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conflict_check(){
|
2024-07-16 12:41:30 +00:00
|
|
|
local repo_name=$1
|
|
|
|
cd $repo_name
|
|
|
|
if [[ $(grep "new" $FILE_TO_BE_MODIFIED | wc -l) > 0 && $(grep "different" $FILE_TO_BE_MODIFIED | wc -l) = 0 ]]; then
|
2024-07-15 16:15:21 +00:00
|
|
|
echo "The remote version has overwritten the local version."
|
|
|
|
conflict_result=0
|
|
|
|
else
|
|
|
|
echo "The remote version has not overwritten the local version."
|
2024-07-15 13:44:03 +00:00
|
|
|
fi
|
2024-07-16 12:41:30 +00:00
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
|
|
|
#intermediate functions
|
|
|
|
make_temporary_existing_dir(){
|
2024-07-17 09:54:29 +00:00
|
|
|
mkdir $TMP_EXISTING_DIR
|
|
|
|
cd $TMP_EXISTING_DIR
|
|
|
|
touch $TMP_EXISTING_FILE
|
|
|
|
touch $FILE_TO_BE_MODIFIED
|
2024-07-16 12:41:30 +00:00
|
|
|
echo "this should be overwritten" > $FILE_TO_BE_MODIFIED
|
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
|
|
|
make_temporary_clone(){
|
|
|
|
mkdir $TMP_CLONE_DIR
|
|
|
|
cd $TMP_CLONE_DIR
|
2024-07-17 09:54:29 +00:00
|
|
|
git clone --recurse-submodules --shallow-submodules --depth 1 --no-single-branch --config core.sshCommand="ssh" $REMOTE . &> /dev/null
|
2024-07-16 12:41:30 +00:00
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
|
|
|
modification_remote(){
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $TMP_CLONE_DIR
|
|
|
|
touch $FILE_TO_BE_CREATED
|
2024-07-16 12:41:30 +00:00
|
|
|
echo "new text" > $FILE_TO_BE_CREATED
|
2024-07-17 09:54:29 +00:00
|
|
|
rm $FILE_TO_BE_DELETED
|
|
|
|
git add $FILE_TO_BE_CREATED $FILE_TO_BE_DELETED &> /dev/null
|
|
|
|
git commit -m "$FILE_TO_BE_CREATED created and $FILE_TO_BE_DELETED deleted" &> /dev/null
|
|
|
|
git push &> /dev/null
|
|
|
|
cd ..
|
2024-07-15 13:44:03 +00:00
|
|
|
}
|
|
|
|
|
2024-07-16 12:41:30 +00:00
|
|
|
undo_modification_remote(){
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $TMP_CLONE_DIR
|
|
|
|
git revert --no-edit HEAD &> /dev/null
|
|
|
|
git push &> /dev/null
|
2024-07-16 12:41:30 +00:00
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
|
|
|
modification_local(){
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $REPO_NAME
|
|
|
|
touch $FILE_TO_BE_CREATED
|
|
|
|
echo "different text" > $FILE_TO_BE_CREATED
|
|
|
|
git add $FILE_TO_BE_CREATED &> /dev/null
|
|
|
|
git commit -m "$FILE_TO_BE_CREATED added" &> /dev/null
|
|
|
|
cd ..
|
2024-07-16 12:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
changing_tag(){
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $TMP_CLONE_DIR
|
|
|
|
git checkout $TAG_NAME &> /dev/null
|
|
|
|
git tag -f $TAG_FLAG &> /dev/null #temporary tag flag to be able to put the tag back here after the test
|
|
|
|
git push -f origin $TAG_FLAG &> /dev/null
|
|
|
|
git checkout $BRANCH_NAME &> /dev/null
|
|
|
|
git tag -f $TAG_NAME &> /dev/null #moving the tag on the branch secondary
|
|
|
|
git push -f origin $TAG_NAME &> /dev/null #push the move to the remote
|
2024-07-16 12:41:30 +00:00
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
|
|
|
undo_changing_tag(){
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $TMP_CLONE_DIR
|
|
|
|
git checkout $TAG_FLAG &> /dev/null
|
|
|
|
git tag -f $TAG_NAME &> /dev/null #move locally
|
|
|
|
git push -f origin $TAG_NAME &> /dev/null #push the move to the remote
|
|
|
|
git push --delete origin $TAG_FLAG &> /dev/null #delete remotely
|
|
|
|
git tag --delete $TAG_FLAG &> /dev/null #delete locally
|
|
|
|
cd ..
|
|
|
|
rm -rf $TMP_CLONE_DIR
|
2024-07-16 12:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-11 12:04:25 +00:00
|
|
|
test0 (){
|
2024-07-12 08:10:04 +00:00
|
|
|
#CASE 0: git cloned in an empty directory
|
2024-07-11 12:04:25 +00:00
|
|
|
section TEST0
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
|
|
|
rm -rf $REPO_NAME
|
|
|
|
fi
|
2024-07-17 09:54:29 +00:00
|
|
|
./git_update.sh -d $REPO_NAME $REMOTE &> /dev/null
|
2024-07-11 12:04:25 +00:00
|
|
|
#checks
|
2024-07-12 15:17:29 +00:00
|
|
|
cloning_check $REPO_NAME ${FILENAMES[@]}
|
|
|
|
history_check $REPO_NAME
|
2024-07-15 16:15:21 +00:00
|
|
|
case0=$((history_result+cloning_result))
|
2024-07-11 16:31:19 +00:00
|
|
|
if [ "$case0" = "0" ]; then
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 0, in a empty directory: OK"
|
2024-07-11 12:04:25 +00:00
|
|
|
else
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 0, in a empty directory: FAIL"
|
2024-07-11 12:04:25 +00:00
|
|
|
fi
|
|
|
|
}
|
2024-06-24 16:09:48 +00:00
|
|
|
|
2024-07-11 12:04:25 +00:00
|
|
|
test1(){
|
|
|
|
#CASE 1: git cloned in an empty directory with tag
|
|
|
|
section TEST1
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
2024-07-17 09:54:29 +00:00
|
|
|
rm -rf $REPO_NAME
|
2024-07-11 12:04:25 +00:00
|
|
|
fi
|
2024-07-17 09:54:29 +00:00
|
|
|
./git_update.sh -d $REPO_NAME -r $TAG_NAME $REMOTE &> /dev/null
|
2024-07-11 12:04:25 +00:00
|
|
|
#checks
|
2024-07-12 15:17:29 +00:00
|
|
|
cloning_check $REPO_NAME ${FILENAMES_TAG[@]}
|
|
|
|
history_check $REPO_NAME
|
|
|
|
tag_check $REPO_NAME
|
2024-06-25 13:52:05 +00:00
|
|
|
|
2024-07-15 16:15:21 +00:00
|
|
|
case1=$((cloning_result+history_result+tag_result))
|
2024-07-11 16:31:19 +00:00
|
|
|
if [ $case1 = 0 ]; then
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 1, in a empty directory, with tag: OK"
|
2024-07-11 12:04:25 +00:00
|
|
|
else
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 1, in a empty directory, with tag: FAIL"
|
2024-07-11 12:04:25 +00:00
|
|
|
fi
|
|
|
|
}
|
2024-06-25 13:52:05 +00:00
|
|
|
|
2024-07-11 12:04:25 +00:00
|
|
|
test2(){
|
2024-07-12 08:10:04 +00:00
|
|
|
#CASE 2: git cloned in an empty directory with branch
|
|
|
|
section TEST2
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
2024-07-17 09:54:29 +00:00
|
|
|
rm -rf $REPO_NAME
|
2024-07-12 08:10:04 +00:00
|
|
|
fi
|
2024-07-17 09:54:29 +00:00
|
|
|
./git_update.sh -d $REPO_NAME -r $BRANCH_NAME $REMOTE &> /dev/null
|
2024-07-12 08:10:04 +00:00
|
|
|
#checks
|
2024-07-12 15:17:29 +00:00
|
|
|
cloning_check $REPO_NAME ${FILENAMES_BRANCH[@]} #we do not check for all files, especially not those specific to the branch.
|
|
|
|
history_check $REPO_NAME
|
|
|
|
branch_check $REPO_NAME
|
2024-06-24 16:09:48 +00:00
|
|
|
|
2024-07-15 16:15:21 +00:00
|
|
|
case2=$((cloning_result+history_result+branch_result))
|
2024-07-12 15:17:29 +00:00
|
|
|
if [ $case2 = 0 ]; then
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 2, in a empty directory, with branch: OK"
|
2024-07-12 08:10:04 +00:00
|
|
|
else
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 2, in a empty directory, with branch: FAIL"
|
2024-07-12 08:10:04 +00:00
|
|
|
fi
|
2024-07-11 12:04:25 +00:00
|
|
|
}
|
|
|
|
|
2024-07-12 15:17:29 +00:00
|
|
|
test3(){
|
|
|
|
#CASE 3: git cloned in an existing directory
|
|
|
|
section TEST3
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
2024-07-17 09:54:29 +00:00
|
|
|
rm -rf $REPO_NAME
|
2024-07-12 15:17:29 +00:00
|
|
|
fi
|
2024-07-16 12:41:30 +00:00
|
|
|
#mimic an existing directory, with two existing file, one with the same name as a to-be-cloned file, and go inside the new dir
|
|
|
|
make_temporary_existing_dir
|
|
|
|
#make git_update.sh clone in the existing dir
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $TMP_EXISTING_DIR
|
|
|
|
../git_update.sh -N $REMOTE &> /dev/null
|
|
|
|
cd ..
|
2024-07-12 15:17:29 +00:00
|
|
|
#checks
|
2024-07-16 12:41:30 +00:00
|
|
|
cloning_check $TMP_EXISTING_DIR ${FILENAMES[@]}
|
|
|
|
history_check $TMP_EXISTING_DIR
|
|
|
|
existing_check
|
2024-07-17 09:54:29 +00:00
|
|
|
rm -rf tmp_existing_dir
|
2024-07-15 16:15:21 +00:00
|
|
|
|
|
|
|
case3=$((cloning_result+history_result+existing_result))
|
2024-07-12 15:17:29 +00:00
|
|
|
if [ $case3 = 0 ]; then
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 3, in a non-empty directory : OK"
|
2024-07-12 15:17:29 +00:00
|
|
|
else
|
2024-07-12 16:30:57 +00:00
|
|
|
echo "case 3, in a non-empty directory : FAIL"
|
2024-07-12 15:17:29 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-07-15 12:32:55 +00:00
|
|
|
test4(){
|
2024-07-15 16:15:21 +00:00
|
|
|
#CASE 4: git updated fast-forward on main
|
2024-07-12 16:30:57 +00:00
|
|
|
section TEST4
|
2024-07-15 12:32:55 +00:00
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
2024-07-17 09:54:29 +00:00
|
|
|
rm -rf $REPO_NAME
|
2024-07-15 12:32:55 +00:00
|
|
|
fi
|
|
|
|
#clone the repo in its last state
|
2024-07-17 09:54:29 +00:00
|
|
|
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
|
2024-07-15 12:32:55 +00:00
|
|
|
#modify the remote from elsewhere
|
2024-07-15 16:15:21 +00:00
|
|
|
modification_remote
|
2024-07-15 12:32:55 +00:00
|
|
|
#make git_update.sh update the repository
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $REPO_NAME
|
|
|
|
../git_update.sh $REMOTE &> /dev/null
|
|
|
|
cd ..
|
2024-07-16 12:41:30 +00:00
|
|
|
#checks
|
|
|
|
modification_check $REPO_NAME
|
2024-07-15 16:15:21 +00:00
|
|
|
history_check $REPO_NAME
|
|
|
|
#cleaning
|
2024-07-15 12:32:55 +00:00
|
|
|
undo_modification_remote
|
2024-07-15 16:15:21 +00:00
|
|
|
|
|
|
|
case4=$((modification_result+history_result))
|
2024-07-15 12:32:55 +00:00
|
|
|
if [ "$case4" = "0" ]; then
|
2024-07-15 16:15:21 +00:00
|
|
|
echo "case 4, fast-forward update on main: OK"
|
2024-07-15 12:32:55 +00:00
|
|
|
else
|
2024-07-15 16:15:21 +00:00
|
|
|
echo "case 4, fast-forward update on main: FAIL"
|
2024-07-15 12:32:55 +00:00
|
|
|
fi
|
2024-07-12 16:30:57 +00:00
|
|
|
}
|
|
|
|
|
2024-07-15 13:44:03 +00:00
|
|
|
test5(){
|
2024-07-15 16:15:21 +00:00
|
|
|
#CASE 5: git updated with underlying conflict on main
|
2024-07-15 13:44:03 +00:00
|
|
|
section TEST5
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
2024-07-17 09:54:29 +00:00
|
|
|
rm -rf $REPO_NAME
|
2024-07-15 13:44:03 +00:00
|
|
|
fi
|
|
|
|
#clone the repo in its last state
|
2024-07-17 09:54:29 +00:00
|
|
|
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
|
2024-07-15 16:15:21 +00:00
|
|
|
#modify the local repo
|
|
|
|
modification_local
|
|
|
|
#modify the remote from elsewhere
|
|
|
|
modification_remote
|
|
|
|
#make git_update.sh update the local repository
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $REPO_NAME
|
|
|
|
../git_update.sh $REMOTE &> /dev/null
|
|
|
|
cd ..
|
2024-07-15 16:15:21 +00:00
|
|
|
#checks
|
2024-07-17 09:54:29 +00:00
|
|
|
conflict_check $REPO_NAME
|
2024-07-15 16:15:21 +00:00
|
|
|
#cleaning
|
|
|
|
undo_modification_remote
|
|
|
|
|
|
|
|
case5=$((conflict_result+history_result))
|
|
|
|
if [ "$case5" = "0" ]; then
|
|
|
|
echo "case 5, update with underlying conflict: OK"
|
|
|
|
else
|
|
|
|
echo "case 5, update with underlying conflict: FAIL"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
test6(){
|
|
|
|
#CASE 6: git updated, switching to another branch, deleting and adding files in the process
|
|
|
|
section TEST6
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
2024-07-17 09:54:29 +00:00
|
|
|
rm -rf $REPO_NAME
|
2024-07-15 16:15:21 +00:00
|
|
|
fi
|
|
|
|
#clone the repo in its last state
|
2024-07-17 09:54:29 +00:00
|
|
|
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
|
2024-07-15 13:44:03 +00:00
|
|
|
#call git update with another branch
|
|
|
|
cd $REPO_NAME
|
2024-07-16 13:51:34 +00:00
|
|
|
../git_update.sh -r $BRANCH_NAME $REMOTE &> /dev/null
|
2024-07-15 16:15:21 +00:00
|
|
|
cd ..
|
2024-07-16 12:41:30 +00:00
|
|
|
#checks
|
|
|
|
switching_branch_check $REPO_NAME
|
2024-07-15 16:15:21 +00:00
|
|
|
history_check $REPO_NAME
|
2024-07-16 12:41:30 +00:00
|
|
|
case6=$((branch_switching_result+history_result))
|
2024-07-15 16:15:21 +00:00
|
|
|
if [ "$case6" = "0" ]; then
|
2024-07-16 12:41:30 +00:00
|
|
|
echo "case 6, branch-switching update: OK"
|
2024-07-15 16:15:21 +00:00
|
|
|
else
|
2024-07-16 12:41:30 +00:00
|
|
|
echo "case 6, branch-switching update: FAIL"
|
2024-07-15 16:15:21 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
test7(){
|
|
|
|
#CASE 7: git updated, switching to a tag, deleting and adding files in the process
|
|
|
|
section TEST7
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
2024-07-17 09:54:29 +00:00
|
|
|
rm -rf $REPO_NAME
|
2024-07-15 16:15:21 +00:00
|
|
|
fi
|
|
|
|
#clone the repo in its last state
|
2024-07-17 09:54:29 +00:00
|
|
|
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
|
2024-07-16 12:41:30 +00:00
|
|
|
#call git_update.sh with a tag
|
2024-07-15 16:15:21 +00:00
|
|
|
cd $REPO_NAME
|
2024-07-16 13:51:34 +00:00
|
|
|
../git_update.sh -r $TAG_NAME $REMOTE &> /dev/null
|
2024-07-17 09:54:29 +00:00
|
|
|
cd ..
|
2024-07-16 12:41:30 +00:00
|
|
|
#checks
|
|
|
|
switching_tag_check $REPO_NAME
|
2024-07-15 16:15:21 +00:00
|
|
|
history_check $REPO_NAME
|
2024-07-16 12:41:30 +00:00
|
|
|
case7=$((tag_switching_result+history_result))
|
2024-07-15 16:15:21 +00:00
|
|
|
if [ "$case7" = "0" ]; then
|
2024-07-16 12:41:30 +00:00
|
|
|
echo "case 7, tag-switching update: OK"
|
2024-07-15 13:44:03 +00:00
|
|
|
else
|
2024-07-16 12:41:30 +00:00
|
|
|
echo "case 7, tag-switching update: FAIL"
|
2024-07-15 13:44:03 +00:00
|
|
|
fi
|
|
|
|
}
|
2024-07-15 16:15:21 +00:00
|
|
|
|
2024-07-16 12:41:30 +00:00
|
|
|
test8(){
|
|
|
|
#CASE 8: git updated, before and after changing a tag, deleting and adding files in the process
|
|
|
|
section TEST8
|
|
|
|
#if it exists, delete the directory
|
|
|
|
if [ -d $REPO_NAME ]; then
|
2024-07-17 09:54:29 +00:00
|
|
|
rm -rf $REPO_NAME
|
2024-07-16 12:41:30 +00:00
|
|
|
fi
|
|
|
|
#clone the repo in its last state
|
2024-07-17 09:54:29 +00:00
|
|
|
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
|
2024-07-16 12:41:30 +00:00
|
|
|
#call git_update.sh with a tag
|
|
|
|
cd $REPO_NAME
|
|
|
|
../git_update.sh -r $TAG_NAME $REMOTE &> /dev/null
|
|
|
|
cd ..
|
|
|
|
#intermediate check to make sure that we are starting on the initial position of the tag
|
|
|
|
echo "first position of the tag"
|
|
|
|
switching_tag_check $REPO_NAME
|
|
|
|
#change the position of the tag from elsewhere
|
|
|
|
changing_tag
|
|
|
|
#call git_update.sh again to go to the new position of the tag
|
2024-07-17 09:54:29 +00:00
|
|
|
cd $REPO_NAME
|
2024-07-16 13:51:34 +00:00
|
|
|
../git_update.sh -r $TAG_NAME $REMOTE &> /dev/null
|
2024-07-17 09:54:29 +00:00
|
|
|
cd ..
|
2024-07-16 12:41:30 +00:00
|
|
|
#put back the remote in its initial state
|
|
|
|
undo_changing_tag
|
2024-07-15 16:15:21 +00:00
|
|
|
|
2024-07-16 12:41:30 +00:00
|
|
|
#checks
|
|
|
|
echo "second position of the tag"
|
|
|
|
switching_branch_check $REPO_NAME #new position of the tag=last commit of the branch hence we can reuse this check
|
|
|
|
history_check $REPO_NAME
|
|
|
|
case8=$((tag_switching_result+branch_switching_result+history_result))
|
|
|
|
if [ "$case8" = "0" ]; then
|
|
|
|
echo "case 8, tag-changing update: OK"
|
|
|
|
else
|
|
|
|
echo "case 8, tag-changing update: FAIL"
|
|
|
|
fi
|
2024-07-12 16:30:57 +00:00
|
|
|
|
2024-07-16 12:41:30 +00:00
|
|
|
}
|
2024-07-12 16:30:57 +00:00
|
|
|
|
2024-07-11 12:04:25 +00:00
|
|
|
while getopts ":hn:a" option; do
|
|
|
|
case $option in
|
|
|
|
h) # display Help
|
|
|
|
Help
|
|
|
|
exit;;
|
|
|
|
n)
|
|
|
|
TEST_NUM=$OPTARG;;
|
|
|
|
a)
|
2024-07-17 09:54:29 +00:00
|
|
|
ALL_TESTS="true";;
|
2024-07-11 12:04:25 +00:00
|
|
|
\?) # Invalid option
|
|
|
|
echo "Error: Invalid option here"
|
|
|
|
exit;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$ALL_TESTS" = "true" ]; then
|
2024-07-16 12:41:30 +00:00
|
|
|
make_temporary_clone
|
2024-07-11 12:04:25 +00:00
|
|
|
test0
|
|
|
|
test1
|
|
|
|
test2
|
|
|
|
test3
|
|
|
|
test4
|
|
|
|
test5
|
|
|
|
test6
|
|
|
|
test7
|
|
|
|
test8
|
2024-07-16 12:41:30 +00:00
|
|
|
rm -rf $TMP_CLONE_DIR
|
2024-07-11 12:04:25 +00:00
|
|
|
elif [ -n "$TEST_NUM" ]; then
|
2024-07-16 12:41:30 +00:00
|
|
|
#in order to only create the temporary clone once if we execute all tests
|
|
|
|
if [[ "$TEST_NUM" = 4 || "$TEST_NUM" = 5 || "$TEST_NUM" = 8 ]]; then
|
2024-07-15 12:32:55 +00:00
|
|
|
make_temporary_clone
|
|
|
|
fi
|
2024-07-11 12:04:25 +00:00
|
|
|
case $TEST_NUM in
|
|
|
|
0)
|
|
|
|
test0;;
|
|
|
|
1)
|
|
|
|
test1;;
|
|
|
|
2)
|
|
|
|
test2;;
|
|
|
|
3)
|
|
|
|
test3;;
|
|
|
|
4)
|
|
|
|
test4;;
|
|
|
|
5)
|
|
|
|
test5;;
|
|
|
|
6)
|
|
|
|
test6;;
|
|
|
|
7)
|
|
|
|
test7;;
|
|
|
|
8)
|
|
|
|
test8;;
|
|
|
|
*)
|
|
|
|
echo "Error: Invalid test number"
|
2024-07-17 09:54:29 +00:00
|
|
|
exit;;
|
2024-07-11 12:04:25 +00:00
|
|
|
esac
|
2024-07-16 13:51:34 +00:00
|
|
|
if [[ "$TEST_NUM" = 4 || "$TEST_NUM" = 5 || "$TEST_NUM" = 8 ]]; then
|
2024-07-16 12:41:30 +00:00
|
|
|
rm -rf $TMP_CLONE_DIR
|
2024-07-15 12:32:55 +00:00
|
|
|
fi
|
2024-07-11 12:04:25 +00:00
|
|
|
else
|
|
|
|
Help
|
2024-07-17 09:54:29 +00:00
|
|
|
fi
|