drizin
drizin

Reputation: 1975

Change case of folder using libgit2sharp

How can I rename a directory in libgit2sharp (under Windows, which is case insensitive) when it's just a case change?

This code works fine for moving files across different directories:

    File.Move(@"C:\repo\folder1\file.txt", @"C:\repo\folder2\file.txt");
    repo.Index.Remove("folder1/file.txt");
    repo.Index.Add("folder2/file.txt");
    repo.Index.Write();
    var commitResult = repo.Commit(logMessage, author, author);

However, if I'm just renaming case of a folder, it doesn't work:

    Directory.Move(@"C:\repo\folder1\", @"C:\repo\Folder1\");
    repo.Index.Remove("folder1/file.txt");
    repo.Index.Add("Folder1/file.txt");
    repo.Index.Write();
    var commitResult = repo.Commit(logMessage, author, author); // nothing gets written - I get LibGit2Sharp.EmptyCommitException

I also tried doing 2 renames (and commiting once at the end) like suggested by this answer

Am I doing something wrong or this is a git limitation? Is there any workaround besides doing an intermediate commit?

PS: I tried changing the repo to ignorecase=false (the default in Windows is true), but it didn't work either.

Upvotes: 1

Views: 161

Answers (1)

drizin
drizin

Reputation: 1975

Turns out that it was enough to set ignorecase=false in git.config - but I had to use that since the beggining (before the first commit).

I only tried changing that setting by the moment that I was really removing the old case and adding the new one, looks like that wasn't enough - git doesn't detect the change.

Upvotes: 1

Related Questions