From cfbc6c30a765247c71254a2ee34fd8c874ab94e6 Mon Sep 17 00:00:00 2001 From: Tim Ward Date: Tue, 25 Oct 2022 12:29:05 +0200 Subject: [PATCH 1/3] Allow users to set working directory In some cases validation is needed for a single path within the repository. It should be possible to select that path using a variable such as `REPOSITORY_PATH` --- entrypoint.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 5a33899..0fec4f0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -145,6 +145,11 @@ getChangedFiles() { echo "eclint version: $(eclint --version)" configureGit +if [ -n "${REPOSITORY_PATH+set}" ]; then + echo "Changing directory to $REPOSITORY_PATH" + cd "$REPOSITORY_PATH" +fi + echo "Looking for .editorconfig file in current directory or parents..." findInCwdOrParent .editorconfig From 37d7e90a88a377178a6b0be52bbe1bb89fe405dd Mon Sep 17 00:00:00 2001 From: Tim Ward Date: Tue, 25 Oct 2022 17:02:53 +0200 Subject: [PATCH 2/3] Fix possible file ownership problems The container validating the editor config may have a different user - this can be fixed up by setting `ADD_SAFE_DIRECTORY` to `true` --- entrypoint.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 0fec4f0..b1bde7d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -28,6 +28,11 @@ findInCwdOrParent() { configureGit() { # This should be the default but it's important that it's set correctly git config --global core.quotePath true + + if [[ "${ADD_SAFE_DIRECTORY:-false}" = [Tt]rue ]]; then + # This prevents errors due to different file ownership from outside the container + git config --global --add safe.directory $PWD + fi } getEventByPath() { From 768a1461d2229eb28f1af69d60abb64ca79d4b2e Mon Sep 17 00:00:00 2001 From: Tim Ward Date: Thu, 27 Oct 2022 15:04:57 +0200 Subject: [PATCH 3/3] Find files relative to REPOSITORY_PATH Update the file search to work relative to the working directory, not the root of the repository Signed-off-by: Tim Ward --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index b1bde7d..060d4ab 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -126,7 +126,7 @@ getChangedFiles() { else echo "File \`$line\` was moved or deleted." fi - done < <(git diff --name-only "${HEAD_COMMIT}..${BASE_COMMIT}") + done < <(git diff --name-only --relative "${HEAD_COMMIT}..${BASE_COMMIT}" -- .) elif $have_last && $have_commits ; then echo "Missing starting commit, new repo?" # We know that core.quotePath is true