Search code examples
windowsgitcase-sensitivecase-insensitive

Folder capitalization not changing on branch switch


I'm working on a python project and want to rename a (package) folder to small letters, let's say from Myackage to mypackage. As git is case-sensitive and Windows is not, I followed the solutions taken from here and espacially here.

My procedure was as follows:

git mv Mypackage tmp
git mv tmp mypackage
git commit -m "Change capitalization of package name"

This changes the folder Myackage to mypackage with success (for both, git and Windows). But if I switch to another branch, I expect the folder to change back to Mypackage (with capital letter!), as it was before. Background is, that all the imports of the package are also case-sensitve in python and i need this renamng acompanied with adaptions of the imports.

I've tried both, core.ignorecase set to true and false, but no matter what I try, if I checkout an older branch, the folder remains in form of small letters (mypackage) and I run into issues within python.

UPDATE: I've set up a small example with only one Folder and one file and could succesfully change the capitalization of the folder. It also shows the desired behaviour, that upon branch switch the capitalization of the folder in Windows changes, yet still this won't work for my python project.

Could it be, that, e.g., submodules, play a role here?

UPDATE 2: I've checked the case sensitivity attribute for both cases via:

fsutil.exe file queryCaseSensitiveInfo .

Both folders claim, that case-sensitivity is deactivated. Still for one project folder name capitalization changes, but for the other folder not.


Solution

  • I found a way to reproduce your behavior :

    if my CaSeD folder contains some extra files (untracked files for example), git will not change the case of my folder name when I jump between commits.

    Is this the case in your setup ?


    If this is your issue : you could go with a post-checkout hook, which forcibly renames the folders according to what is stored in HEAD after a checkout.

    One way to get the full list of paths to directories from commit HEAD is :

    git ls-tree --name-only -d -r HEAD
    

    If you match this list with a similar list extracted from your local file system (ls -r ? find . -type d ? some python function from os.* ?), you can spot what folders need to be recapitalized.