I'm trying to format an old monolith of bad design and tech debt into something resembling readable for the sake of automating this and checking it in the future. I've been hammering on this for a few days now, and have read the contents of this article, and the first comment on it, many times. This gets me on the correct path, and a slightly modified version of the command even seems to work!
git filter-branch --tree-filter 'prettier --no-config --ignore-path /Users/samuraiseoul/.prettierignore --single-quote --use-tabs --print-width=90 --write "**/*.{js,php,scss,ts,md,css}" || echo “Error formatting, possibly invalid code“' -- --all
The problem with that is that while it works on a smaller test repo with about 500 commits, it would take weeks to run on the main repo of doom with 30,000+ commits and 100x the files.
As a result, I've been trying to get only the changed files per commit, and format those. The following command's outputs seem like it should be working, but after it runs on the small repo, none of the changes from the git filter-branch
seem to be saved. I'm not sure exactly what's going wrong here. It seems similar to the solution from this SO post, but it doesn't work.
git filter-branch --tree-filter 'git show $GIT_COMMIT --pretty="" --name-only --diff-filter=AM | grep -e "\.scss$" -e "\.php$" -e "\.css$" -e "\.js$" -e "\.ts$" -e "\.md$" -e "\.yml$" | tr " " "\ " | tr "\n" " " | xargs -t find 2> /dev/null | tr " " "\ " | tr "\n" " " | xargs -t prettier --no-config --single-quote --use-tabs --print-width=90 --write || echo “Error formatting, invalid syntax' -- --all
I'm not sure exactly where things are going wrong. From what I understand the command I pass into the tree filter, gets applied to every commit, then rewrites that commits history to include that command's effect. The output of it, shows that it is hitting the files, and that prettier is working on them. Unfortunately, after the command is ran, if I do a diff on the same file from the repo and an un-modified version of the repo, it shows no differences.
I think the problem is with the bash command I have written to pass into the filter-branch, but I'm not 100% sure at this point. Any help would be very appreciated and if there is more information or some other command I should try, let me know! Thanks.