Skip to content

Commit a3368b2

Browse files
committed
Merge branch 'main' into safeguard-discard
2 parents bf99a2d + 313b11b commit a3368b2

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111
- Discards safeguarded by discard stash and warning modal (#455)
12+
- Files in uncommitted queue in any namespace warn users when opened except for in VSCode (#370)
1213

1314
### Fixed
1415
- Changed prompts in configure from 0/1 to no/yes (#461)

cls/SourceControl/Git/Change.cls

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,51 @@ ClassMethod RefreshUncommitted(Display = 0, IncludeRevert = 0, Output gitFiles,
186186
quit sc
187187
}
188188

189+
Query InstanceUncommitted() As %Query(ROWSPEC = "InternalName:%String,User:%String,Namespace:%String")
190+
{
191+
}
192+
193+
ClassMethod InstanceUncommittedExecute(ByRef qHandle As %Binary) As %Status
194+
{
195+
set qHandle("q") = "SELECT InternalName, ChangedBy FROM SourceControl_Git.Change"
196+
set namespaces = ##class(SourceControl.Git.Utils).GetGitEnabledNamespaces()
197+
set tPtr = 0
198+
set qHandle("i") = 1
199+
new $namespace
200+
while $LISTNEXT(namespaces, tPtr, tValue) {
201+
set namespace = $ZCONVERT(tValue, "U")
202+
if '(namespace [ "^") {
203+
set $NAMESPACE = namespace
204+
set statement = ##class(%SQL.Statement).%New()
205+
$$$ThrowOnError(statement.%Prepare(qHandle("q"), 0))
206+
set resultSet = statement.%Execute()
207+
throw:resultSet.%SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(resultSet.%SQLCODE,resultSet.%Message)
208+
while resultSet.%Next(.sc) {
209+
$$$ThrowOnError(sc)
210+
set qHandle("changes", $increment(qHandle("changes")), "InternalName") = resultSet.%GetData(1)
211+
set qHandle("changes", qHandle("changes"), "User") = resultSet.%GetData(2)
212+
set qHandle("changes", qHandle("changes"), "Namespace") = namespace
213+
}
214+
}
215+
}
216+
217+
Quit $$$OK
218+
}
219+
220+
ClassMethod InstanceUncommittedFetch(ByRef qHandle As %Binary, ByRef Row As %List, ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = InstanceUncommittedExecute ]
221+
{
222+
set i = qHandle("i")
223+
if $data(qHandle("changes",i))=10 {
224+
set Row = $listbuild(qHandle("changes", i, "InternalName"), qHandle("changes", i, "User"), qHandle("changes", i, "Namespace"))
225+
}
226+
if i >= $get(qHandle("changes"),0) {
227+
set AtEnd = 1
228+
} else {
229+
set qHandle("i") = $increment(qHandle("i"))
230+
}
231+
Quit $$$OK
232+
}
233+
189234
Storage Default
190235
{
191236
<Data name="ChangeDefaultData">
@@ -238,3 +283,4 @@ Storage Default
238283
}
239284

240285
}
286+

cls/SourceControl/Git/Extension.cls

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,29 @@ XData Menu
4444

4545
Method UserAction(Type As %Integer, Name As %String, InternalName As %String, SelectedText As %String, ByRef Action As %String, ByRef Target As %String, ByRef Msg As %String, ByRef Reload As %Boolean) As %Status
4646
{
47+
set settings = ##class(SourceControl.Git.Settings).%New()
4748
// If namespace change event
4849
if Type = 1, Name = 5 {
4950
// reroute to Status menu option
5051
set Name = "%SourceMenu,Status"
5152
}
5253

54+
if (Type = 1) && (Name = 3) {
55+
if settings.warnInstanceWideUncommitted {
56+
// if item is being edited in a different namespace, opening it will display an alert. Editing in this namespace will remove the alert.
57+
set filename = ##class(SourceControl.Git.Utils).FullExternalName(.InternalName)
58+
do ##class(SourceControl.Git.Change).GetUncommitted(filename,.tAction)
59+
if '$data(tAction) {
60+
set user = "", inNamespace = ""
61+
if ##class(SourceControl.Git.Utils).InstanceWideUncommittedCheck(InternalName, .user, .inNamespace) {
62+
set Target = "Warning: Item " _ InternalName _ " is currently being modified by " _ user _ " in namespace " _ inNamespace _ "."
63+
write !, Target
64+
set Action = 6
65+
}
66+
}
67+
}
68+
}
69+
5370
if (Type = 1) && ((Name = 1) || (Name = 7)) {
5471
do ..AddToSourceControl(InternalName)
5572
}

