diff options
author | Matt Ward <matt.ward@xamarin.com> | 2015-06-05 14:04:55 +0300 |
---|---|---|
committer | Matt Ward <matt.ward@xamarin.com> | 2015-06-05 14:07:01 +0300 |
commit | b5f79387000f53eea13ad0c1060c78bfd2a4bf83 (patch) | |
tree | 87efdd85dd523e6d87179ba6b8aa78e7a4168ddb /main/src/addins/MonoDevelop.PackageManagement | |
parent | 1fd0463819aedab16bf36b578091a26e652dc04f (diff) |
[NuGet] Fix packages.config marked as deleted by Git on retargeting
Similar to the bug fixed in 1fd0463819aedab16bf36b578091a26e652dc04f
With a project that had only one NuGet package in its packages.config
file, when the project's target framework was changed, the Retarget
menu option that is made available will uninstall and then install the
package so the correct assemblies are referenced for the project's
target framework. The packages.config file is deleted since all the
NuGet packages are removed from the project. This was causing Git to
mark the file as deleted. Now the packages.config file is deleted by
the NuGet addin and the version control system is not told about this
since the file will be recreated when the NuGet package is installed
again. This prevents Git showing the file as deleted.
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
5 files changed, 77 insertions, 14 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProject.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProject.cs index 3c7b19962e..f820f5472e 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProject.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProject.cs @@ -66,6 +66,14 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers IsUpdatePackageCalled = true;
};
+ UninstallPackageAction = (package, uninstallAction) => {
+ PackagePassedToUninstallPackage = package;
+ ForceRemovePassedToUninstallPackage = uninstallAction.ForceRemove;
+ RemoveDependenciesPassedToUninstallPackage = uninstallAction.RemoveDependencies;
+ };
+
+ CreateUninstallPackageActionFunc = () => FakeUninstallPackageAction;
+
this.Name = name;
ConstraintProvider = NullConstraintProvider.Instance;
@@ -159,11 +167,11 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers public void UninstallPackage (IPackage package, UninstallPackageAction uninstallAction)
{
- PackagePassedToUninstallPackage = package;
- ForceRemovePassedToUninstallPackage = uninstallAction.ForceRemove;
- RemoveDependenciesPassedToUninstallPackage = uninstallAction.RemoveDependencies;
+ UninstallPackageAction (package, uninstallAction);
}
+ public Action<IPackage, UninstallPackageAction> UninstallPackageAction;
+
public IPackage PackagePassedToUpdatePackage;
public IEnumerable<PackageOperation> PackageOperationsPassedToUpdatePackage;
public bool UpdateDependenciesPassedToUpdatePackage;
@@ -187,9 +195,11 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers public virtual UninstallPackageAction CreateUninstallPackageAction ()
{
- return FakeUninstallPackageAction;
+ return CreateUninstallPackageActionFunc ();
}
+ public Func<UninstallPackageAction> CreateUninstallPackageActionFunc;
+
public UpdatePackageAction CreateUpdatePackageAction ()
{
var action = new FakeUpdatePackageAction (this);
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ReinstallPackageActionTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ReinstallPackageActionTests.cs index cb5e9e8fd4..c6a6d53182 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ReinstallPackageActionTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ReinstallPackageActionTests.cs @@ -24,7 +24,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using System;
using ICSharpCode.PackageManagement;
using MonoDevelop.PackageManagement.Tests.Helpers;
using NuGet;
@@ -38,6 +37,7 @@ namespace MonoDevelop.PackageManagement.Tests ReinstallPackageAction action;
PackageManagementEvents packageManagementEvents;
FakePackageManagementProject project;
+ FakeFileRemover fileRemover;
void CreateAction (string packageId = "MyPackage", string packageVersion = "1.2.3.4")
{
@@ -46,7 +46,9 @@ namespace MonoDevelop.PackageManagement.Tests packageManagementEvents = new PackageManagementEvents ();
- action = new ReinstallPackageAction (project, packageManagementEvents);
+ fileRemover = new FakeFileRemover ();
+
+ action = new ReinstallPackageAction (project, packageManagementEvents, fileRemover);
action.PackageId = packageId;
action.PackageVersion = new SemanticVersion (packageVersion);
}
@@ -102,6 +104,44 @@ namespace MonoDevelop.PackageManagement.Tests Assert.IsTrue (project.LastInstallPackageCreated.IsExecuteCalled);
Assert.IsFalse (project.LastInstallPackageCreated.OpenReadMeText);
}
+
+ [Test]
+ public void Execute_PackagesConfigFileDeletedDuringUninstall_FileServicePackagesConfigFileDeletionIsCancelled ()
+ {
+ CreateAction ();
+ action.Package = new FakePackage ("Test");
+ string expectedFileName = @"d:\projects\MyProject\packages.config".ToNativePath ();
+ bool? fileRemovedResult = null;
+ project.UninstallPackageAction = (p, a) => {
+ fileRemovedResult = packageManagementEvents.OnFileRemoving (expectedFileName);
+ };
+ project.CreateUninstallPackageActionFunc = () => {
+ return new UninstallPackageAction (project, packageManagementEvents);
+ };
+ action.Execute ();
+
+ Assert.AreEqual (expectedFileName, fileRemover.FileRemoved);
+ Assert.IsFalse (fileRemovedResult.Value);
+ }
+
+ [Test]
+ public void Execute_ScriptFileDeletedDuringUninstall_FileDeletionIsNotCancelled ()
+ {
+ CreateAction ();
+ action.Package = new FakePackage ("Test");
+ string fileName = @"d:\projects\MyProject\scripts\myscript.js".ToNativePath ();
+ bool? fileRemovedResult = null;
+ project.UninstallPackageAction = (p, a) => {
+ fileRemovedResult = packageManagementEvents.OnFileRemoving (fileName);
+ };
+ project.CreateUninstallPackageActionFunc = () => {
+ return new UninstallPackageAction (project, packageManagementEvents);
+ };
+ action.Execute ();
+
+ Assert.IsTrue (fileRemovedResult.Value);
+ Assert.IsNull (fileRemover.FileRemoved);
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs index cf1e92ac1c..d5f6229521 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs @@ -253,5 +253,12 @@ namespace ICSharpCode.PackageManagement {
return new OpenPackageReadMeMonitor (packageId, Project, packageManagementEvents);
}
+
+ protected IDisposable CreateFileMonitor (IFileRemover fileRemover)
+ {
+ return new PreventPackagesConfigFileBeingRemovedOnUpdateMonitor (
+ packageManagementEvents,
+ fileRemover);
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageOperationsAction.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageOperationsAction.cs index 1f832b38f4..8a8d60f691 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageOperationsAction.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageOperationsAction.cs @@ -83,12 +83,5 @@ namespace ICSharpCode.PackageManagement {
packageManagementEvents.OnParentPackageInstalled (Package, Project, Operations);
}
-
- protected IDisposable CreateFileMonitor (IFileRemover fileRemover)
- {
- return new PreventPackagesConfigFileBeingRemovedOnUpdateMonitor (
- packageManagementEvents,
- fileRemover);
- }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ReinstallPackageAction.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ReinstallPackageAction.cs index 6be4d46d97..37a52862d8 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ReinstallPackageAction.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ReinstallPackageAction.cs @@ -38,11 +38,22 @@ namespace MonoDevelop.PackageManagement {
public class ReinstallPackageAction : ProcessPackageAction
{
+ IFileRemover fileRemover;
+
public ReinstallPackageAction (
IPackageManagementProject project,
IPackageManagementEvents packageManagementEvents)
+ : this (project, packageManagementEvents, new FileRemover ())
+ {
+ }
+
+ public ReinstallPackageAction (
+ IPackageManagementProject project,
+ IPackageManagementEvents packageManagementEvents,
+ IFileRemover fileRemover)
: base (project, packageManagementEvents)
{
+ this.fileRemover = fileRemover;
}
protected override string StartingMessageFormat {
@@ -51,7 +62,9 @@ namespace MonoDevelop.PackageManagement protected override void ExecuteCore ()
{
- UninstallPackage ();
+ using (IDisposable monitor = CreateFileMonitor (fileRemover)) {
+ UninstallPackage ();
+ }
InstallPackage ();
}
|