privatenumber / git-detect-case-change

🤖 Script to detect file name case changes in a Git repository

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

git-detect-case-change

Script to stage file-path case changes in a Git repository.

Support this project by ⭐️ starring and sharing it. Follow me to see what other cool projects I'm working on! ❤️

Usage

After renaming files, run the script with npx in your Git repository:

npx git-detect-case-change

If there were any case-changes, it will detect and stage them for you.

Dry run

Run with --dry to see what files would be renamed before staging them:

npx git-detect-case-change --dry

Scoping files

Pass in specific paths after -- to scope the search to:

npx git-detect-case-change -- <scope to directory path>

Why?

File-systems on macOS & Windows are case-insensitive by default, which means paths /a.txt and /A.txt cannot exist at the same time. Because of this default, Git is also case-insensitive by default, preventing it from detecting case changes in file names.

The recommended solution from this StackOverflow discussion is to rename the files individually with git mv:

git mv <old-path> <new-path>

However, this may not be practical if the case-changes were made without Git (eg. automated by another program) and there's a lot to rename.

This script automates case-change detection for Git.

How does it work?

  1. Get the case-sensitive file paths from the current Git project:

    git ls-tree --name-only -r HEAD
  2. Check each file path with fs.promises.exists to find a case-insensitive match.

  3. If the path exists with a different case, register the change with Git:

    git mv <old-path> <new-path>

About

🤖 Script to detect file name case changes in a Git repository

License:MIT License


Languages

Language:TypeScript 100.0%