Home > Software design >  PSR-4 specs and git behavior
PSR-4 specs and git behavior

Time:10-04

I'm trying to wrap my head around why a couple of things have happened to me over the past two days.

I had a folder structure like this:

includes/bootstrap/Loader.php

And my namespace for that Loader.php file would be something like this:

App\Bootstrap

composer was setup for PSR4 with source directory as includes and namespace as App.

My code was working PERFECTLY fine locally on my Mac, but when uploaded to a web server(linux) everything broke and it kept spitting that classes weren't found. My searching lead me to the fact that Linux is case sensitive, so I went back and change bootstrap folder to Bootstrap so new structure was includes/Bootstrap/Loader.php everything worked fine in production after that.

  1. That was the root cause for it working on my local mac and not on a web server right? The fact that Linux being case sensitive?

Everything currently works fine now, I prefer my namespaces to be like this:

App\Bootstrap

I don't want my name spaces to be like this:

App\bootstrap.

After pushing the code to github I realized it lowercased all folder names! Further searching lead me to the fact that I had to run it config core.ignorecase false so it can respect the case of the folder names!

Then I tried pulling down the repo in a totally different directory and terminal showed me this message:

enter image description here

  1. What does it mean by "collided"? There were no files in the folder. Also the version on git is the capitalized folder name version, why did git try to download something different?

I can see that it shows both in the terminal but in the folder it's the actual version which is on github...so I'm just wondering why it showed both versions in the terminal.

  1. Would git try to lowercase the repo for someone else on a Mac? How could I prevent these sort of things moving forward? Was it the fact that some folder names in the repo were lowercased before? I read that by default git config ignore case is set to false...why did I have to run it again for git to respect the folder name case?

CodePudding user response:

As a rule, Linux file systems are case sensitive and so if you referred to the file as App\Bootstrap, then it needs to be in that case in the file system. So yes, to your first question.

What Git means by "collided" is that your repository has two sets of paths in it: one starting with include/Bootstrap and one starting with include/bootstrap. Git is case sensitive, so it treats those paths differently. However, your Mac is not capable of distinguishing case, so when Git goes to write both sets of paths into the file system, only one of them can be successfully written.

As to the setting core.ignoreCase, it is set to reflect what your file system is actually capable of and shouldn't be changed. The problem is not Git: the problem is that your file system is simply not capable enough to handle this case. The Git FAQ explains this in some detail.

To remove the duplicates, run git rm -r --cached includes/bootstrap and then commit.

You may additionally wish to use a case-sensitive file system in the future, which is an option when formatted in APFS partition, although it is not the default on macOS. Note that some programs don't handle this gracefully and can cause problems when run on a case-sensitive file system.

  • Related