Skip to content

Commit 313b11b

Browse files
authored
Merge pull request #436 from intersystems/instance-wide-uncommitted-queue
Instance wide uncommitted queue
2 parents 317c644 + d8ae210 commit 313b11b

File tree

6 files changed

+97
-3
lines changed

6 files changed

+97
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [2.5.1] - Unreleased
8+
## [2.6.0] - Unreleased
9+
10+
### Added
11+
- Files in uncommitted queue in any namespace warn users when opened except for in VSCode (#370)
912

1013
### Fixed
1114
- 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
@@ -185,6 +185,51 @@ ClassMethod RefreshUncommitted(Display = 0, IncludeRevert = 0, Output gitFiles,
185185
quit sc
186186
}
187187

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

239284
}
285+

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: 4 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")
@@ -320,4 +324,3 @@ Method OnAfterConfigure() As %Boolean
320324
}
321325

322326
}
323-

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() = """")
@@ -2515,6 +2520,25 @@ ClassMethod GetGitEnabledNamespaces() As %String
25152520
quit enabledNamespaces
25162521
}
25172522

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

26712695
}
2696+

module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Document name="git-source-control.ZPM">
44
<Module>
55
<Name>git-source-control</Name>
6-
<Version>2.5.1</Version>
6+
<Version>2.6.0</Version>
77
<Description>Server-side source control extension for use of Git on InterSystems platforms</Description>
88
<Keywords>git source control studio vscode</Keywords>
99
<Packaging>module</Packaging>

0 commit comments

Comments
 (0)