Skip to content

Commit d244f0e

Browse files
committed
Merge pull request mono#1396 from mono/bug35665
Case rename support.
2 parents f1b7c29 + f24866a commit d244f0e

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,19 @@ protected override void OnMoveFile (FilePath localSrcPath, FilePath localDestPat
14441444
dstRepo.Unstage (localDestPath);
14451445

14461446
if (srcRepo == dstRepo) {
1447-
srcRepo.Move (localSrcPath, localDestPath);
1447+
if (string.Equals (localSrcPath, localDestPath, StringComparison.OrdinalIgnoreCase)) {
1448+
try {
1449+
string temp = Path.GetTempFileName ();
1450+
File.Delete (temp);
1451+
File.Move (localSrcPath, temp);
1452+
DeleteFile (localSrcPath, true, monitor, false);
1453+
File.Move (temp, localDestPath);
1454+
} finally {
1455+
srcRepo.Stage (localDestPath);
1456+
}
1457+
} else {
1458+
srcRepo.Move (localSrcPath, localDestPath);
1459+
}
14481460
ClearCachedVersionInfo (localSrcPath, localDestPath);
14491461
} else {
14501462
File.Copy (localSrcPath, localDestPath);

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Pads.ProjectPad/ProjectFileNodeBuilder.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public async override void RenameItem (string newName)
181181

182182
if (!FileService.IsValidPath (newPath) || ProjectFolderCommandHandler.ContainsDirectorySeparator (newName)) {
183183
MessageService.ShowWarning (GettextCatalog.GetString ("The name you have chosen contains illegal characters. Please choose a different name."));
184-
} else if ((newProjectFile != null && newProjectFile != file) || File.Exists (file.FilePath.ParentDirectory.Combine (newName))) {
184+
} else if ((newProjectFile != null && newProjectFile != file) || FileExistsCaseSensitive (file.FilePath.ParentDirectory, newName)) {
185185
// If there is already a file under the newPath which is *different*, then throw an exception
186186
MessageService.ShowWarning (GettextCatalog.GetString ("File or directory name is already in use. Please choose a different one."));
187187
} else {
@@ -195,6 +195,15 @@ public async override void RenameItem (string newName)
195195
MessageService.ShowError (GettextCatalog.GetString ("There was an error renaming the file."), ex);
196196
}
197197
}
198+
199+
static bool FileExistsCaseSensitive (FilePath parentDirectory, string fileName)
200+
{
201+
if (!Directory.Exists (parentDirectory))
202+
return false;
203+
204+
return Directory.GetFiles (parentDirectory, fileName)
205+
.Any (file => Path.GetFileName (file) == fileName);
206+
}
198207

199208
public override void ActivateItem ()
200209
{

0 commit comments

Comments
 (0)