From f41d50bb3c7a8bfecc4036399266f8ef5e2ac3a4 Mon Sep 17 00:00:00 2001 From: isc-vgao Date: Thu, 21 Dec 2023 16:45:35 -0500 Subject: [PATCH 1/6] add class to test Delete --- cls/TestDelete.cls | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 cls/TestDelete.cls diff --git a/cls/TestDelete.cls b/cls/TestDelete.cls new file mode 100644 index 00000000..63e0bdc9 --- /dev/null +++ b/cls/TestDelete.cls @@ -0,0 +1,3 @@ +Class cls.TestDelete Extends %RegisteredObject +{ +} \ No newline at end of file From 9fe0be6afb0f1351112ae80db64188083d224111 Mon Sep 17 00:00:00 2001 From: isc-vgao Date: Fri, 22 Dec 2023 11:12:39 -0500 Subject: [PATCH 2/6] move TestDelete into SourceControl.Git package --- cls/SourceControl/Git/TestDelete.cls | 5 +++++ cls/TestDelete.cls | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 cls/SourceControl/Git/TestDelete.cls delete mode 100644 cls/TestDelete.cls diff --git a/cls/SourceControl/Git/TestDelete.cls b/cls/SourceControl/Git/TestDelete.cls new file mode 100644 index 00000000..e0e2055b --- /dev/null +++ b/cls/SourceControl/Git/TestDelete.cls @@ -0,0 +1,5 @@ +Class SourceControl.Git.TestDelete Extends %RegisteredObject +{ + +} + diff --git a/cls/TestDelete.cls b/cls/TestDelete.cls deleted file mode 100644 index 63e0bdc9..00000000 --- a/cls/TestDelete.cls +++ /dev/null @@ -1,3 +0,0 @@ -Class cls.TestDelete Extends %RegisteredObject -{ -} \ No newline at end of file From 1eeefef359ca4a1ef9817c5c08400beee65b0fd4 Mon Sep 17 00:00:00 2001 From: isc-vgao Date: Fri, 22 Dec 2023 12:52:58 -0500 Subject: [PATCH 3/6] prevent deletion in locked environment --- cls/SourceControl/Git/Extension.cls | 22 +++++++++++++------ test/UnitTest/SourceControl/Git/AddRemove.cls | 14 ++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/cls/SourceControl/Git/Extension.cls b/cls/SourceControl/Git/Extension.cls index 9e639c5c..002526d1 100644 --- a/cls/SourceControl/Git/Extension.cls +++ b/cls/SourceControl/Git/Extension.cls @@ -47,7 +47,7 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se if Type = 1, Name = 5 { // reroute to Status menu option set Name = "%SourceMenu,Status" - } + } #dim ec as %Status = $$$OK #dim menu as %Status = $piece(Name, ",", 1) @@ -253,13 +253,21 @@ InternalName'="" && ##class(Utils).IsInSourceControl(##class(Utils).NormalizeInt /// Called before an item is deleted. Method OnBeforeDelete(InternalName As %String) As %Status { - set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName) - set InternalName = ##class(Utils).NormalizeInternalName(InternalName) - set Filename = ##class(Utils).FullExternalName(InternalName) - if ##class(Utils).IsInSourceControl(InternalName) { - quit ##class(Change).AddDeletedToUncommitted(Filename, InternalName) + if ..IsReadOnly(InternalName) { + set ^mtempVG("dbg",$i(^mtempVG)) = "readonly" + // throw error if deleting readonly item + Throw ##class(%Exception.General).%New("Can't delete in locked environment") + } else { + set ^mtempVG("dbg",$i(^mtempVG)) = "not readonly" + set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName) + set InternalName = ##class(Utils).NormalizeInternalName(InternalName) + set Filename = ##class(Utils).FullExternalName(InternalName) + if ##class(Utils).IsInSourceControl(InternalName) { + quit ##class(Change).AddDeletedToUncommitted(Filename, InternalName) + } + quit $$$OK } - quit $$$OK + set ^mtempVG("dbg",$i(^mtempVG)) = "outside, after if readonly" } /// Called after an item is deleted. diff --git a/test/UnitTest/SourceControl/Git/AddRemove.cls b/test/UnitTest/SourceControl/Git/AddRemove.cls index 85890573..6ae2ac16 100644 --- a/test/UnitTest/SourceControl/Git/AddRemove.cls +++ b/test/UnitTest/SourceControl/Git/AddRemove.cls @@ -3,6 +3,20 @@ Import SourceControl.Git Class UnitTest.SourceControl.Git.AddRemove Extends %UnitTest.TestCase { +Method TestReadonlyDelete() +{ + new %SourceControl + do ##class(%Studio.SourceControl.Interface).SourceControlCreate() + do ##class(API).Lock() + try { + do %SourceControl.OnBeforeDelete("") + do $$$AssertFailure("No error thrown when deleting in locked environment") + } catch e { + do $$$AssertEquals(e.Name,"Can't delete in locked environment") + } + do ##class(API).Unlock() +} + Method TestInit() { new %SourceControl From 088301e5039837a3ec37d4ee4ad76fd51eaecd77 Mon Sep 17 00:00:00 2001 From: isc-vgao Date: Thu, 28 Dec 2023 09:38:12 -0500 Subject: [PATCH 4/6] clean up code --- cls/SourceControl/Git/Extension.cls | 3 --- 1 file changed, 3 deletions(-) diff --git a/cls/SourceControl/Git/Extension.cls b/cls/SourceControl/Git/Extension.cls index 002526d1..1674fcc1 100644 --- a/cls/SourceControl/Git/Extension.cls +++ b/cls/SourceControl/Git/Extension.cls @@ -254,11 +254,9 @@ InternalName'="" && ##class(Utils).IsInSourceControl(##class(Utils).NormalizeInt Method OnBeforeDelete(InternalName As %String) As %Status { if ..IsReadOnly(InternalName) { - set ^mtempVG("dbg",$i(^mtempVG)) = "readonly" // throw error if deleting readonly item Throw ##class(%Exception.General).%New("Can't delete in locked environment") } else { - set ^mtempVG("dbg",$i(^mtempVG)) = "not readonly" set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName) set InternalName = ##class(Utils).NormalizeInternalName(InternalName) set Filename = ##class(Utils).FullExternalName(InternalName) @@ -267,7 +265,6 @@ Method OnBeforeDelete(InternalName As %String) As %Status } quit $$$OK } - set ^mtempVG("dbg",$i(^mtempVG)) = "outside, after if readonly" } /// Called after an item is deleted. From 1a45cdd11b44996cdfc2a6d1e115aa615b2f5f0f Mon Sep 17 00:00:00 2001 From: isc-vgao Date: Tue, 2 Jan 2024 16:40:46 -0500 Subject: [PATCH 5/6] delete TestDelete --- cls/SourceControl/Git/TestDelete.cls | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 cls/SourceControl/Git/TestDelete.cls diff --git a/cls/SourceControl/Git/TestDelete.cls b/cls/SourceControl/Git/TestDelete.cls deleted file mode 100644 index e0e2055b..00000000 --- a/cls/SourceControl/Git/TestDelete.cls +++ /dev/null @@ -1,5 +0,0 @@ -Class SourceControl.Git.TestDelete Extends %RegisteredObject -{ - -} - From f2d4a2ac800f6e270715ecbbd8771691e1f24a78 Mon Sep 17 00:00:00 2001 From: isc-vgao Date: Wed, 3 Jan 2024 12:20:15 -0500 Subject: [PATCH 6/6] add suppress deletion to Fixed section --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a99708d4..1df052cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Support for git submodules in package manager-aware setting (#305) +- Deletion of files in locked environment is now suppressed (#302) ## [2.3.0] - 2023-12-06