Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
canro91 opened this issue Apr 21, 2022 · 8 comments
Open

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

canro91 opened this issue Apr 21, 2022 · 8 comments

Comments

@canro91
Copy link

canro91 commented Apr 21, 2022

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
Copy link
Owner

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
Copy link

any news on this?

@ModernRonin
Copy link
Owner

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

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

@Jabbado
Copy link

Jabbado commented Aug 29, 2022

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
Copy link

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

@Jabbado
Copy link

Jabbado commented Aug 30, 2022

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
Copy link

304NotModified commented Aug 30, 2022

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
Copy link

related: #33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants