local remote
This commit is contained in:
parent
2d2ff93a45
commit
369e86ca7d
@ -2,26 +2,6 @@
|
||||
#importer driglibash
|
||||
echo "<execution of test_git_update.sh>"
|
||||
|
||||
#Variables definitions
|
||||
REPO_NAME="performance_testing"
|
||||
REMOTE="https://git.jean-cloud.net/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"
|
||||
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"
|
||||
|
||||
Help()
|
||||
{
|
||||
echo "
|
||||
@ -38,8 +18,8 @@ DESCRIPTION
|
||||
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
|
||||
TEST4: git updated fast-forward on main
|
||||
TEST3: git updated fast-forward on main
|
||||
TEST4: git updated fast-forward on main with untracked file
|
||||
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
|
||||
@ -47,6 +27,28 @@ DESCRIPTION
|
||||
"
|
||||
}
|
||||
|
||||
#Variables definitions
|
||||
WORKING_DIRECTORY=$(pwd)
|
||||
REMOTE="file://${WORKING_DIRECTORY}/remote/git_update_testing" #we must trick git_update.sh into thinking we are not working in local, otherwise depth=1 is not respected
|
||||
LOCAL_REMOTE="/${WORKING_DIRECTORY}/remote/git_update_testing" #cd does not understand file://
|
||||
REPO_NAME="git_update_testing"
|
||||
WITH_SUBMODULE="true"
|
||||
FILENAMES=("sample0" "sample1 sample3")
|
||||
FILENAMES_TAG=("sample0 sample1 sample4")
|
||||
FILENAMES_BRANCH=("sample0 sample1 sample2")
|
||||
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
|
||||
UNTRACKED_FILE="untracked_file"
|
||||
TAG_NAME="tagging_point"
|
||||
TAG_FLAG="tag_flag"
|
||||
BRANCH_NAME="secondary"
|
||||
|
||||
bash creation_repo.sh -s &> /dev/null
|
||||
|
||||
#output function
|
||||
section(){
|
||||
echo "------------------------------ $1 ------------------------------"
|
||||
@ -118,18 +120,19 @@ branch_check(){
|
||||
cd ..
|
||||
}
|
||||
|
||||
existing_check(){
|
||||
cd $TMP_EXISTING_DIR
|
||||
if [ -f $TMP_EXISTING_FILE ]; then
|
||||
echo "The preexisting non-conflicting file is still here."
|
||||
existing_result=0
|
||||
untracked_check(){
|
||||
local repo_name=$1
|
||||
cd $repo_name
|
||||
if [ -f $UNTRACKED_FILE ]; then
|
||||
echo "The untracked file is still here."
|
||||
untracked_result=0
|
||||
cd ..
|
||||
conflict_check $TMP_EXISTING_DIR
|
||||
existing_result=conflict_result
|
||||
conflict_check $repo_name
|
||||
untracked_result=conflict_result
|
||||
else
|
||||
echo "The preexisting non-conflicting file has been deleted."
|
||||
echo "The untracked file has been deleted."
|
||||
cd ..
|
||||
existing_result=1
|
||||
untracked_result=1
|
||||
fi
|
||||
}
|
||||
|
||||
@ -206,42 +209,41 @@ conflict_check(){
|
||||
}
|
||||
|
||||
#intermediate functions
|
||||
make_temporary_existing_dir(){
|
||||
mkdir $TMP_EXISTING_DIR
|
||||
cd $TMP_EXISTING_DIR
|
||||
touch $TMP_EXISTING_FILE
|
||||
touch $FILE_TO_BE_MODIFIED
|
||||
echo "this should be overwritten" > $FILE_TO_BE_MODIFIED
|
||||
cd ..
|
||||
}
|
||||
|
||||
make_temporary_clone(){
|
||||
mkdir $TMP_CLONE_DIR
|
||||
cd $TMP_CLONE_DIR
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 --no-single-branch --config core.sshCommand="ssh" $REMOTE . &> /dev/null
|
||||
cd ..
|
||||
}
|
||||
|
||||
modification_remote(){
|
||||
cd $TMP_CLONE_DIR
|
||||
echo "remote : $LOCAL_REMOTE"
|
||||
echo "pwd : $(pwd)"
|
||||
cd $LOCAL_REMOTE
|
||||
touch $FILE_TO_BE_CREATED
|
||||
echo "new text" > $FILE_TO_BE_CREATED
|
||||
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 ..
|
||||
git commit -m "$FILE_TO_BE_CREATED created and $FILE_TO_BE_DELETED deleted" #&> /dev/null
|
||||
cd ../..
|
||||
}
|
||||
|
||||
undo_modification_remote(){
|
||||
cd $TMP_CLONE_DIR
|
||||
cd $LOCAL_REMOTE
|
||||
git revert --no-edit HEAD &> /dev/null
|
||||
git push &> /dev/null
|
||||
cd ../..
|
||||
}
|
||||
|
||||
add_untracked_file(){
|
||||
local repo_name=$1
|
||||
cd $repo_name
|
||||
touch $UNTRACKED_FILE
|
||||
cd ..
|
||||
}
|
||||
|
||||
remove_untracked_file(){
|
||||
local repo_name=$1
|
||||
cd $repo_name
|
||||
touch $UNTRACKED_FILE
|
||||
cd ..
|
||||
}
|
||||
|
||||
modification_local(){
|
||||
cd $REPO_NAME
|
||||
local repo_name=$1
|
||||
cd $repo_name
|
||||
touch $FILE_TO_BE_CREATED
|
||||
echo "different text" > $FILE_TO_BE_CREATED
|
||||
git add $FILE_TO_BE_CREATED &> /dev/null
|
||||
@ -250,25 +252,20 @@ modification_local(){
|
||||
}
|
||||
|
||||
changing_tag(){
|
||||
cd $TMP_CLONE_DIR
|
||||
cd $LOCAL_REMOTE
|
||||
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
|
||||
cd ..
|
||||
cd ../..
|
||||
}
|
||||
|
||||
undo_changing_tag(){
|
||||
cd $TMP_CLONE_DIR
|
||||
cd $LOCAL_REMOTE
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@ -279,7 +276,7 @@ test0 (){
|
||||
if [ -d $REPO_NAME ]; then
|
||||
rm -rf $REPO_NAME
|
||||
fi
|
||||
./git_update.sh -d $REPO_NAME $REMOTE &> /dev/null
|
||||
./git_update.sh -d $REPO_NAME $REMOTE #&> /dev/null
|
||||
#checks
|
||||
cloning_check $REPO_NAME ${FILENAMES[@]}
|
||||
history_check $REPO_NAME
|
||||
@ -334,42 +331,14 @@ test2(){
|
||||
}
|
||||
|
||||
test3(){
|
||||
#CASE 3: git cloned in an existing directory
|
||||
#CASE 3: git updated fast-forward on main
|
||||
section TEST3
|
||||
#if it exists, delete the directory
|
||||
if [ -d $REPO_NAME ]; then
|
||||
rm -rf $REPO_NAME
|
||||
fi
|
||||
#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
|
||||
cd $TMP_EXISTING_DIR
|
||||
../git_update.sh -N $REMOTE &> /dev/null
|
||||
cd ..
|
||||
#checks
|
||||
cloning_check $TMP_EXISTING_DIR ${FILENAMES[@]}
|
||||
history_check $TMP_EXISTING_DIR
|
||||
existing_check
|
||||
rm -rf tmp_existing_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
|
||||
rm -rf $REPO_NAME
|
||||
fi
|
||||
#clone the repo in its last state
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 $REMOTE &> /dev/null
|
||||
#modify the remote from elsewhere
|
||||
modification_remote
|
||||
#make git_update.sh update the repository
|
||||
@ -382,11 +351,44 @@ test4(){
|
||||
#cleaning
|
||||
undo_modification_remote
|
||||
|
||||
case4=$((modification_result+history_result))
|
||||
if [ "$case4" = "0" ]; then
|
||||
echo "case 4, fast-forward update on main: OK"
|
||||
case3=$((modification_result+history_result))
|
||||
if [ "$case3" = "0" ]; then
|
||||
echo "case 3, fast-forward update on main: OK"
|
||||
else
|
||||
echo "case 4, fast-forward update on main: FAIL"
|
||||
echo "case 3, fast-forward update on main: FAIL"
|
||||
fi
|
||||
}
|
||||
|
||||
test4(){
|
||||
#CASE 4: git updated fast-forward on main with untracked file
|
||||
section TEST4
|
||||
#if it exists, delete the directory
|
||||
if [ -d $REPO_NAME ]; then
|
||||
rm -rf $REPO_NAME
|
||||
fi
|
||||
#clone the repo in its last state
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 $REMOTE &> /dev/null
|
||||
#modify the remote from elsewhere
|
||||
modification_remote
|
||||
#add an untracked file
|
||||
add_untracked_file $REPO_NAME
|
||||
#make git_update.sh update the repository
|
||||
cd $REPO_NAME
|
||||
../git_update.sh $REMOTE &> /dev/null
|
||||
cd ..
|
||||
#checks
|
||||
modification_check $REPO_NAME
|
||||
history_check $REPO_NAME
|
||||
untracked_check $REPO_NAME
|
||||
#cleaning
|
||||
undo_modification_remote
|
||||
remove_untracked_file $REPO_NAME
|
||||
|
||||
case3=$((modification_result+history_result+untracked_result))
|
||||
if [ "$case3" = "0" ]; then
|
||||
echo "case 3, fast-forward update on main: OK"
|
||||
else
|
||||
echo "case 3, fast-forward update on main: FAIL"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -398,9 +400,9 @@ test5(){
|
||||
rm -rf $REPO_NAME
|
||||
fi
|
||||
#clone the repo in its last state
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 $REMOTE &> /dev/null
|
||||
#modify the local repo
|
||||
modification_local
|
||||
modification_local $REPO_NAME
|
||||
#modify the remote from elsewhere
|
||||
modification_remote
|
||||
#make git_update.sh update the local repository
|
||||
@ -428,7 +430,7 @@ test6(){
|
||||
rm -rf $REPO_NAME
|
||||
fi
|
||||
#clone the repo in its last state
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 $REMOTE &> /dev/null
|
||||
#call git update with another branch
|
||||
cd $REPO_NAME
|
||||
../git_update.sh -r $BRANCH_NAME $REMOTE &> /dev/null
|
||||
@ -452,7 +454,7 @@ test7(){
|
||||
rm -rf $REPO_NAME
|
||||
fi
|
||||
#clone the repo in its last state
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 $REMOTE &> /dev/null
|
||||
#call git_update.sh with a tag
|
||||
cd $REPO_NAME
|
||||
../git_update.sh -r $TAG_NAME $REMOTE &> /dev/null
|
||||
@ -476,22 +478,24 @@ test8(){
|
||||
rm -rf $REPO_NAME
|
||||
fi
|
||||
#clone the repo in its last state
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
|
||||
git clone --recurse-submodules --shallow-submodules --depth 1 $REMOTE &> /dev/null
|
||||
#call git_update.sh with a tag
|
||||
cd $REPO_NAME
|
||||
../git_update.sh -r $TAG_NAME $REMOTE &> /dev/null
|
||||
../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"
|
||||
pwd
|
||||
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
|
||||
cd $REPO_NAME
|
||||
../git_update.sh -r $TAG_NAME $REMOTE &> /dev/null
|
||||
pwd
|
||||
../git_update.sh -r $TAG_NAME $REMOTE #&> /dev/null
|
||||
cd ..
|
||||
#put back the remote in its initial state
|
||||
undo_changing_tag
|
||||
#undo_changing_tag
|
||||
|
||||
#checks
|
||||
echo "second position of the tag"
|
||||
@ -522,7 +526,6 @@ while getopts ":hn:a" option; do
|
||||
done
|
||||
|
||||
if [ "$ALL_TESTS" = "true" ]; then
|
||||
make_temporary_clone
|
||||
test0
|
||||
test1
|
||||
test2
|
||||
@ -532,12 +535,8 @@ if [ "$ALL_TESTS" = "true" ]; then
|
||||
test6
|
||||
test7
|
||||
test8
|
||||
rm -rf $TMP_CLONE_DIR
|
||||
elif [ -n "$TEST_NUM" ]; then
|
||||
#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
|
||||
make_temporary_clone
|
||||
fi
|
||||
case $TEST_NUM in
|
||||
0)
|
||||
test0;;
|
||||
@ -561,9 +560,6 @@ elif [ -n "$TEST_NUM" ]; then
|
||||
echo "Error: Invalid test number"
|
||||
exit;;
|
||||
esac
|
||||
if [[ "$TEST_NUM" = 4 || "$TEST_NUM" = 5 || "$TEST_NUM" = 8 ]]; then
|
||||
rm -rf $TMP_CLONE_DIR
|
||||
fi
|
||||
else
|
||||
Help
|
||||
fi
|
Loading…
Reference in New Issue
Block a user