Skip to content

Commit 9024dac

Browse files
committed
fix: git pull now successfully deletes production config items
1 parent 01d0759 commit 9024dac

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// Maintains a cache mapping PTD items' full external names to internal names.
2+
/// This is only required to deploy deletes because once the file is deleted from disk, there is
3+
/// no way to determine the internal name for it.
4+
Class SourceControl.Git.Util.ProductionItemCache
5+
{
6+
7+
ClassMethod Store(externalName, internalName)
8+
{
9+
if externalName '= "" {
10+
set @##class(SourceControl.Git.Utils).#Storage@("ptd_items", $translate(externalName,"\","/")) = internalName
11+
}
12+
}
13+
14+
ClassMethod Lookup(externalName)
15+
{
16+
return $select(
17+
externalName="":"",
18+
1:$get(@##class(SourceControl.Git.Utils).#Storage@("ptd_items", $translate(externalName,"\","/"))))
19+
}
20+
21+
ClassMethod Clear()
22+
{
23+
kill @##class(SourceControl.Git.Utils).#Storage@("ptd_items")
24+
}
25+
26+
}

cls/SourceControl/Git/Utils.cls

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,14 +1265,16 @@ ClassMethod ImportItem(InternalName As %String, force As %Boolean = 0, verbose A
12651265
set imported = 1
12661266
if ..IsRoutineOutdated(InternalName) || force || (type = "ptd"){
12671267
if (type = "ptd") && settings.decomposeProductions && ##class(%Library.EnsembleMgr).IsEnsembleNamespace() {
1268-
// Deployment manager should not reexport because studio project file includes timestamp
1269-
// ideally we could just new %SourceControl, but Ens portal config pages do not use %SourceControl
1270-
new %gscSkipSaveHooks
1271-
set %gscSkipSaveHooks = 1
1272-
set targetProduction = $piece(InternalName,"||",1)
1273-
set rollbackFile = ##class(%File).TempFilename()
1274-
set sc = ##class(Ens.Deployment.Deploy).DeployCode(filename,targetProduction,0,rollbackFile)
1275-
do ##class(%File).Delete(rollbackFile)
1268+
if ##class(%File).Exists(filename) {
1269+
// Deployment manager should not reexport because studio project file includes timestamp
1270+
// ideally we could just new %SourceControl, but Ens portal config pages do not use %SourceControl
1271+
new %gscSkipSaveHooks
1272+
set %gscSkipSaveHooks = 1
1273+
set targetProduction = $piece(InternalName,"||",1)
1274+
set rollbackFile = ##class(%File).TempFilename()
1275+
set sc = ##class(Ens.Deployment.Deploy).DeployCode(filename,targetProduction,0,rollbackFile)
1276+
do ##class(%File).Delete(rollbackFile)
1277+
}
12761278
} elseif (type = "cls") && settings.decomposeProductions
12771279
&& ##class(SourceControl.Git.Production).IsProductionClass(
12781280
..NameWithoutExtension(InternalName), "FullExternalName") {
@@ -2150,7 +2152,9 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S
21502152
quit $translate(found_$translate(InternalName,"%","_"),"\","/")
21512153
} elseif (..Type(InternalName) = "ptd") {
21522154
do ##class(SourceControl.Git.Production).ParseInternalName(InternalName,'default,.filename)
2153-
return $translate(found_filename, "\","/")
2155+
set externalName = $translate(found_filename, "\","/")
2156+
do ##class(SourceControl.Git.Util.ProductionItemCache).Store(..TempFolder()_externalName, InternalName)
2157+
return externalName
21542158
} elseif ext="CLS"||(ext="PRJ")||usertype {
21552159
set nam=$replace(nam,"%", ..PercentClassReplace())
21562160
if default{
@@ -2216,10 +2220,6 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
22162220
}
22172221
if (##class(%File).Exists(Name)) {
22182222
set InternalName = ##class(SourceControl.Git.File).ExternalNameToInternalName(Name)
2219-
if (InternalName '= "") && (context.IsInGitEnabledPackage) {
2220-
// Don't need mappings!
2221-
return ..NormalizeInternalName(InternalName)
2222-
}
22232223
} else {
22242224
// check for file in uncommitted queue
22252225
&sql(SELECT internalName into :InternalName FROM SourceControl_Git.Change where ItemFile = :Name)
@@ -2229,6 +2229,11 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
22292229
set Deleted = 1
22302230
}
22312231
}
2232+
// check for file in production item cache
2233+
if InternalName = "" {
2234+
set InternalName = ##class(SourceControl.Git.Util.ProductionItemCache).Lookup(Name)
2235+
}
2236+
// use mappings
22322237
if (InternalName="") {
22332238
set name=$extract(Name,$length($$$SourceRoot)+1,*)
22342239
set name=$replace(name,"\","/") // standardize slash direction
@@ -2361,7 +2366,11 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
23612366
}
23622367
if ((IgnorePercent)&&($extract(InternalName)="%")) { set InternalName = "" } // don't return a result for % items if instructed to ignore them
23632368
if ((IgnoreNonexistent)&&('##class(%RoutineMgr).Exists(InternalName))&&('Deleted)) { set InternalName = "" } // only return item names which exist in the DB
2364-
quit ..NormalizeInternalName(InternalName)
2369+
set normalizedInternalName = ..NormalizeInternalName(InternalName)
2370+
if ..Type(normalizedInternalName) = "ptd" {
2371+
do ##class(SourceControl.Git.Util.ProductionItemCache).Store(Name, normalizedInternalName)
2372+
}
2373+
quit normalizedInternalName
23652374
}
23662375

23672376
ClassMethod OutputConfigureMessage()

0 commit comments

Comments
 (0)