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