ProjectRenamer icon indicating copy to clipboard operation
ProjectRenamer copied to clipboard

Rename from 'X' to 'Y' failed.

Open canro91 opened this issue 3 years ago • 8 comments

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

canro91 avatar Apr 21 '22 16:04 canro91

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.

ModernRonin avatar Apr 27 '22 11:04 ModernRonin

any news on this?

304NotModified avatar Aug 26 '22 22:08 304NotModified

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

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

ModernRonin avatar Aug 29 '22 16:08 ModernRonin

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?

Jabbado avatar Aug 29 '22 21:08 Jabbado

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

304NotModified avatar Aug 30 '22 19:08 304NotModified

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.

Jabbado avatar Aug 30 '22 21:08 Jabbado

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 avatar Aug 30 '22 23:08 304NotModified

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

304NotModified avatar Apr 04 '24 10:04 304NotModified