Skip to content

Commit

Permalink
Merge pull request #307 from intersystems/suppressDelete
Browse files Browse the repository at this point in the history
Suppress deletion in locked environment
  • Loading branch information
isc-tleavitt authored Jan 4, 2024
2 parents 5fa879a + 8d6bea7 commit 8b1b391
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 12 additions & 7 deletions cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions test/UnitTest/SourceControl/Git/AddRemove.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b1b391

Please sign in to comment.