jusqu'au test 7

This commit is contained in:
eleonore12345 2024-07-15 18:15:21 +02:00
parent 0c87c46c18
commit 639bd07ee3
2 changed files with 141 additions and 42 deletions

View File

@ -74,8 +74,8 @@ run cd "$dst"
if [ -d .git ] ; then
run git submodule update --init --recursive --force --depth=1 --remote &> /dev/null
run git fetch --tags --depth=1 --prune --prune-tags origin $ref &> /dev/null
run git reset --hard FETCH_HEAD &> /dev/null
run git fetch --tags --depth=1 --prune --prune-tags origin $ref #&> /dev/null
run git reset --hard FETCH_HEAD #&> /dev/null
git reflog expire --expire=now --all &> /dev/null
if "$be_aggressive" ; then
git gc --prune=now --aggressive &> /dev/null
@ -83,8 +83,8 @@ if [ -d .git ] ; then
git gc --prune=now &> /dev/null
fi
# Preserve existing files in some cases
if ! "$nonempty_target" ; then #so we keep uncommitted files when not in -N
git clean -qffdx
if ! "$nonempty_target" ; then #we keep uncommitted files when in -N mode
git clean -qfdx
fi
else

View File

@ -7,11 +7,14 @@ REPO_NAME=performance_testing
REMOTE=ssh://git@git.jean-cloud.net:22529/eleonore/performance_testing.git
WITH_SUBMODULE="true"
FILENAMES=("sample0" "sample1 sample3") #we do not check for all files
FILENAMES_TAG=("sample0")
FILENAMES_TAG=("sample0 sample1 sample4")
FILENAMES_BRANCH=("sample0 sample1 sample2") #we do not check for all files, especially not those specific to the branch.
FILE_ON_BRANCH_ONLY=sample2
FILE_ON_TAG_ONLY=sample4
FILE_ON_MAIN_ONLY=sample3
TAG_NAME=start
FILE_TO_BE_DELETED=sample0
FILE_TO_BE_CREATED=new_file
TAG_NAME=tagging_point
BRANCH_NAME=secondary
TEMP_CLONE_DIR="temp_local_clone"
@ -67,10 +70,10 @@ history_check(){
local repo_name=$1
cd $repo_name
history_result=0
if [ $(git log | grep "commit" | wc -l) -gt 1 ]; then
if [ $(git log | grep "Date" | wc -l) -gt 1 ]; then
echo "Several commits have been saved"
history_result=1
elif [ $(git log | grep "commit" | wc -l) = 1 ]; then
elif [ $(git log | grep "Date" | wc -l) = 1 ]; then
echo "Only the last commit has been saved"
else
history_result=1
@ -115,13 +118,12 @@ make_temporary_clone(){
}
modification_remote(){
local filenames=("$@")
run cd $TEMP_CLONE_DIR
run touch new_file
echo "new text" > new_file
run rm ${filenames[0]}
run git add new_file ${filenames[0]}
run git commit -m "new_file created and ${filenames[0]} deleted" &> /dev/null
run touch $FILE_TO_BE_CREATED
echo "new text" > $FILE_TO_BE_CREATED
run rm $FILE_TO_BE_DELETED
run git add $FILE_TO_BE_CREATED $FILE_TO_BE_DELETED
run git commit -m "$FILE_TO_BE_CREATED created and $FILE_TO_BE_DELETED deleted" &> /dev/null
run git push &> /dev/null
run cd ..
}
@ -133,9 +135,17 @@ undo_modification_remote(){
cd ..
}
modification_local(){
cd $REPO_NAME
touch $FILE_TO_BE_CREATED
echo "different text" > $FILE_TO_BE_CREATED
git add $FILE_TO_BE_CREATED
git commit -m "$FILE_TO_BE_CREATED added"
cd ..
}
modification_check(){
local filenames=("$@")
if [ -f "new_file" ]; then
if [ -f $FILE_TO_BE_CREATED ]; then
echo "The new file has been imported."
modification_result=0
@ -143,11 +153,11 @@ modification_check(){
echo "The new file has not been imported."
modification_result="1"
fi
if [ -f "${filenames[0]}" ]; then
echo "${filenames[0]} has not been deleted."
if [ -f "$FILE_TO_BE_DELETED" ]; then
echo "$FILE_TO_BE_DELETED has not been deleted."
modification_result="1"
else
echo "${filenames[0]} has been deleted."
echo "$FILE_TO_BE_DELETED has been deleted."
fi
}
@ -155,16 +165,44 @@ changing_branch_check(){
if [ -f $FILE_ON_BRANCH_ONLY ]; then
echo "The files of the branch $BRANCH_NAME are present."
branch_changing_result=0
if [ -f $FILE_ON_MAIN_ONLY ]; then
echo "The files of the branch main are present."
branch_changing_result=1
else
echo "The files of the branch main are absent."
branch_changing_result=0
fi
else
echo "The files of the branch $BRANCH_NAME are absent."
branch_changing_result=1
fi
if [ -f $FILE_ON_MAIN_ONLY ]; then
echo "The files of the branch main are present."
branch_changing_result=1
}
changing_tag_check(){
if [ -f $FILE_ON_TAG_ONLY ]; then
echo "The files of the tag $TAG_NAME are present."
tag_changing_result=0
if [ -f $FILE_ON_MAIN_ONLY ]; then
echo "The files of the last commit on main are present."
tag_changing_result=1
else
echo "The files of the last commit in main are absent."
tag_changing_result=0
fi
else
echo "The files of the branch main are absent."
branch_changing_result=0
echo "The files of the tag $TAG_NAME are absent."
tag_changing_result=1
fi
}
conflict_check(){
if [[ $(grep "new" $FILE_TO_BE_CREATED | wc -l) > 0 && $(grep "different" $FILE_TO_BE_CREATED | wc -l) = 0 ]]; then
echo "The remote version has overwritten the local version."
conflict_result=0
else
echo "The remote version has not overwritten the local version."
fi
}
@ -179,7 +217,7 @@ test0 (){
#checks
cloning_check $REPO_NAME ${FILENAMES[@]}
history_check $REPO_NAME
case0=$(($history_result+$cloning_result))
case0=$((history_result+cloning_result))
if [ "$case0" = "0" ]; then
echo "case 0, in a empty directory: OK"
else
@ -200,7 +238,7 @@ test1(){
history_check $REPO_NAME
tag_check $REPO_NAME
case1=$(($cloning_result+$history_result+$tag_result))
case1=$((cloning_result+history_result+tag_result))
if [ $case1 = 0 ]; then
echo "case 1, in a empty directory, with tag: OK"
else
@ -221,7 +259,7 @@ test2(){
history_check $REPO_NAME
branch_check $REPO_NAME
case2=$(($cloning_result+$history_result+$branch_result))
case2=$((cloning_result+history_result+branch_result))
if [ $case2 = 0 ]; then
echo "case 2, in a empty directory, with branch: OK"
else
@ -263,8 +301,9 @@ test3(){
existing_result=1
fi
run cd ..
run rm -rf tmp_dir
case3=$(($cloning_result+$history_result+$existing_result))
#run rm -rf tmp_dir
case3=$((cloning_result+history_result+existing_result))
if [ $case3 = 0 ]; then
echo "case 3, in a non-empty directory : OK"
else
@ -274,7 +313,7 @@ test3(){
}
test4(){
#CASE 4: git updated fast-forward
#CASE 4: git updated fast-forward on main
section TEST4
#if it exists, delete the directory
if [ -d $REPO_NAME ]; then
@ -283,25 +322,27 @@ test4(){
#clone the repo in its last state
run git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
#modify the remote from elsewhere
modification_remote ${FILENAMES[@]}
modification_remote
#make git_update.sh update the repository
run cd $REPO_NAME
run ../git_update.sh $REMOTE
#checks
run modification_check ${FILENAMES[@]}
#cleaning
modification_check
run cd ..
history_check $REPO_NAME
#cleaning
undo_modification_remote
case4=$modification_result
case4=$((modification_result+history_result))
if [ "$case4" = "0" ]; then
echo "case 4, fast-forward update: OK"
echo "case 4, fast-forward update on main: OK"
else
echo "case 4, fast-forward update: FAIL"
echo "case 4, fast-forward update on main: FAIL"
fi
}
test5(){
#CASE 5: git updated, changing to another branch, deleting and adding files in the process
#CASE 5: git updated with underlying conflict on main
section TEST5
#if it exists, delete the directory
if [ -d $REPO_NAME ]; then
@ -309,18 +350,76 @@ test5(){
fi
#clone the repo in its last state
run git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
#modify the local repo
modification_local
#modify the remote from elsewhere
modification_remote
#make git_update.sh update the local repository
run cd $REPO_NAME
run ../git_update.sh $REMOTE
#checks
run conflict_check ${FILENAMES[@]}
#cleaning
run cd ..
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
run rm -rf $REPO_NAME
fi
#clone the repo in its last state
run git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
#call git update with another branch
cd $REPO_NAME
../git_update.sh -r $BRANCH_NAME $REMOTE
#checks
changing_branch_check
case5=$branch_changing_result
if [ "$case5" = "0" ]; then
echo "case 5, branch-changing update: OK"
cd ..
history_check $REPO_NAME
case6=$((branch_changing_result+history_result))
if [ "$case6" = "0" ]; then
echo "case 6, branch-changing update: OK"
else
echo "case 5, branch-changing update: FAIL"
echo "case 6, branch-changing update: FAIL"
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
run rm -rf $REPO_NAME
fi
#clone the repo in its last state
run git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
#call git update with another branch
cd $REPO_NAME
../git_update.sh -r $TAG_NAME $REMOTE
#checks
changing_tag_check
run cd ..
history_check $REPO_NAME
case7=$((tag_changing_result+history_result))
if [ "$case7" = "0" ]; then
echo "case 7, branch-changing update: OK"
else
echo "case 7, branch-changing update: FAIL"
fi
}
#not ff
#ref changed
@ -356,7 +455,7 @@ if [ "$ALL_TESTS" = "true" ]; then
test9
elif [ -n "$TEST_NUM" ]; then
if [ "$TEST_NUM" = 4 ];then
if [[ "$TEST_NUM" = 4 || "$TEST_NUM" = 5 ]];then
make_temporary_clone
fi
case $TEST_NUM in