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 diff --git a/cls/SourceControl/Git/Extension.cls b/cls/SourceControl/Git/Extension.cls index 9e639c5c..1674fcc1 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,18 @@ 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) { + // throw error if deleting readonly item + Throw ##class(%Exception.General).%New("Can't delete in locked environment") + } else { + 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 } /// 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