Skip to content

Commit 284b0a9

Browse files
authored
Merge branch 'main' into longBranchName
2 parents 3d38013 + 8b1b391 commit 284b0a9

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111
- Support for git submodules in package manager-aware setting (#305)
1212
- Web UI's 'More ...' view shows longer branch names (#294)
13+
- Deletion of files in locked environment is now suppressed (#302)
1314

1415
## [2.3.0] - 2023-12-06
1516

cls/SourceControl/Git/Extension.cls

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
4747
if Type = 1, Name = 5 {
4848
// reroute to Status menu option
4949
set Name = "%SourceMenu,Status"
50-
}
50+
}
5151

5252
#dim ec as %Status = $$$OK
5353
#dim menu as %Status = $piece(Name, ",", 1)
@@ -253,13 +253,18 @@ InternalName'="" && ##class(Utils).IsInSourceControl(##class(Utils).NormalizeInt
253253
/// Called before an item is deleted.
254254
Method OnBeforeDelete(InternalName As %String) As %Status
255255
{
256-
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
257-
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
258-
set Filename = ##class(Utils).FullExternalName(InternalName)
259-
if ##class(Utils).IsInSourceControl(InternalName) {
260-
quit ##class(Change).AddDeletedToUncommitted(Filename, InternalName)
256+
if ..IsReadOnly(InternalName) {
257+
// throw error if deleting readonly item
258+
Throw ##class(%Exception.General).%New("Can't delete in locked environment")
259+
} else {
260+
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
261+
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
262+
set Filename = ##class(Utils).FullExternalName(InternalName)
263+
if ##class(Utils).IsInSourceControl(InternalName) {
264+
quit ##class(Change).AddDeletedToUncommitted(Filename, InternalName)
265+
}
266+
quit $$$OK
261267
}
262-
quit $$$OK
263268
}
264269

265270
/// Called after an item is deleted.

test/UnitTest/SourceControl/Git/AddRemove.cls

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ Import SourceControl.Git
33
Class UnitTest.SourceControl.Git.AddRemove Extends %UnitTest.TestCase
44
{
55

6+
Method TestReadonlyDelete()
7+
{
8+
new %SourceControl
9+
do ##class(%Studio.SourceControl.Interface).SourceControlCreate()
10+
do ##class(API).Lock()
11+
try {
12+
do %SourceControl.OnBeforeDelete("")
13+
do $$$AssertFailure("No error thrown when deleting in locked environment")
14+
} catch e {
15+
do $$$AssertEquals(e.Name,"Can't delete in locked environment")
16+
}
17+
do ##class(API).Unlock()
18+
}
19+
620
Method TestInit()
721
{
822
new %SourceControl

0 commit comments

Comments
 (0)