cls/SourceControl/Git/Settings.cls

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Property compileOnImport As %Boolean [ InitialExpression = {##class(SourceContro
5050
/// Define a namespace-level web application allowing access to multiple git repos across separate namespaces
5151
Property namespaceLevelGitWebApp As %Boolean [ InitialExpression = {##class(SourceControl.Git.Settings).HasNamespaceWebApp()} ];
5252

53+
/// Warn when an item has uncommitted changes in a different namespace in this instance
54+
Property warnInstanceWideUncommitted As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).WarnInstanceWideUncommitted()} ];
55+
5356
Property Mappings [ MultiDimensional ];
5457

5558
Method %OnNew() As %Status
@@ -105,6 +108,7 @@ Method %Save() As %Status
105108
set @storage@("settings", "mappedItemsReadOnly") = ..mappedItemsReadOnly
106109
set @storage@("settings", "defaultMergeBranch") = ..defaultMergeBranch
107110
set @storage@("settings", "compileOnImport") = ..compileOnImport
111+
set @storage@("settings", "warnInstanceWideUncommitted") = ..warnInstanceWideUncommitted
108112
set @storage@("settings", "basicMode") = ..systemBasicMode
109113
if ..basicMode = "system" {
110114
kill @storage@("settings", "user", $username, "basicMode")
@@ -319,4 +323,4 @@ Method OnAfterConfigure() As %Boolean
319323
}
320324
}
321325

322-
}
326+
}

cls/SourceControl/Git/Utils.cls

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ ClassMethod CompileOnImport() As %Boolean
158158
quit $get(@..#Storage@("settings","compileOnImport"),1)
159159
}
160160

161+
ClassMethod WarnInstanceWideUncommitted() As %Boolean
162+
{
163+
quit $get(@..#Storage@("settings","warnInstanceWideUncommitted"),1)
164+
}
165+
161166
ClassMethod NeedSettings() As %Boolean [ CodeMode = expression ]
162167
{
163168
(..TempFolder() = "") || (..GitBinPath() = "") || (..GitBinPath() = """")
@@ -2516,6 +2521,25 @@ ClassMethod GetGitEnabledNamespaces() As %String
25162521
quit enabledNamespaces
25172522
}
25182523

2524+
/// Returns true if the given item has uncommitted changes on a different namespace in this instance.
2525+
ClassMethod InstanceWideUncommittedCheck(InternalName As %String, Output User, Output Namespace) As %Boolean
2526+
{
2527+
set isUncommitted = 0
2528+
set resultSet = ##class(SourceControl.Git.Change).InstanceUncommittedFunc()
2529+
throw:resultSet.%SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(resultSet.%SQLCODE,resultSet.%Message)
2530+
while resultSet.%Next(.sc) {
2531+
$$$ThrowOnError(sc)
2532+
set fileName = resultSet.InternalName
2533+
if (InternalName = fileName) && (resultSet.Namespace '= $namespace) {
2534+
set isUncommitted = 1
2535+
set User = resultSet.User
2536+
set Namespace = resultSet.Namespace
2537+
}
2538+
}
2539+
2540+
quit isUncommitted
2541+
}
2542+
25192543
ClassMethod BuildCEInstallationPackage(ByRef destination As %String) As %Status
25202544
{
25212545
#define sourcedir $System.Util.InstallDirectory()_"devuser/studio/templates/gitsourcecontrol/"
@@ -2670,3 +2694,4 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
26702694
}
26712695

26722696
}
2697+

0 commit comments

Comments
 (0)