Skip to content

Commit

Permalink
d4
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Mar 14, 2024
1 parent 1c046c5 commit e27b1b8
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .drevops/docs/.utils/tests/bats/_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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.
##
Expand All @@ -77,6 +81,7 @@ setup() {
}

teardown() {
restore_global_gitignore
popd >/dev/null || cd "${ROOT_DIR}" || exit 1
}

Expand Down Expand Up @@ -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 <<EOT >"${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)"
}

0 comments on commit e27b1b8

Please sign in to comment.