From 78fa09b803ecc817e9a39738332574b119f9bc25 Mon Sep 17 00:00:00 2001 From: Zakariae Mkassi <97558392+ZakariaeMkassi@users.noreply.github.com> Date: Sat, 25 Jun 2022 16:55:16 +0200 Subject: [PATCH 1/4] Draft: Undo changes if repo creation fails --- scripts/repositories/common/create-repo.sh | 35 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/scripts/repositories/common/create-repo.sh b/scripts/repositories/common/create-repo.sh index 8754578fa..8d65bebae 100644 --- a/scripts/repositories/common/create-repo.sh +++ b/scripts/repositories/common/create-repo.sh @@ -102,7 +102,17 @@ if [ "$directory" != "" ] then [ "$action" == "create" ] && mkdir -p "$directory" cd "$directory" - MSG_ERROR "Cding into the directory given." $? + #check if the directory exists! + ret_value3="$?" + if [ "$ret_value3" != "0" ] + then + cd .. + rm -rf "$directory" + az repos delete --id "$repo_id" --org "$organization" -p "$project" --yes + echo -e "${red}The repository made will be deleted, try again!" + fi + + MSG_ERROR "Cding into the directory given." "$ret_value3" fi directory_name=$(basename "$(pwd)") @@ -458,9 +468,28 @@ then fi elif [ "$action" = "create" ] then - MSG_ERROR "Cding into the directory given." "$?" + #cd "$directory" + #Check when starting if everything is OK? + ret_value="$?" + if [ "$ret_value" != "0" ] + then + cd .. + rm -rf "$directory" + az repos delete --id "$repo_id" --org "$organization" -p "$project" --yes + echo -e "${red}The repository made will be deleted, try again!" + fi + MSG_ERROR "Cding into the directory given." "$ret_value" clone_git_project_create - MSG_ERROR "Cloning empty repo." $? + #Check after cloning! + ret_value2="$?" + if [ "$ret_value2" != "0" ] + then + cd .. + rm -rf "$directory" + az repos delete --id "$repo_id" --org "$organization" -p "$project" --yes + echo -e "${red}You're trying to clone an empty repository, The repository made will be deleted, try again!" + fi + MSG_ERROR "Cloning empty repo." "$ret_value2" git checkout -b master cp "$absoluteFolderScriptPath/README.md" . git a dd -A From 66e6585a10e87a855959c844c51244729a9f0206 Mon Sep 17 00:00:00 2001 From: Zakariae Mkassi <97558392+ZakariaeMkassi@users.noreply.github.com> Date: Sat, 25 Jun 2022 17:00:43 +0200 Subject: [PATCH 2/4] Update create-repo.sh --- scripts/repositories/common/create-repo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/repositories/common/create-repo.sh b/scripts/repositories/common/create-repo.sh index 8d65bebae..ff34323ad 100644 --- a/scripts/repositories/common/create-repo.sh +++ b/scripts/repositories/common/create-repo.sh @@ -492,7 +492,7 @@ then MSG_ERROR "Cloning empty repo." "$ret_value2" git checkout -b master cp "$absoluteFolderScriptPath/README.md" . - git a dd -A + git add -A git commit -m "Adding README" git push -u origin --all if [ "$strategy" != "" ] From 5f7f5b2cb7769eaa0b8d5654a6a6b2f8f9b4006d Mon Sep 17 00:00:00 2001 From: Mkassi Date: Mon, 27 Jun 2022 16:52:23 +0200 Subject: [PATCH 3/4] Update create-repo.sh --- scripts/repositories/common/create-repo.sh | 44 ++++++---------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/scripts/repositories/common/create-repo.sh b/scripts/repositories/common/create-repo.sh index ff34323ad..b5f4de7ed 100644 --- a/scripts/repositories/common/create-repo.sh +++ b/scripts/repositories/common/create-repo.sh @@ -90,6 +90,13 @@ function MSG_ERROR { if [ "$2" != 0 ] then echo "" + + # do all or nothing ! In case something goes wrong while creating or importing a repository, the created repository and the local directory will be deleted. + cd .. + rm -rf "$directory" + az repos delete --id "$repo_id" --org "$organization" -p "$project" --yes + echo -e "${red}The repository made will be deleted, try again!" + echo -e "${red}A problem occured in the step: $1." echo -e "Stopping the script..." echo -e "${white}" @@ -100,19 +107,10 @@ fi [ "$directory_tmp" != "" ] && directory=$(echo "$directory_tmp" | sed 's/\\/\//g') if [ "$directory" != "" ] then - [ "$action" == "create" ] && mkdir -p "$directory" + [ "$action" == "create" ] + mkdir -p "$directory" cd "$directory" - #check if the directory exists! - ret_value3="$?" - if [ "$ret_value3" != "0" ] - then - cd .. - rm -rf "$directory" - az repos delete --id "$repo_id" --org "$organization" -p "$project" --yes - echo -e "${red}The repository made will be deleted, try again!" - fi - - MSG_ERROR "Cding into the directory given." "$ret_value3" + MSG_ERROR "Cding into the directory given." $? fi directory_name=$(basename "$(pwd)") @@ -469,27 +467,9 @@ then elif [ "$action" = "create" ] then #cd "$directory" - #Check when starting if everything is OK? - ret_value="$?" - if [ "$ret_value" != "0" ] - then - cd .. - rm -rf "$directory" - az repos delete --id "$repo_id" --org "$organization" -p "$project" --yes - echo -e "${red}The repository made will be deleted, try again!" - fi - MSG_ERROR "Cding into the directory given." "$ret_value" + MSG_ERROR "Cding into the directory given." $? clone_git_project_create - #Check after cloning! - ret_value2="$?" - if [ "$ret_value2" != "0" ] - then - cd .. - rm -rf "$directory" - az repos delete --id "$repo_id" --org "$organization" -p "$project" --yes - echo -e "${red}You're trying to clone an empty repository, The repository made will be deleted, try again!" - fi - MSG_ERROR "Cloning empty repo." "$ret_value2" + MSG_ERROR "Cloning empty repo." $? git checkout -b master cp "$absoluteFolderScriptPath/README.md" . git add -A From ba5519dc9c0aa5c444c78fcb97a1a518b6706775 Mon Sep 17 00:00:00 2001 From: Mkassi Date: Tue, 28 Jun 2022 14:11:39 +0200 Subject: [PATCH 4/4] update create-repo.sh --- scripts/repositories/common/create-repo.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/repositories/common/create-repo.sh b/scripts/repositories/common/create-repo.sh index b5f4de7ed..68d45551e 100644 --- a/scripts/repositories/common/create-repo.sh +++ b/scripts/repositories/common/create-repo.sh @@ -93,8 +93,13 @@ then # do all or nothing ! In case something goes wrong while creating or importing a repository, the created repository and the local directory will be deleted. cd .. - rm -rf "$directory" + az repos delete --id "$repo_id" --org "$organization" -p "$project" --yes + if [ "$?" == 0 ] + then + rm -rf "$directory" + fi + echo -e "${red}The repository made will be deleted, try again!" echo -e "${red}A problem occured in the step: $1."