avec https et plus de driglibash

This commit is contained in:
eleonore12345 2024-07-17 11:54:29 +02:00
parent 691a715297
commit f16c64204e
3 changed files with 118 additions and 152 deletions

View File

@ -47,7 +47,7 @@ if [ ! -d $REPO_PATH ]; then
fi
cd $REPO_PATH
if [ ! -d $REPO_NAME ]; then
echo "remote/performance testing va devoir être créé"
echo "remote/performance testing will be created"
mkdir $REPO_NAME
cd $REPO_NAME
git init

View File

@ -1,64 +1,38 @@
#!/bin/bash
# Clone un dépôt git au bon endroit
# Stocker un minimum de données (et donc nettoyer)
# Télécharger un minimum de données
# En cas de conflit donner raison au remote (on écrase les versions locales)
#bien que le minimum
#bon tag, bonne branche
#historique bien viré
#si le tag change, c'est bon
declare -A usage
declare -A varia
summary="$0 [options] <repo>"
usage[r]="Reference of wanted commit"
varia[r]=ref
ref=main
usage[d]="Destination of clone"
varia[d]=dst
dst='.'
usage[i]="privkey used to ssh pull"
varia[i]=privkey
privkey=''
usage[N]="Clone to a Non-empty target. Existing files will be overwritten"
varia[N]=nonempty_target
nonempty_target=false
usage[K]="Remote host key file (known_hosts) for ssh connections"
varia[K]=hostkeyfile
hostkeyfile=''
usage[H]="Use real home dir"
varia[H]=use_home
use_home=false
usage[a]="use git clean with the aggressive option"
varia[a]=be_aggressive
be_aggressive=false
. driglibash-args
while getopts ":hr:d:NHa" option; do
case $option in
h) # display Help
Help
exit;;
r) # branch or tag wanted
ref="$OPTARG";;
d) # destination of clone
dst="$OPTARG";;
N) # clone to a Non-empty target. Existing files will be overwritten
nonempty_target="true";;
H) # use real home dir
use_home="false";;
a) # use git clean with the aggressive option
be_aggressive="true";;
\?) # invalid option
echo "Error: Invalid option here"
exit;;
esac
done
shift $((OPTIND-1))
# Some SSH options
ssh_opt='ssh'
if [ -n "$privkey" ] ; then
ssh_opt="$ssh_opt -i $privkey"
fi
if [ -n "$hostkeyfile" ] ; then
ssh_opt="$ssh_opt -o 'UserKnownHostsFile $hostkeyfile'"
fi
repo="$1"
if [ -z "$repo" ] ; then
die "$0: Empty repo given\n$summary"
exit "$0: Empty repo given\n$summary"
fi
if [ ! $use_home ] ; then
@ -67,20 +41,20 @@ if [ ! $use_home ] ; then
set +a
fi
run mkdir -p "$dst"
run cd "$dst"
mkdir -p "$dst"
cd "$dst"
if [ -d .git ] ; then
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
git submodule update --init --recursive --force --depth=1 --remote
git fetch --tags --depth=1 --prune --prune-tags --force origin $ref
git reset --hard FETCH_HEAD
git reflog expire --expire=now --all
if "$be_aggressive" ; then
git gc --prune=now --aggressive &> /dev/null
git gc --prune=now --aggressive
else
git gc --prune=now &> /dev/null
git gc --prune=now
fi
# Preserve existing files in some cases
if ! "$nonempty_target" ; then #we keep uncommitted files when in -N mode
@ -94,12 +68,12 @@ else
if "$nonempty_target" ; then
clone_dst="$(mktemp -d)"
fi
run git clone -b "$ref" --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="$ssh_opt" "$repo" "$clone_dst"
git clone -b "$ref" --recurse-submodules --shallow-submodules --depth 1 "$repo" "$clone_dst"
# To override an existing dir, we then move everything to that dir
if "$nonempty_target" ; then
run mv "$clone_dst/"{*,.*} .
run rmdir "$clone_dst"
mv "$clone_dst/"{*,.*} .
rmdir "$clone_dst"
fi
fi

View File

