git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Bug: Changing folder case with `git mv` crashes on case-insensitive file system

From
MAMark Amery <markrobertamery@gmail.com>
Date
May 3, 2021, 17:25 UTC
Message-ID
<CAD8jeghpOQoibk0xM0QgLsOwLNw9GdM=4rhYuzV-NSkw8LinMQ@mail.gmail.com>

Attempting to change the case of a folder's name using a command like `git mv foo FOO` crashes on case-insensitive file systems, like the default APFS used on Apple Macs.

Here are simple steps to repro this:
    $ mkdir testrepo && cd testrepo && git init
    Initialized empty Git repository in /Users/markamery/testrepo/.git/
    $ mkdir foo && touch foo/bar && git add foo && git commit -m bla
    [master (root-commit) a7e9f5f] bla
    1 file changed, 0 insertions(+), 0 deletions(-)
    create mode 100644 foo/bar
    $ git mv foo FOO
    fatal: renaming 'foo' failed: Invalid argument
    $ echo $?
    128
    $ git status
    On branch master
    nothing to commit, working tree clean

If I create a case-sensitive APFS volume using Disk Utility and try the commands above on that volume, `git mv foo FOO` works correctly: it emits no output, exits with a 0 status code, and stages a change renaming `foo/bar` to `FOO/bar`. However, on my main case-insensitive volume, `git mv` behaves as shown above: it exits with code 128, prints an "Invalid argument" error message, and does not stage any changes.

The command still fails in the same way if you use `git mv --force` instead of just `git mv`.

Note that previously, `git mv` could not change the case of *file* names on case-insensitive file systems, until that was fixed in commit https://github.com/git/git/commit/baa37bff9a845471754d3f47957d58a6ccc30058. I'm guessing there's a different code path that needs fixing for changing the case of *folders*.

As far as I can tell, this error has never been reported to the Git mailing list, but it seems to be encountered frequently; https://stackoverflow.com/questions/3011625/git-mv-and-only-change-case-of-directory mentions this bug and has 86000 views.

In case it's relevant, here's my system info as output by `git bugreport`:
    [System Info]
    git version:
    git version 2.31.1
    cpu: x86_64
    no commit associated with this build
    sizeof-long: 8
    sizeof-size_t: 8
    shell-path: /bin/sh
    uname: Darwin 18.7.0 Darwin Kernel Version 18.7.0: Mon Apr 27
20:09:39 PDT 2020; root:xnu-4903.278.35~1/RELEASE_X86_64 x86_64
    compiler info: clang: 11.0.0 (clang-1100.0.33.17)
    libc info: no libc information available
    $SHELL (typically, interactive shell): /bin/bash
Next: brian m. carlson
Message 1 of 14 in “Bug: Changing folder case with `git mv` crashes on case-insensitive file system”
  1. Mark AmeryMay 3, 2021
  2. brian m. carlsonMay 3, 2021
  3. Junio C HamanoMay 4, 2021
  4. brian m. carlsonMay 4, 2021
  5. Johannes SchindelinMay 5, 2021
  6. Junio C HamanoMay 6, 2021
  7. Torsten BögershausenMay 4, 2021
  8. Junio C HamanoMay 5, 2021
  9. brian m. carlsonMay 5, 2021
  10. Torsten BögershausenMay 6, 2021
  11. Mark AmeryMay 6, 2021
  12. Bagas SanjayaMay 6, 2021
  13. Torsten BögershausenMay 6, 2021
  14. Junio C HamanoMay 6, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.