From 49f361670de46ef0cb5ee30aeb1f9d188a0123fe Mon Sep 17 00:00:00 2001 From: eleonore12345 Date: Mon, 15 Jul 2024 14:32:55 +0200 Subject: [PATCH] test 4 update ff fonctionne --- git_update.sh | 12 +++---- test_git_update.sh | 89 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 88 insertions(+), 13 deletions(-) diff --git a/git_update.sh b/git_update.sh index 74589dc..2c5fc97 100755 --- a/git_update.sh +++ b/git_update.sh @@ -73,14 +73,14 @@ run cd "$dst" if [ -d .git ] ; then - run git submodule update --init --recursive --force --depth=1 --remote - run git fetch --tags --depth=1 --prune --prune-tags origin $ref - run git reset --hard FETCH_HEAD - git reflog expire --expire=now --all + 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 + git reflog expire --expire=now --all &> /dev/null if "$be_aggressive" ; then - git gc --prune=now --aggressive + git gc --prune=now --aggressive &> /dev/null else - git gc --prune=now + 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 diff --git a/test_git_update.sh b/test_git_update.sh index 6469bfd..7a1a961 100755 --- a/test_git_update.sh +++ b/test_git_update.sh @@ -11,6 +11,7 @@ FILENAMES_TAG=("sample0") FILENAMES_BRANCH=("sample0" "sample1") #we do not check for all files, especially not those specific to the branch. TAG_NAME=start BRANCH_NAME=secondary +TEMP_CLONE_DIR="temp_local_clone" if [ "$WITH_SUBMODULE" = "true" ]; then bash creation_repo.sh -s &> /dev/null @@ -84,8 +85,8 @@ tag_check(){ echo "The tag instruction has been respected" tag_result=0 else - tag_result=1 echo "The tag instruction has not been respected" + tag_result=1 fi cd .. } @@ -104,6 +105,50 @@ branch_check(){ 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(){ + 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 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_check(){ + local filenames=("$@") + if [ -f "new_file" ]; 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 "${filenames[0]}" ]; then + echo "${filenames[0]} has not been deleted." + modification_result="1" + else + echo "${filenames[0]} has been deleted." + fi +} + test0 (){ #CASE 0: git cloned in an empty directory section TEST0 @@ -183,7 +228,6 @@ test3(){ #checks cloning_check "tmp_dir" ${FILENAMES[@]} history_check $"tmp_dir" - #existing check cd tmp_dir if [ -f tmp_file ]; then @@ -199,7 +243,8 @@ test3(){ echo "The preexisting non-conflicting file has been deleted." existing_result=1 fi - cd .. + 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" @@ -209,12 +254,35 @@ test3(){ } -TEST4(){ -#CASE 4: git updated ff +test4(){ +#CASE 4: git updated fast-forward 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 ${FILENAMES[@]} + #make git_update.sh update the repository + run cd $REPO_NAME + run ../git_update.sh $REMOTE + #checks + run modification_check ${FILENAMES[@]} + #cleaning + run cd .. + undo_modification_remote + case4=$modification_result + if [ "$case4" = "0" ]; then + echo "case 4, fast-forward update: OK" + else + echo "case 4, fast-forward update: FAIL" + fi } +#not ff +#ref changed @@ -248,6 +316,9 @@ if [ "$ALL_TESTS" = "true" ]; then test9 elif [ -n "$TEST_NUM" ]; then + if [ "$TEST_NUM" = 4 ];then + make_temporary_clone + fi case $TEST_NUM in 0) test0;; @@ -273,6 +344,10 @@ elif [ -n "$TEST_NUM" ]; then echo "Error: Invalid test number" die;; esac + if [ "$TEST_NUM" = 4 ];then + rm -rf $TEMP_CLONE_DIR + fi else Help -fi \ No newline at end of file +fi +