@ -1,10 +1,10 @@
#! /bin/bash
#importer driglibash
. driglibash-base
echo "<execution of test_git_update.sh>"
#Variables definitions
REPO_NAME="performance_testing"
REMOTE="ssh://git@git.jean-cloud.net:22529/eleonore/performance_testing.git"
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")
@ -22,12 +22,6 @@ TMP_CLONE_DIR="tmp_local_clone"
TMP_EXISTING_DIR="tmp_existing_dir"
TMP_EXISTING_FILE="tmp_existing_file"
if [ "$WITH_SUBMODULE" = "true" ]; then
bash creation_repo.sh -s &> /dev/null
else
bash creation_repo.sh &> /dev/null
fi
Help()
{
echo "
@ -53,6 +47,10 @@ DESCRIPTION
"
}
#output function
section(){
echo "------------------------------ $1 ------------------------------"
}
#check functions
cloning_check(){
local input=("$@")
@ -108,7 +106,7 @@ tag_check(){
branch_check(){
local repo_name=$1
run cd $repo_name
cd $repo_name
git branch > res
if [ $(grep $BRANCH_NAME res | wc -l) = 1 ];then
echo "The branch instruction has been respected"
@ -121,23 +119,23 @@ branch_check(){
}
existing_check(){
run cd $TMP_EXISTING_DIR
cd $TMP_EXISTING_DIR
if [ -f $TMP_EXISTING_FILE ]; then
echo "The preexisting non-conflicting file is still here."
existing_result=0
run cd ..
cd ..
conflict_check $TMP_EXISTING_DIR
existing_result=conflict_result
else
echo "The preexisting non-conflicting file has been deleted."
run cd ..
cd ..
existing_result=1
fi
}
modification_check(){
local repo_name=$1
run cd $repo_name
cd $repo_name
if [ -f $FILE_TO_BE_CREATED ]; then
echo "The new file has been imported."
modification_result=0
@ -152,12 +150,12 @@ modification_check(){
else
echo "$FILE_TO_BE_DELETED has been deleted."
fi
run cd ..
cd ..
}
switching_branch_check(){
local repo_name=$1
run cd $repo_name
cd $repo_name
if [ -f $FILE_ON_BRANCH_ONLY ]; then
echo "The files of the branch $BRANCH_NAME are present."
branch_switching_result=0
@ -177,7 +175,7 @@ switching_branch_check(){
switching_tag_check(){
local repo_name=$1
run cd $repo_name
cd $repo_name
if [ -f $FILE_ON_TAG_ONLY ]; then
echo "The files of the tag $TAG_NAME are present."
tag_switching_result=0
@ -192,7 +190,7 @@ switching_tag_check(){
echo "The files of the tag $TAG_NAME are absent."
tag_switching_result=1
fi
run cd ..
cd ..
}
conflict_check(){
@ -209,10 +207,10 @@ conflict_check(){
#intermediate functions
make_temporary_existing_dir(){
run mkdir $TMP_EXISTING_DIR
run cd $TMP_EXISTING_DIR
run touch $TMP_EXISTING_FILE
run touch $FILE_TO_BE_MODIFIED
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 ..
}
@ -220,57 +218,57 @@ make_temporary_existing_dir(){
make_temporary_clone(){
mkdir $TMP_CLONE_DIR
cd $TMP_CLONE_DIR
run git clone --recurse-submodules --shallow-submodules --depth 1 --no-single-branch --config core.sshCommand="ssh" $REMOTE . &> /dev/null
git clone --recurse-submodules --shallow-submodules --depth 1 --no-single-branch --config core.sshCommand="ssh" $REMOTE . &> /dev/null
cd ..
}
modification_remote(){
run cd $TMP_CLONE_DIR
run touch $FILE_TO_BE_CREATED
cd $TMP_CLONE_DIR
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 &> /dev/null
run git commit -m "$FILE_TO_BE_CREATED created and $FILE_TO_BE_DELETED deleted" &> /dev/null
run git push &> /dev/null
run cd ..
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 ..
}
undo_modification_remote(){
run cd $TMP_CLONE_DIR
run git revert --no-edit HEAD &> /dev/null
run git push &> /dev/null
cd $TMP_CLONE_DIR
git revert --no-edit HEAD &> /dev/null
git push &> /dev/null
cd ..
}
modification_local(){
run cd $REPO_NAME
run touch $FILE_TO_BE_CREATED
run echo "different text" > $FILE_TO_BE_CREATED
run git add $FILE_TO_BE_CREATED &> /dev/null
run git commit -m "$FILE_TO_BE_CREATED added" &> /dev/null
run cd ..
cd $REPO_NAME
touch $FILE_TO_BE_CREATED
echo "different text" > $FILE_TO_BE_CREATED
git add $FILE_TO_BE_CREATED &> /dev/null
git commit -m "$FILE_TO_BE_CREATED added" &> /dev/null
cd ..
}
changing_tag(){
run cd $TMP_CLONE_DIR
run git checkout $TAG_NAME &> /dev/null
run git tag -f $TAG_FLAG &> /dev/null #temporary tag flag to be able to put the tag back here after the test
run git push -f origin $TAG_FLAG &> /dev/null
run git checkout $BRANCH_NAME &> /dev/null
run git tag -f $TAG_NAME &> /dev/null #moving the tag on the branch secondary
run git push -f origin $TAG_NAME &> /dev/null #push the move to the remote
cd $TMP_CLONE_DIR
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 ..
}
undo_changing_tag(){
run cd $TMP_CLONE_DIR
run git checkout $TAG_FLAG &> /dev/null
run git tag -f $TAG_NAME &> /dev/null #move locally
run git push -f origin $TAG_NAME &> /dev/null #push the move to the remote
run git push --delete origin $TAG_FLAG &> /dev/null #delete remotely
run git tag --delete $TAG_FLAG &> /dev/null #delete locally
run cd ..
run rm -rf $TMP_CLONE_DIR
cd $TMP_CLONE_DIR
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
}
@ -281,7 +279,7 @@ test0 (){
if [ -d $REPO_NAME ]; then
rm -rf $REPO_NAME
fi
run ./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
@ -298,9 +296,9 @@ test1(){
section TEST1
#if it exists, delete the directory
if [ -d $REPO_NAME ]; then
run rm -rf $REPO_NAME
rm -rf $REPO_NAME
fi
run ./git_update.sh -d $REPO_NAME -r $TAG_NAME $REMOTE &> /dev/null
./git_update.sh -d $REPO_NAME -r $TAG_NAME $REMOTE &> /dev/null
#checks
cloning_check $REPO_NAME ${FILENAMES_TAG[@]}
history_check $REPO_NAME
@ -319,9 +317,9 @@ test2(){
section TEST2
#if it exists, delete the directory
if [ -d $REPO_NAME ]; then
run rm -rf $REPO_NAME
rm -rf $REPO_NAME
fi
run ./git_update.sh -d $REPO_NAME -r $BRANCH_NAME $REMOTE &> /dev/null
./git_update.sh -d $REPO_NAME -r $BRANCH_NAME $REMOTE &> /dev/null
#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
@ -340,19 +338,19 @@ test3(){
section TEST3
#if it exists, delete the directory
if [ -d $REPO_NAME ]; then
run rm -rf $REPO_NAME
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
run cd $TMP_EXISTING_DIR
run ../git_update.sh -N $REMOTE &> /dev/null
run cd ..
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
run rm -rf tmp_existing_dir
rm -rf tmp_existing_dir
case3=$((cloning_result+history_result+existing_result))
if [ $case3 = 0 ]; then
@ -368,16 +366,16 @@ test4(){
section TEST4
#if it exists, delete the directory
if [ -d $REPO_NAME ]; then
run rm -rf $REPO_NAME
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
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 &> /dev/null
run cd ..
cd $REPO_NAME
../git_update.sh $REMOTE &> /dev/null
cd ..
#checks
modification_check $REPO_NAME
history_check $REPO_NAME
@ -397,20 +395,20 @@ test5(){
section TEST5
#if it exists, delete the directory
if [ -d $REPO_NAME ]; then
run rm -rf $REPO_NAME
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
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 &> /dev/null
run cd ..
cd $REPO_NAME
../git_update.sh $REMOTE &> /dev/null
cd ..
#checks
run conflict_check $REPO_NAME
conflict_check $REPO_NAME
#cleaning
undo_modification_remote
@ -427,10 +425,10 @@ test6(){
section TEST6
#if it exists, delete the directory
if [ -d $REPO_NAME ]; then
run rm -rf $REPO_NAME
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
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 &> /dev/null
@ -451,14 +449,14 @@ test7(){
section TEST7
#if it exists, delete the directory
if [ -d $REPO_NAME ]; then
run rm -rf $REPO_NAME
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
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
#call git_update.sh with a tag
cd $REPO_NAME
../git_update.sh -r $TAG_NAME $REMOTE &> /dev/null
run cd ..
cd ..
#checks
switching_tag_check $REPO_NAME
history_check $REPO_NAME
@ -475,10 +473,10 @@ test8(){
section TEST8
#if it exists, delete the directory
if [ -d $REPO_NAME ]; then
run rm -rf $REPO_NAME
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
git clone --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="ssh" $REMOTE &> /dev/null
#call git_update.sh with a tag
cd $REPO_NAME
../git_update.sh -r $TAG_NAME $REMOTE &> /dev/null
@ -489,9 +487,9 @@ test8(){
#change the position of the tag from elsewhere
changing_tag
#call git_update.sh again to go to the new position of the tag
run cd $REPO_NAME
cd $REPO_NAME
../git_update.sh -r $TAG_NAME $REMOTE &> /dev/null
run cd ..
cd ..
#put back the remote in its initial state
undo_changing_tag
@ -508,11 +506,6 @@ test8(){
}
#ref changed
#updating on a branch/tag
#créer une option dans creation_repo pour le relier à un remote
#appeler creation tmp dir à l'intérieur
while getopts ":hn:a" option; do
case $option in
h) # display Help
@ -521,7 +514,7 @@ while getopts ":hn:a" option; do
n)
TEST_NUM=$OPTARG;;
a)
ALL_TESTS=true;;
ALL_TESTS="true";;
\?) # Invalid option
echo "Error: Invalid option here"
exit;;
@ -566,7 +559,7 @@ elif [ -n "$TEST_NUM" ]; then
test8;;
*)
echo "Error: Invalid test number"
die;;
exit;;
esac
if [[ "$TEST_NUM" = 4 || "$TEST_NUM" = 5 || "$TEST_NUM" = 8 ]]; then
rm -rf $TMP_CLONE_DIR
@ -574,4 +567,3 @@ elif [ -n "$TEST_NUM" ]; then
else
Help
fi