diff --git a/CHANGELOG.md b/CHANGELOG.md index 052a2e6f..7a5c2ff6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2.5.1] - Unreleased +## [2.6.0] - Unreleased + +### Added +- Files in uncommitted queue in any namespace warn users when opened except for in VSCode (#370) ### Fixed - Changed prompts in configure from 0/1 to no/yes (#461) diff --git a/cls/SourceControl/Git/Change.cls b/cls/SourceControl/Git/Change.cls index f43f5927..c0c6c7ea 100644 --- a/cls/SourceControl/Git/Change.cls +++ b/cls/SourceControl/Git/Change.cls @@ -185,6 +185,51 @@ 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") + if '(namespace [ "^") { + 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(.sc) { + $$$ThrowOnError(sc) + 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 { @@ -237,3 +282,4 @@ Storage Default } } + diff --git a/cls/SourceControl/Git/Extension.cls b/cls/SourceControl/Git/Extension.cls index f4eab0b3..fb250cad 100644 --- a/cls/SourceControl/Git/Extension.cls +++ b/cls/SourceControl/Git/Extension.cls @@ -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) } diff --git a/cls/SourceControl/Git/Settings.cls b/cls/SourceControl/Git/Settings.cls index 9a763650..58b16522 100644 --- a/cls/SourceControl/Git/Settings.cls +++ b/cls/SourceControl/Git/Settings.cls @@ -50,6 +50,9 @@ Property compileOnImport As %Boolean [ InitialExpression = {##class(SourceContro /// Define a namespace-level web application allowing access to multiple git repos across separate namespaces Property namespaceLevelGitWebApp As %Boolean [ InitialExpression = {##class(SourceControl.Git.Settings).HasNamespaceWebApp()} ]; +/// 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 @@ -105,6 +108,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") @@ -320,4 +324,3 @@ Method OnAfterConfigure() As %Boolean } } - diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index d1533610..5d035521 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -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() = """") @@ -2515,6 +2520,25 @@ ClassMethod GetGitEnabledNamespaces() As %String 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(.sc) { + $$$ThrowOnError(sc) + 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/" @@ -2669,3 +2693,4 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status } } + diff --git a/module.xml b/module.xml index 9374fb5c..f8bc2027 100644 --- a/module.xml +++ b/module.xml @@ -3,7 +3,7 @@ git-source-control - 2.5.1 + 2.6.0 Server-side source control extension for use of Git on InterSystems platforms git source control studio vscode module