ModernRonin / ProjectRenamer

Conveniently rename your csproj files
Other
155 stars 14 forks source link

Rename from 'X' to 'Y' failed. #37

Open canro91 opened 2 years ago

canro91 commented 2 years ago

First, thanks for this awesome tool. It saved a lot of time.

I'm trying to rename a project from something like src/SomeThing.Core to src/Something.Core. This is the command I'm running in a Powershell run as admin:

> renameproject.exe SomeThing.Core Something.Core --no-commit --no-paket --no-review

But, after running the above command, the renaming fails with the next output:

Analyzing references in your projects - depending on the number of projects this can take a bit...
Project `SomeThing.Core\SomeThing.Core.csproj` removed from the solution.
Rename from 'SomeThing.Core' to 'Something.Core/SomeThing.Core' failed. Should I try again? (y/n) n
fatal: renaming 'SomeThing.Core' failed: Permission denied
call 'git mv "C:\[redacted]\SomeThing\SomeThing.Core" "C:\[redacted]\SomeThing\Something.Core"' failed - aborting
...running git reset to undo any changes...
HEAD is now at f9dd0d3 Initial commit

After googling a bit, I found this SO answer where a intermediate folder is used to move the src folder to destination. Like:

git mv src src-temp
git mv src-temp dest

Changing the gitMove method to follow that workaround seems to work. This is the gitMove method after the change:

void gitMove()
{
    _filesystem.EnsureDirectoryExists(Path.GetDirectoryName(newDir));

    var tmp = $"{oldDir}-Temp";
    _git.Move(oldDir, tmp);
    _git.Move(tmp, newDir);
    var oldPath = Path.GetFileName(oldProjectPath).ToAbsolutePath(newDir);
    if (oldPath != newProjectPath) _git.Move(oldPath, newProjectPath);
}

I'm running Git 2.29.2.windows.2

ModernRonin commented 2 years ago

Hey there, thanks for this! Sorry it took a while to answer, I was (and still am) sick.

I'll look into this more deeply once I'm well again.

304NotModified commented 1 year ago

any news on this?

ModernRonin commented 1 year ago

nope, sorry, didn't get to it yet.

would be grateful to take a PR, though :-)

Jabbado commented 1 year ago

But, after running the above command, the renaming fails with the next output:

Analyzing references in your projects - depending on the number of projects this can take a bit...
Project `SomeThing.Core\SomeThing.Core.csproj` removed from the solution.
Rename from 'SomeThing.Core' to 'Something.Core/SomeThing.Core' failed. Should I try again? (y/n) n
fatal: renaming 'SomeThing.Core' failed: Permission denied
call 'git mv "C:\[redacted]\SomeThing\SomeThing.Core" "C:\[redacted]\SomeThing\Something.Core"' failed - aborting
...running git reset to undo any changes...
HEAD is now at f9dd0d3 Initial commit

I tried using ProjectRenamer for the first time yesterday and ran into this issue. It turned out I had the project folder and some of the subfolders open in Windows Explorer and it must have been holding handles to them or the contents. Once I closed all the folders (actually restarted explorer.exe) the tool worked perfectly.

This wouldn't be your issue too?

304NotModified commented 1 year ago

That is always a hard issue, if explorer.exe is locking your folders. Not sure if we could fix/recognize that in .NET?

Jabbado commented 1 year ago

That is always a hard issue, if explorer.exe is locking your folders. Not sure if we could fix/recognize that in .NET?

I would say it was actually a file locked in one of the folders I had open. If this is what was affecting the other users then I don't think it's an issue with ProjectRenamer per se.

Anyway I looked into this file locking issue as I have use for it in a project and found some interesting code that attempts to find if and what is locking a file: https://stackoverflow.com/a/20623302 It seems to work at least in Windows 10.

304NotModified commented 1 year ago

Anyway I looked into this file locking issue as I have use for it in a project and found some interesting code that attempts to find if and what is locking a file: https://stackoverflow.com/a/20623302 It seems to work at least in Windows 10.

Cool stuff:)

304NotModified commented 3 months ago

related: https://github.com/ModernRonin/ProjectRenamer/issues/33