493 lines
13 KiB
Bash
Executable File
493 lines
13 KiB
Bash
Executable File
#! /bin/bash
|
|
#importer driglibash
|
|
. driglibash-base
|
|
echo "<execution of test_git_update.sh>"
|
|
|
|
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 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
|
|
FILE_TO_BE_DELETED=sample0
|
|
FILE_TO_BE_CREATED=new_file
|
|
TAG_NAME=tagging_point
|
|
BRANCH_NAME=secondary
|
|
TEMP_CLONE_DIR="temp_local_clone"
|
|
|
|
if [ "$WITH_SUBMODULE" = "true" ]; then
|
|
bash creation_repo.sh -s &> /dev/null
|
|
else
|
|
bash creation_repo.sh &> /dev/null
|
|
fi
|
|
|
|
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.
|
|
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
|
|
TEST3: git cloned in an existing directory
|
|
"
|
|
}
|
|
|
|
cloning_check(){
|
|
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
|
|
}
|
|
|
|
history_check(){
|
|
local repo_name=$1
|
|
cd $repo_name
|
|
history_result=0
|
|
if [ $(git log | grep "Date" | wc -l) -gt 1 ]; then
|
|
echo "Several commits have been saved"
|
|
history_result=1
|
|
elif [ $(git log | grep "Date" | wc -l) = 1 ]; then
|
|
echo "Only the last commit has been saved"
|
|
else
|
|
history_result=1
|
|
echo "Cloning error, incoherent git log"
|
|
fi
|
|
cd ..
|
|
}
|
|
|
|
tag_check(){
|
|
local repo_name=$1
|
|
cd $repo_name
|
|
git branch > res
|
|
if [ $(grep "no branch" res | wc -l) = 1 ]; then
|
|
echo "The tag instruction has been respected"
|
|
tag_result=0
|
|
else
|
|
echo "The tag instruction has not been respected"
|
|
tag_result=1
|
|
fi
|
|
cd ..
|
|
}
|
|
|
|
branch_check(){
|
|
local repo_name=$1
|
|
run cd $repo_name
|
|
git branch > res
|
|
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 ..
|
|
}
|
|
|
|
make_temporary_clone(){
|
|
mkdir $TEMP_CLONE_DIR
|
|
cd $TEMP_CLONE_DIR
|
|
run git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE . &> /dev/null
|
|
cd ..
|
|
}
|
|
|
|
modification_remote(){
|
|
run cd $TEMP_CLONE_DIR
|
|
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 ..
|
|
}
|
|
|
|
undo_modification_remote(){
|
|
cd $TEMP_CLONE_DIR
|
|
run git revert --no-edit HEAD &> /dev/null
|
|
run git push &> /dev/null
|
|
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(){
|
|
if [ -f $FILE_TO_BE_CREATED ]; then
|
|
echo "The new file has been imported."
|
|
modification_result=0
|
|
|
|
else
|
|
echo "The new file has not been imported."
|
|
modification_result="1"
|
|
fi
|
|
if [ -f "$FILE_TO_BE_DELETED" ]; then
|
|
echo "$FILE_TO_BE_DELETED has not been deleted."
|
|
modification_result="1"
|
|
else
|
|
echo "$FILE_TO_BE_DELETED has been deleted."
|
|
fi
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
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 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
|
|
}
|
|
|
|
test0 (){
|
|
#CASE 0: git cloned in an empty directory
|
|
section TEST0
|
|
#if it exists, delete the directory
|
|
if [ -d $REPO_NAME ]; then
|
|
rm -rf $REPO_NAME
|
|
fi
|
|
run ./git_update.sh -d $REPO_NAME $REMOTE
|
|
#checks
|
|
cloning_check $REPO_NAME ${FILENAMES[@]}
|
|
history_check $REPO_NAME
|
|
case0=$((history_result+cloning_result))
|
|
if [ "$case0" = "0" ]; then
|
|
echo "case 0, in a empty directory: OK"
|
|
else
|
|
echo "case 0, in a empty directory: FAIL"
|
|
fi
|
|
}
|
|
|
|
test1(){
|
|
#CASE 1: git cloned in an empty directory with tag
|
|
section TEST1
|
|
#if it exists, delete the directory
|
|
if [ -d $REPO_NAME ]; then
|
|
run rm -rf $REPO_NAME
|
|
fi
|
|
run ./git_update.sh -d $REPO_NAME -r $TAG_NAME $REMOTE
|
|
#checks
|
|
cloning_check $REPO_NAME ${FILENAMES_TAG[@]}
|
|
history_check $REPO_NAME
|
|
tag_check $REPO_NAME
|
|
|
|
case1=$((cloning_result+history_result+tag_result))
|
|
if [ $case1 = 0 ]; then
|
|
echo "case 1, in a empty directory, with tag: OK"
|
|
else
|
|
echo "case 1, in a empty directory, with tag: FAIL"
|
|
fi
|
|
}
|
|
|
|
test2(){
|
|
#CASE 2: git cloned in an empty directory with branch
|
|
section TEST2
|
|
#if it exists, delete the directory
|
|
if [ -d $REPO_NAME ]; then
|
|
run rm -rf $REPO_NAME
|
|
fi
|
|
run ./git_update.sh -d $REPO_NAME -r $BRANCH_NAME $REMOTE
|
|
#checks
|
|
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
|
|
|
|
case2=$((cloning_result+history_result+branch_result))
|
|
if [ $case2 = 0 ]; then
|
|
echo "case 2, in a empty directory, with branch: OK"
|
|
else
|
|
echo "case 2, in a empty directory, with branch: FAIL"
|
|
fi
|
|
}
|
|
|
|
test3(){
|
|
#CASE 3: git cloned in an existing directory
|
|
section TEST3
|
|
#if it exists, delete the directory
|
|
if [ -d $REPO_NAME ]; then
|
|
run rm -rf $REPO_NAME
|
|
fi
|
|
#mimic an existing directory, with two existing file, one with the same name as a to-be-cloned file
|
|
run mkdir tmp_dir
|
|
run cd tmp_dir
|
|
run touch tmp_file
|
|
run touch "${FILENAMES[0]}"
|
|
echo "this should be overwritten" > ${FILENAMES[0]}
|
|
run ../git_update.sh -N $REMOTE
|
|
run cd ..
|
|
#checks
|
|
cloning_check "tmp_dir" ${FILENAMES[@]}
|
|
history_check $"tmp_dir"
|
|
#existing check
|
|
cd tmp_dir
|
|
if [ -f tmp_file ]; then
|
|
echo "The preexisting non-conflicting file is still here."
|
|
existing_result=0
|
|
if [ $(grep "overwritten" ${FILENAMES[0]} | wc -l) = 0 ]; then
|
|
echo "The conflicting files have been overwitten."
|
|
else
|
|
echo "The conflicting existing files have not been overwritten."
|
|
existing_result=1
|
|
fi
|
|
else
|
|
echo "The preexisting non-conflicting file has been deleted."
|
|
existing_result=1
|
|
fi
|
|
run cd ..
|
|
#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
|
|
echo "case 3, in a non-empty directory : FAIL"
|
|
fi
|
|
|
|
}
|
|
|
|
test4(){
|
|
#CASE 4: git updated fast-forward on main
|
|
section TEST4
|
|
#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
|
|
#modify the remote from elsewhere
|
|
modification_remote
|
|
#make git_update.sh update the repository
|
|
run cd $REPO_NAME
|
|
run ../git_update.sh $REMOTE
|
|
#checks
|
|
modification_check
|
|
run cd ..
|
|
history_check $REPO_NAME
|
|
#cleaning
|
|
undo_modification_remote
|
|
|
|
case4=$((modification_result+history_result))
|
|
if [ "$case4" = "0" ]; then
|
|
echo "case 4, fast-forward update on main: OK"
|
|
else
|
|
echo "case 4, fast-forward update on main: FAIL"
|
|
fi
|
|
}
|
|
|
|
test5(){
|
|
#CASE 5: git updated with underlying conflict on main
|
|
section TEST5
|
|
#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
|
|
#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
|
|
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 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
|
|
|
|
|
|
|
|
|
|
|
|
while getopts ":hn:a" option; do
|
|
case $option in
|
|
h) # display Help
|
|
Help
|
|
exit;;
|
|
n)
|
|
TEST_NUM=$OPTARG;;
|
|
a)
|
|
ALL_TESTS=true;;
|
|
\?) # Invalid option
|
|
echo "Error: Invalid option here"
|
|
exit;;
|
|
esac
|
|
done
|
|
|
|
if [ "$ALL_TESTS" = "true" ]; then
|
|
test0
|
|
test1
|
|
test2
|
|
test3
|
|
test4
|
|
test5
|
|
test6
|
|
test7
|
|
test8
|
|
test9
|
|
|
|
elif [ -n "$TEST_NUM" ]; then
|
|
if [[ "$TEST_NUM" = 4 || "$TEST_NUM" = 5 ]];then
|
|
make_temporary_clone
|
|
fi
|
|
case $TEST_NUM in
|
|
0)
|
|
test0;;
|
|
1)
|
|
test1;;
|
|
2)
|
|
test2;;
|
|
3)
|
|
test3;;
|
|
4)
|
|
test4;;
|
|
5)
|
|
test5;;
|
|
6)
|
|
test6;;
|
|
7)
|
|
test7;;
|
|
8)
|
|
test8;;
|
|
9)
|
|
test9;;
|
|
*)
|
|
echo "Error: Invalid test number"
|
|
die;;
|
|
esac
|
|
if [ "$TEST_NUM" = 4 ];then
|
|
rm -rf $TEMP_CLONE_DIR
|
|
fi
|
|
else
|
|
Help
|
|
fi
|
|
|