From 7b83c67ac01e3947a4f639b34770587ed4cad1af Mon Sep 17 00:00:00 2001 From: Dennis Buchhorn Date: Fri, 12 Nov 2021 14:31:27 +0100 Subject: [PATCH] feat: add .gitignore file and hook scripts --- .githooks/post-checkout | 16 ++++++++++++++++ .githooks/pre-commit | 25 +++++++++++++++++++++++++ .gitignore | 17 +++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100755 .githooks/post-checkout create mode 100755 .githooks/pre-commit create mode 100644 .gitignore diff --git a/.githooks/post-checkout b/.githooks/post-checkout new file mode 100755 index 0000000..4675a1f --- /dev/null +++ b/.githooks/post-checkout @@ -0,0 +1,16 @@ +#!/bin/bash + +repoRoot=$(git rev-parse --show-toplevel) +listFilesToSubstitute=$(find -name *.gitsubstitute) +listStaticPathFiles=$(git grep -lr --untracked $repoRoot) +listStagedFiles=$(git diff --staged --name-only) + +staticPathSubstitution="\${REPO_ROOT}" + +for entryFileToSubstitute in $listFilesToSubstitute; do + fullPath="${repoRoot}/${entryFileToSubstitute}" + fullPathSubstitute="${repoRoot}/${entryFileToSubstitute%.gitsubstitute}" + + fileContent=$(<$fullPath) + echo "${fileContent//${staticPathSubstitution}/${repoRoot}}" > "${fullPathSubstitute}" +done diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..f9b3c9f --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,25 @@ +#!/bin/bash + +repoRoot=$(git rev-parse --show-toplevel) +listStaticPathFiles=$(git grep -lr --untracked $repoRoot) +listStagedFiles=$(git diff --staged --name-only) + +staticPathSubstitution="\${REPO_ROOT}" + +for entryStagedFile in $listStagedFiles; do + for entryStaticPathFile in $listStaticPathFiles; do + if [ $entryStagedFile == $entryStaticPathFile ]; then + fullPath="${repoRoot}/${entryStagedFile}" + entryStagedFileSubstitute="${entryStagedFile}.gitsubstitute" + fullPathSubstitute="${repoRoot}/${entryStagedFileSubstitute}" + + rm -f $fullPathSubstitute + + fileContent=$(<$fullPath) + echo "${fileContent//${repoRoot}/${staticPathSubstitution}}" > "${fullPathSubstitute}" + + git rm --cached $entryStagedFile + git add -f $entryStagedFileSubstitute + fi + done +done diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ca7304 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# ignore all workspace files +/.metadata/ +/RemoteSystemsTempFiles/ +.analytics + +# ignore all log files +**/*.log + +# ignore all files generated by pre-commit hook +**/*.gitsubstitute + +# ignore all generated platform files but platform setup script +/hw_platform/* +!/hw_platform/platform.tcl + +# ignore ide scripts +/*_system/_ide/scripts/*