Filesystem case-sensitivity and git

I’m in the process of moving from OS X to Ubuntu (via WSL2) for all of my development work, and ran into an odd behavior with a zsh function I use all the time to diff my current work against the master branch, that it turns out, is caused by the case-sensitivity of the Linux filesystem (unless I’ve misunderstood things).

The two functions list all files touched in each commit in a PR, or all files changed in a branch and all commits that affect them:

$ this-branch-files-by-commit

SHA Update contnroller
app/controllers/my_controller.rb
spec/controllers/my_controllers_spec.rb

SHA Update model
app/models/my_model.rb
spec/models/my_model.rb

or

$ this-branch-commits-by-file

app/controllers/my_controller.rb
1: SHA Update controller

spec/controllers/my_controllers_spec.rb
1: SHA Update controller

app/models/my_model.rb
2: SHA Update model

spec/models/my_model.rb
2: SHA Update model

These two functions rely on running git diff master..head, which works fine on OS X, but on Ubuntu results in…

flying-grizzly production % git diff master..head

fatal: ambiguous argument 'master..head': unknown revision or path not in the
working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

It turns out that this is because OS X is willing to interpret .git/HEAD as .git/head if there is no conflicting file already in that place.

Ubuntu (and Linux, to my new understanding), not so much.

The solution was to update these two functions to use git diff master..HEAD instead of the lazy lowercase option.

Thanks to this answer on SO for helping me figure why this was the case.