commit 4ec099942c6c67b40d6cbe703e95d80f42b713a3 Author: eleonore12345 Date: Mon Jun 24 18:09:48 2024 +0200 initialisation diff --git a/.~lock.notes.odt# b/.~lock.notes.odt# new file mode 100644 index 0000000..9f5f00a --- /dev/null +++ b/.~lock.notes.odt# @@ -0,0 +1 @@ +,eleonore1,eleonore,24.06.2024 18:03,file:///home/eleonore1/.config/libreoffice/4; \ No newline at end of file diff --git a/git_update.sh b/git_update.sh new file mode 100755 index 0000000..8b6da8a --- /dev/null +++ b/git_update.sh @@ -0,0 +1,105 @@ +#!/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) + +declare -A usage +declare -A varia + +summary="$0 [options] " + +usage[b]="Branch of git repo" +varia[b]=branch +branch=main + +usage[t]="Tag of git repo" +varia[t]=tag +tag= + +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 + + +. driglibash-args + + +# 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" +fi + +if [ ! $use_home ] ; then + set -a + export HOME=/dev/null + set +a +fi + +run mkdir -p "$dst" +run cd "$dst" + + +if [ -d .git ] ; then + + # Compute git branch and tag + tagref= + if [ -n "$tag" ] ; then + tagref="tags/$tag" + fi + + run git fetch origin "$branch" --tags + run git checkout --force $tagref -B "$branch" + run git reset --hard # TODO we can keep some files? + # Preserve existing files in some cases + if ! "$nonempty_target" ; then + git clean -qffdx + fi + run git submodule update --init --recursive --force --recommend-shallow + run git submodule foreach git fetch + run git submodule foreach git checkout --force HEAD + run git submodule foreach git reset --hard + run git submodule foreach git clean -fdx +else + clone_dst='.' + + # To override an existing dir, we need to clone elsewhere first + if "$nonempty_target" ; then + clone_dst="$(mktemp -d)" + fi + + run git clone -b "$branch" --single-branch --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="$ssh_opt" "$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" + fi +fi + diff --git a/notes.odt b/notes.odt new file mode 100644 index 0000000..da2bfab Binary files /dev/null and b/notes.odt differ diff --git a/test_git_update.sh b/test_git_update.sh new file mode 100755 index 0000000..3bf741a --- /dev/null +++ b/test_git_update.sh @@ -0,0 +1,100 @@ +#! /bin/bash +# création d'un repo git en ligne leRepo avec dedans un fichier texte et un fichier main.c +echo "" +foldername="leRepo" #folder de test +filenames=("texte" "main.c") #quand main.c n'est pas compilé +lienClonage=ssh://git@git.jean-cloud.net:22529/eleonore/pourTesterGitUpdate.git + +#CAS 0 : git cloné dans un dossier vide sans tag +#if it exists, delete the folder +if [ -d $foldername ]; then + rm -rf $foldername + echo "le dossier de test préexistant $foldername a été supprimé" +fi +cas0="true" +mkdir $foldername +cd $foldername +../git_update.sh $lienClonage +cd .. + +#vérification que leRepo a été cloné et qu'il contient bien les fichiers +if [ -d "./$foldername" ]; then + echo "le dossier $foldername a été créé" + for file in ${filenames[@]} + do + if [ -f "./$foldername/$file" ]; then + echo "le fichier $file a bien été importé" + else + echo "le fichier $file n'a pas pu être importé" + cas0="false" + echo $cas0 + exit #or die ? + fi + done +else + echo "le dossier $foldername n'a pas pu être créé" + cas0="false" + echo $cas0 + exit #ou die ? +fi + +#vérification que l'historique n'a pas été importé +cd $foldername +if [ $(git log | grep "commit" | wc -l) -gt 1 ]; then + echo "Plus d'un commit a été sauvegardé" + cas0="false" +elif [ $(git log | grep "commit" | wc -l) = 1 ]; then + echo "Seul le dernier commit a été sauvegardé" +else + echo "Erreur dans le clonage, git log non cohérent" + exit +fi + +if [ "$cas0" = "true" ]; then + echo "Cas de test 0, dans un dossier vide préexistant, sans historique, sans tag : OK" +else + echo "Cas de test 0, dans un dossier vide préexistant, sans historique, sans tag : ECHEC" +fi +cd .. +#CAS 1 : git cloné dans un dossier vide avec tag +#if it exists, delete the folder +nomBranche=main +nomTag=debut +if [ -d $foldername ]; then + rm -rf $foldername + echo "le dossier de test préexistant $foldername a été supprimé" +fi + +cas1="true" +mkdir $foldername +cd $foldername +echo "$(pwd)" +../git_update.sh -b $nomBranche -t $nomTag $lienClonage #avec l'option t qui redirige vers un tag +cd .. + + +if [ -d "./$foldername" ]; then + echo "le dossier $filename a bien été créé" + for file in ${filenames[@]} + do + if [ -f "./$foldername/$file" ]; then + echo "le fichier $file a bien été importé" + else + echo "le fichier $file n'a pas pu être importé" + cas1=false + fi + done +else + echo "le dossier $filename n'a pas pu être cloné" + cas1=false +fi + +if [ $(git tag | wc -l) -lt 1 ]; then + echo "le tag $tagname n'a pas été importé" +elif [ $(cat texte | grep "0.1" | wc -l) -lt 1]; then + echo "le tag $tagname a été importé mais le git checkout n'a pas fonctionné" +else + echo "le tag a été importé et le git checkout $tagname a fonctionné" +fi + + diff --git a/tests-manuels/pourTesterGitUpdate b/tests-manuels/pourTesterGitUpdate new file mode 160000 index 0000000..0767da6 --- /dev/null +++ b/tests-manuels/pourTesterGitUpdate @@ -0,0 +1 @@ +Subproject commit 0767da6236479ef7a3e43ec6d5d74f0663901205