diff --git a/CHANGELOG.md b/CHANGELOG.md index 12c55d2c..08a76457 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Production Decomposition mode allows controlling interoperability productions as individual files for each host (#469) +- Mapping configuration supports parameter expansion of \ to the environment name (#640) - Added saving settings as system default for new namespaces (#535) - Added filtering through branch names in UI (#615) diff --git a/README.md b/README.md index 6e99fb8e..ec99d771 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ Documentation for the various git-source-control menu options can be found [here To specify where files should go relative to your repository root, add mappings via the "Settings" menu item. A mapping has three parts: * The file extension to use: e.g., CLS, MAC. As a special case for web application files, use "/CSP/" as the mapping. * A filter on the files of that type (e.g., a package name or web application folder) -* The folder relative to the repo root that contains the item. This controls behavior for import and export. +* The folder relative to the repo root that contains the item. This controls behavior for import and export. The keyword `` will be expanded into the environment name to support different mapping configurations, for example for system default settings. This might look like: diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index bb569f35..3d6e46bf 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -1728,6 +1728,7 @@ ClassMethod ExportSystemDefaults() As %Status { new %SourceControl do ##class(%Studio.SourceControl.Interface).SourceControlCreate() + $$$QuitOnError(%SourceControl.AddToSourceControl("Ens.Config.DefaultSettings.ESD")) quit %SourceControl.OnAfterSave("Ens.Config.DefaultSettings.ESD") } @@ -2374,6 +2375,9 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S set MappingExists = 1 } + set settings = ##class(SourceControl.Git.Settings).%New() + set found = ..ExpandMappingParameters(found) + if InternalName["/" { // If no specific mapping was specified (p=""), then return the whole csp filename; otherwise return the name without the mapped piece set InternalName=$extract(InternalName,$length(p)+2,*) @@ -2397,6 +2401,14 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S } } +ClassMethod ExpandMappingParameters(MapDirectory, Settings As SourceControl.Git.Settings = {##class(SourceControl.Git.Settings).%New()}) +{ + return $replace(MapDirectory,"", $zconvert($select( + Settings.environmentName = "": "DEVELOPMENT", + 1: Settings.environmentName) + ,"l")) +} + /// Implementation copied from %Library.RoutineMgr, but with results cached in a PPG. ClassMethod UserTypeCached(Name As %String, ByRef Class As %String, ByRef StudioType As %String, ByRef Schema As %String, ByRef StudioIcon As %Integer) As %Boolean { @@ -2462,6 +2474,7 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V set Deleted = 1 } } + set settings = ##class(SourceControl.Git.Settings).%New() if (InternalName="") { set name=$extract(Name,$length($$$SourceRoot)+1,*) set name=$replace(name,"\","/") // standardize slash direction @@ -2474,6 +2487,7 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V set bestScore = 0 set currScore = 0 while (queryary'="")&&(mappingsSubscript="mappings") { + set dir = ..ExpandMappingParameters(dir, settings) set nam = $extract(name, $length(dir)+1, *) if ($zconvert(subscript, "U") = $zconvert($piece(name, ".", *), "U")) { set extScore = 1 diff --git a/test/UnitTest/SourceControl/Git/NameTest.cls b/test/UnitTest/SourceControl/Git/NameTest.cls index 120df789..3bc97942 100644 --- a/test/UnitTest/SourceControl/Git/NameTest.cls +++ b/test/UnitTest/SourceControl/Git/NameTest.cls @@ -64,6 +64,25 @@ Method TestMixedFoldering() do $$$AssertEquals(##class(Utils).Name("TestPackage.Hello.World.mac"),"rtn/TestPackage/Hello/World.mac") } +Method TestEnvExpansion() +{ + try { + set $$$SourceMapping("ESD","*") = "config//" + set $$$SourceMapping("ESD","*","NoFolders") = 1 + set settings = ##class(SourceControl.Git.Settings).%New() + set oldEnvName = settings.environmentName + set settings.environmentName = "TEST" + $$$ThrowOnError(settings.%Save()) + do $$$AssertEquals(##class(SourceControl.Git.Utils).Name("Ens.Config.DefaultSettings.esd"),"config/test/Ens.Config.DefaultSettings.esd") + } catch err { + do $$$AssertStatusOK(err.AsStatus()) + } + if $data(settings)#2 && $data(oldEnvName)#2 { + set settings.environmentName = oldEnvName + $$$ThrowOnError(settings.%Save()) + } +} + Method OnBeforeAllTests() As %Status { merge ..Mappings = @##class(SourceControl.Git.Utils).MappingsNode() @@ -97,4 +116,3 @@ Method %OnClose() As %Status } } - diff --git a/test/UnitTest/SourceControl/Git/NameToInternalNameTest.cls b/test/UnitTest/SourceControl/Git/NameToInternalNameTest.cls index e8aa60d1..9a7fddd6 100644 --- a/test/UnitTest/SourceControl/Git/NameToInternalNameTest.cls +++ b/test/UnitTest/SourceControl/Git/NameToInternalNameTest.cls @@ -91,6 +91,25 @@ Method TestNegative() do $$$AssertEquals(##class(SourceControl.Git.Utils).NameToInternalName("bar\NotMyBarFile1.bar", 1, 0, 1),"") } +Method TestEnvExpansion() +{ + try { + set $$$SourceMapping("ESD","*") = "config//" + set $$$SourceMapping("ESD","*","NoFolders") = 1 + set settings = ##class(SourceControl.Git.Settings).%New() + set oldEnvName = settings.environmentName + set settings.environmentName = "TEST" + $$$ThrowOnError(settings.%Save()) + do $$$AssertEquals(##class(SourceControl.Git.Utils).NameToInternalName("config/test/Ens.Config.DefaultSettings.ESD",1,0,1),"Ens.Config.DefaultSettings.ESD") + } catch err { + do $$$AssertStatusOK(err.AsStatus()) + } + if $data(settings)#2 && $data(oldEnvName)#2 { + set settings.environmentName = oldEnvName + $$$ThrowOnError(settings.%Save()) + } +} + Method OnBeforeAllTests() As %Status { set settings = ##class(SourceControl.Git.Settings).%New()