From f7ab20702ccfaf45ab48117c5eb795ef929e7050 Mon Sep 17 00:00:00 2001 From: Josef Andersson Date: Sun, 21 Aug 2022 13:19:05 +0200 Subject: [PATCH] Add env DEFAULT_WORKSPACE path to git safe.directory (#1770) Signed-off-by: Josef Andersson Signed-off-by: Josef Andersson --- CHANGELOG.md | 1 + entrypoint.sh | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b149988ec85..17af164f237 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `oxsecurity/megalinter:beta` docker image +- Set DEFAULT_WORKSPACE as git safe directory per default [#1766](https://github.com/oxsecurity/megalinter/issues/1766) - Update pre-commit hooks from v5 to v6 ([#1755](https://github.com/oxsecurity/megalinter/issues/1755)). - Fix version in URL in logs produced by reporters - Improve documentation for TAP_REPORTER diff --git a/entrypoint.sh b/entrypoint.sh index f69a8a4f2a9..5e55bdf5d08 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,6 +10,14 @@ if [[ ${LOG_LEVEL} == "DEBUG" ]]; then fi # Manage newest git versions (related to CVE https://github.blog/2022-04-12-git-security-vulnerability-announced/) +# +if [[ "${WORKSPACE_AS_SAFE_DIR}" != 'false' && "${DEFAULT_WORKSPACE}" && -d "${DEFAULT_WORKSPACE}" ]] ; then + echo "Setting git safe.directory DEFAULT_WORKSPACE: ${DEFAULT_WORKSPACE} ..." + git config --global --add safe.directory "${DEFAULT_WORKSPACE}" +else + echo "Skipped setting git safe.directory DEFAULT_WORKSPACE: ${DEFAULT_WORKSPACE} ..." +fi + if [ -z ${GITHUB_WORKSPACE+x} ]; then echo "Setting git safe.directory default: /github/workspace ..." git config --global --add safe.directory /github/workspace @@ -17,6 +25,7 @@ else echo "Setting git safe.directory GITHUB_WORKSPACE: $GITHUB_WORKSPACE ..." git config --global --add safe.directory "$GITHUB_WORKSPACE" fi + echo "Setting git safe.directory to /tmp/lint ..." git config --global --add safe.directory /tmp/lint