#!/bin/bash
|
|
|
|
repoRoot=$(git rev-parse --show-toplevel)
|
|
listStaticPathFiles=$(git grep -lr --untracked $repoRoot)
|
|
listStagedFiles=$(git diff --staged --name-only)
|
|
|
|
staticPathSubstitution="\$\$\${GITSUBSTITUTE_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
|