You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

25 lines
900 B

#!/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