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

  1. #!/bin/bash
  2. repoRoot=$(git rev-parse --show-toplevel)
  3. listStaticPathFiles=$(git grep -lr --untracked $repoRoot)
  4. listStagedFiles=$(git diff --staged --name-only)
  5. staticPathSubstitution="\${REPO_ROOT}"
  6. for entryStagedFile in $listStagedFiles; do
  7. for entryStaticPathFile in $listStaticPathFiles; do
  8. if [ $entryStagedFile == $entryStaticPathFile ]; then
  9. fullPath="${repoRoot}/${entryStagedFile}"
  10. entryStagedFileSubstitute="${entryStagedFile}.gitsubstitute"
  11. fullPathSubstitute="${repoRoot}/${entryStagedFileSubstitute}"
  12. rm -f $fullPathSubstitute
  13. fileContent=$(<$fullPath)
  14. echo "${fileContent//${repoRoot}/${staticPathSubstitution}}" > "${fullPathSubstitute}"
  15. git rm --cached $entryStagedFile
  16. git add -f $entryStagedFileSubstitute
  17. fi
  18. done
  19. done