Browse Source

feat: post-checkout hook checks if branch or file checkout

master
Dennis Buchhorn 2 years ago
parent
commit
a43a0064ff
1 changed files with 26 additions and 9 deletions
  1. +26
    -9
      .githooks/post-checkout

+ 26
- 9
.githooks/post-checkout View File

@ -1,14 +1,31 @@
#!/bin/bash
repoRoot=$(git rev-parse --show-toplevel)
listFilesToSubstitute=$(find -name *.gitsubstitute)
staticPathSubstitution="\$\$\${GITSUBSTITUTE_REPO_ROOT}"
oneOrMoreSubstitutedFileExists="false"
for entryFileToSubstitute in $listFilesToSubstitute; do
fullPath="${repoRoot}/${entryFileToSubstitute}"
fullPathSubstitute="${repoRoot}/${entryFileToSubstitute%.gitsubstitute}"
# if checkout is a branch checkout
if [ $3 == "1" ]; then
echo "Looking for files to substitute..."
repoRoot=$(git rev-parse --show-toplevel)
listFilesToSubstitute=$(find -name *.gitsubstitute)
for fileToSubstitute in $listFilesToSubstitute; do
if ! [ -f ${fileToSubstitute%.gitsubstitute} ]; then
echo "create file: ${fileToSubstitute%.gitsubstitute}"
fullPath="${repoRoot}/${fileToSubstitute}"
fullPathSubstitute="${repoRoot}/${fileToSubstitute%.gitsubstitute}"
fileContent=$(<$fullPath)
echo "${fileContent//${staticPathSubstitution}/${repoRoot}}" > "${fullPathSubstitute}"
else
oneOrMoreSubstitutedFileExists="true"
fi
done
fileContent=$(<$fullPath)
echo "${fileContent//${staticPathSubstitution}/${repoRoot}}" > "${fullPathSubstitute}"
done
if [ $oneOrMoreSubstitutedFileExists == "true" ]; then
echo "One or more substituted file exists."
echo "If you want to clean the repo and recreate all projects run './clean_and_recreate_all'"
fi
fi

Loading…
Cancel
Save