From e27b1b8a403d6e762be7f45abf24cd01b5f4b10c Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Fri, 15 Mar 2024 10:11:15 +1100 Subject: [PATCH] d4 --- .drevops/docs/.utils/tests/bats/_helper.bash | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/.drevops/docs/.utils/tests/bats/_helper.bash b/.drevops/docs/.utils/tests/bats/_helper.bash index 4b8cac2b3..8756c0b1b 100644 --- a/.drevops/docs/.utils/tests/bats/_helper.bash +++ b/.drevops/docs/.utils/tests/bats/_helper.bash @@ -59,6 +59,10 @@ setup() { # Copy DrevOps at the last commit. fixture_export_codebase "${LOCAL_REPO_DIR}" "${ROOT_DIR}" >/dev/null + # Prepare global git config and ignore files required for testing cleanup scenarios. + prepare_global_gitconfig + prepare_global_gitignore + ## ## Setting debug mode. ## @@ -77,6 +81,7 @@ setup() { } teardown() { + restore_global_gitignore popd >/dev/null || cd "${ROOT_DIR}" || exit 1 } @@ -114,3 +119,46 @@ git_add_all_commit() { commit=$(git --work-tree="${dir}" --git-dir="${dir}/.git" rev-parse HEAD) echo "${commit}" } + + +prepare_global_gitconfig() { + git config --global init.defaultBranch >/dev/null || git config --global init.defaultBranch "main" +} + +prepare_global_gitignore() { + filename="${HOME}/.gitignore" + filename_backup="${filename}".bak + + if git config --global --list | grep -q core.excludesfile; then + git config --global core.excludesfile >/tmp/git_config_global_exclude + fi + + [ -f "${filename}" ] && cp "${filename}" "${filename_backup}" + + cat <"${filename}" +## +## Temporary files generated by various OSs and IDEs +## +Thumbs.db +._* +.DS_Store +.idea +.idea/* +*.sublime* +.project +.netbeans +.vscode +.vscode/* +nbproject +nbproject/* +EOT + + git config --global core.excludesfile "${filename}" +} + +restore_global_gitignore() { + filename=${HOME}/.gitignore + filename_backup="${filename}".bak + [ -f "${filename_backup}" ] && cp "${filename_backup}" "${filename}" + [ -f "/tmp/git_config_global_exclude" ] && git config --global core.excludesfile "$(cat /tmp/git_config_global_exclude)" +}