This commit is contained in:
eleonore12345 2024-07-12 17:17:29 +02:00
parent e8683f850e
commit f0f9fbf3b3

View File

@ -39,27 +39,30 @@ DESCRIPTION
}
cloning_check(){
if [ -d "./$REPO_NAME" ]; then
echo "$REPO_NAME has been created"
cloning_result=0
local FILENAMES=$@
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 folder $REPO_NAME could not be created"
fi
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(){
run cd $REPO_NAME
local repo_name=$1
cd $repo_name
history_result=0
if [ $(git log | grep "commit" | wc -l) -gt 1 ]; then
echo "Several commits have been saved"
@ -74,8 +77,9 @@ history_check(){
}
tag_check(){
run cd $REPO_NAME
run git branch > res
local repo_name=$1
cd $repo_name
run $(git branch) > res
if [ $(grep "no branch" res | wc -l) = 1 ];then
echo "The tag instruction has been respected"
tag_result=0
@ -87,8 +91,9 @@ tag_check(){
}
branch_check(){
run cd $REPO_NAME
run git branch > res
local repo_name=$1
run cd $repo_name
run $(git branch) > res
if [ $(grep $BRANCH_NAME res | wc -l) = 1 ];then
echo "The branch instruction has been respected"
branch_result=0
@ -108,8 +113,8 @@ test0 (){
fi
run ./git_update.sh -d $REPO_NAME $REMOTE
#checks
cloning_check ${FILENAMES[@]}
history_check
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 without history: OK"
@ -127,9 +132,9 @@ test1(){
fi
run ./git_update.sh -d $REPO_NAME -r $TAG_NAME $REMOTE
#checks
cloning_check $FILENAMES_TAG
history_check
tag_check
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
@ -148,18 +153,62 @@ test2(){
fi
run ./git_update.sh -d $REPO_NAME -r $BRANCH_NAME $REMOTE
#checks
cloning_check $FILENAMES_BRANCH #we do not check for all files, especially not those specific to the branch.
history_check
branch_check
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
case1=$(($cloning_result+$history_result+$branch_result))
if [ $case1 = 0 ]; then
echo "case 1, in a empty directory without history, with branch: OK"
case2=$(($cloning_result+$history_result+$branch_result))
if [ $case2 = 0 ]; then
echo "case 2, in a empty directory without history, with branch: OK"
else
echo "case 1, in a empty directory without history, with branch: FAIL"
echo "case 2, in a empty directory without history, 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
cd ..
case3=$(($cloning_result+$history_result+$existing_result))
if [ $case3 = 0 ]; then
echo "case 3, in a non-empty directory without history: OK"
else
echo "case 3, in a non-empty directory without history: FAIL"
fi
}
while getopts ":hn:a" option; do
case $option in