Rather than installing Black on my local machine, I'm experimenting with running Black (installed from requirements.txt) from a Docker container. I'm looking to add a Makefile command to format modified files. This is what I've come up with so far, which is run with make format
:
# formats any files which differ from the point at which the current branch (2) forked from master (1)
# ____1_____________ master
# \__________ dev
# \_________2 current_branch
diff_files := $(shell git diff $(git merge-base --fork-point master) --name-only -- "*.py")
format:
docker-compose run --rm api black $(diff_files)
This finds the point at which the current branch forked from master
https://git-scm.com/docs/git-merge-base#_operation_modes:
git merge-base --fork-point master
And this returns the files names returned from the diff with the .py extension (.py filter might be overkill?)
https://git-scm.com/docs/git-diff#_description
--name-only -- "*.py"
Would love to hear some feedback, or any examples of similar setups.