Skip to content

Instance wide uncommitted queue #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- New UI for the basic mode Sync (#415)
- Files in uncommitted queue in any namespace warn users when opened except for in VSCode (#370)

### Fixed
- Instance wide settings are placed in proper global (#444)
Expand Down
43 changes: 43 additions & 0 deletions cls/SourceControl/Git/Change.cls
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,48 @@ ClassMethod RefreshUncommitted(Display = 0, IncludeRevert = 0, Output gitFiles,
quit sc
}

Query InstanceUncommitted() As %Query(ROWSPEC = "InternalName:%String,User:%String,Namespace:%String")
{
}

ClassMethod InstanceUncommittedExecute(ByRef qHandle As %Binary) As %Status
{
set qHandle("q") = "SELECT InternalName, ChangedBy FROM SourceControl_Git.Change"
set namespaces = ##class(SourceControl.Git.Utils).GetGitEnabledNamespaces()
set tPtr = 0
set qHandle("i") = 1
new $namespace
while $LISTNEXT(namespaces, tPtr, tValue) {
set namespace = $ZCONVERT(tValue, "U")
set $NAMESPACE = namespace
set statement = ##class(%SQL.Statement).%New()
$$$ThrowOnError(statement.%Prepare(qHandle("q"), 0))
set resultSet = statement.%Execute()
throw:resultSet.%SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(resultSet.%SQLCODE,resultSet.%Message)
while resultSet.%Next() {
set qHandle("changes", $increment(qHandle("changes")), "InternalName") = resultSet.%GetData(1)
set qHandle("changes", qHandle("changes"), "User") = resultSet.%GetData(2)
set qHandle("changes", qHandle("changes"), "Namespace") = namespace
}
}

Quit $$$OK
}

ClassMethod InstanceUncommittedFetch(ByRef qHandle As %Binary, ByRef Row As %List, ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = InstanceUncommittedExecute ]
{
set i = qHandle("i")
if $data(qHandle("changes",i))=10 {
set Row = $listbuild(qHandle("changes", i, "InternalName"), qHandle("changes", i, "User"), qHandle("changes", i, "Namespace"))
}
if i >= $get(qHandle("changes"),0) {
set AtEnd = 1
} else {
set qHandle("i") = $increment(qHandle("i"))
}
Quit $$$OK
}

Storage Default
{
<Data name="ChangeDefaultData">
Expand Down Expand Up @@ -237,3 +279,4 @@ Storage Default
}

}

17 changes: 17 additions & 0 deletions cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,29 @@ XData Menu

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
{
set settings = ##class(SourceControl.Git.Settings).%New()
// If namespace change event
if Type = 1, Name = 5 {
// reroute to Status menu option
set Name = "%SourceMenu,Status"
}

if (Type = 1) && (Name = 3) {
if settings.warnInstanceWideUncommitted {
// if item is being edited in a different namespace, opening it will display an alert. Editing in this namespace will remove the alert.
set filename = ##class(SourceControl.Git.Utils).FullExternalName(.InternalName)
do ##class(SourceControl.Git.Change).GetUncommitted(filename,.tAction)
if '$data(tAction) {
set user = "", inNamespace = ""
if ##class(SourceControl.Git.Utils).InstanceWideUncommittedCheck(InternalName, .user, .inNamespace) {
set Target = "Warning: Item " _ InternalName _ " is currently being modified by " _ user _ " in namespace " _ inNamespace _ "."
write !, Target
set Action = 6
}
}
}
}

if (Type = 1) && ((Name = 1) || (Name = 7)) {
do ..AddToSourceControl(InternalName)
}
Expand Down
5 changes: 4 additions & 1 deletion cls/SourceControl/Git/Settings.cls
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Property defaultMergeBranch As %String [ InitialExpression = {##class(SourceCont
/// Compile using the configured pull event handler when "Import All" is run
Property compileOnImport As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).CompileOnImport()} ];

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

Property Mappings [ MultiDimensional ];

Method %OnNew() As %Status
Expand Down Expand Up @@ -102,6 +105,7 @@ Method %Save() As %Status
set @storage@("settings", "mappedItemsReadOnly") = ..mappedItemsReadOnly
set @storage@("settings", "defaultMergeBranch") = ..defaultMergeBranch
set @storage@("settings", "compileOnImport") = ..compileOnImport
set @storage@("settings", "warnInstanceWideUncommitted") = ..warnInstanceWideUncommitted
set @storage@("settings", "basicMode") = ..systemBasicMode
if ..basicMode = "system" {
kill @storage@("settings", "user", $username, "basicMode")
Expand Down Expand Up @@ -229,4 +233,3 @@ Method OnAfterConfigure() As %Boolean
}

}

47 changes: 47 additions & 0 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ ClassMethod CompileOnImport() As %Boolean
quit $get(@..#Storage@("settings","compileOnImport"),1)
}

ClassMethod WarnInstanceWideUncommitted() As %Boolean
{
quit $get(@..#Storage@("settings","warnInstanceWideUncommitted"),1)
}

ClassMethod NeedSettings() As %Boolean [ CodeMode = expression ]
{
(..TempFolder() = "") || (..GitBinPath() = "") || (..GitBinPath() = """")
Expand Down Expand Up @@ -2417,6 +2422,47 @@ ClassMethod UncommittedWithAction() As %Library.DynamicObject
quit fileToOtherDevelopers
}

/// Retrieve the list of Namespaces that have git enabled
ClassMethod GetGitEnabledNamespaces() As %String
{
// Get all namespaces
set allNamespaces = ""
do ##class(%SYS.Namespace).ListAll(.allNamespaces)

set enabledNamespaces = ""
set namespace = ""
for {
set namespace = $ORDER(allNamespaces(namespace))
quit:namespace=""
try {
set sourceControlClass = ##class(%Studio.SourceControl.Interface).SourceControlClassGet(namespace)
} catch err {
set sourceControlClass = "" // user does not have access to this namespace
}
if (sourceControlClass = "SourceControl.Git.Extension") set enabledNamespaces = enabledNamespaces _ $listbuild(namespace)
}

quit enabledNamespaces
}

/// Returns true if the given item has uncommitted changes on a different namespace in this instance.
ClassMethod InstanceWideUncommittedCheck(InternalName As %String, Output User, Output Namespace) As %Boolean
{
set isUncommitted = 0
set resultSet = ##class(SourceControl.Git.Change).InstanceUncommittedFunc()
throw:resultSet.%SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(resultSet.%SQLCODE,resultSet.%Message)
while resultSet.%Next() {
set fileName = resultSet.InternalName
if (InternalName = fileName) && (resultSet.Namespace '= $namespace) {
set isUncommitted = 1
set User = resultSet.User
set Namespace = resultSet.Namespace
}
}

quit isUncommitted
}

ClassMethod BuildCEInstallationPackage(ByRef destination As %String) As %Status
{
#define sourcedir $System.Util.InstallDirectory()_"devuser/studio/templates/gitsourcecontrol/"
Expand Down Expand Up @@ -2571,3 +2617,4 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
}

}

Loading