diff --git a/.githooks/post-checkout b/.githooks/post-checkout index d61859c..52a8e1f 100755 --- a/.githooks/post-checkout +++ b/.githooks/post-checkout @@ -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