Skip to content

Commit fc15782

Browse files
committed
Merge branch 'main' into issue-495
2 parents d08dcf6 + 6ad5fe0 commit fc15782

File tree

20 files changed

+678
-32
lines changed

20 files changed

+678
-32
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [2.6.0] - Unreleased
99

10-
### Added
10+
### Added
11+
- Discards safeguarded by discard stash and warning modal (#455)
1112
- Files in uncommitted queue in any namespace warn users when opened except for in VSCode (#370)
1213
- Added link back to IRIS management portal from Settings, Git WebUI pages (#449)
1314
- Added Import all and Import All (Force) to basic mode menu (#498)

cls/SourceControl/Git/Build.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ ClassMethod BuildUIForDevMode(devMode As %Boolean, rootDirectory As %String)
1414
write !, $zf(-100, "/SHELL", "npm", "run", "build", "--prefix", webUIDirectory)
1515
}
1616

17-
}
18-
17+
}

cls/SourceControl/Git/Change.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ ClassMethod AddDeletedToUncommitted(Filename, InternalName) As %Status
6666
Quit ..SetUncommitted(Filename, "delete", InternalName, $USERNAME, "", 1, "", "", 0)
6767
}
6868

69+
/// The Filename here is an ExternalName formatted name with the full file path
6970
ClassMethod IsUncommitted(Filename, ByRef ID) As %Boolean
7071
{
7172
&SQL(SELECT ID INTO :ID FROM SourceControl_Git.Change WHERE ItemFile = :Filename AND Committed = '0')
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
Class SourceControl.Git.DiscardState Extends (%Persistent, %JSON.Adaptor)
2+
{
3+
4+
Property FullExternalName As %String(MAXLEN = "") [ Required ];
5+
6+
Property Name As %String [ Required ];
7+
8+
Property Contents As %Stream.GlobalCharacter(LOCATION = "^SourceControl.Git.DiscardS");
9+
10+
Property Username As %String [ Required ];
11+
12+
Property Branch As %String [ Required ];
13+
14+
Property Timestamp As %TimeStamp [ Required ];
15+
16+
Property ExternalFile As %Boolean [ Required ];
17+
18+
Index BranchMap On Branch [ Type = bitmap ];
19+
20+
Method RestoreToFileTree()
21+
{
22+
// Make sure directory for file exists
23+
set dir = ##class(%File).GetDirectory(..FullExternalName)
24+
if ('##class(%File).DirectoryExists(dir)) {
25+
do ##class(%File).CreateDirectoryChain(dir)
26+
}
27+
28+
// Recreate File
29+
set fileStream = ##class(%Stream.FileCharacter).%New()
30+
set fileStream.Filename = ..FullExternalName
31+
$$$ThrowOnError(fileStream.CopyFrom(..Contents))
32+
$$$ThrowOnError(fileStream.%Save())
33+
34+
// Add file to source-control / IRIS
35+
if '..ExternalFile {
36+
do ##class(SourceControl.Git.Utils).ImportItem(..Name, 1, 1, 1)
37+
do ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(..Name)
38+
}
39+
40+
// Delete discard record
41+
$$$ThrowOnError(..%DeleteId(..%Id()))
42+
}
43+
44+
ClassMethod SaveDiscardState(InternalName As %String, name As %String) As %Status
45+
{
46+
set discardState = ..%New()
47+
48+
if (InternalName = "") {
49+
// If not in IRIS
50+
set externalName = ##class(%File).Construct(##class(SourceControl.Git.Utils).DefaultTempFolder(),name)
51+
set discardState.FullExternalName = externalName
52+
set discardState.Name = name
53+
set discardState.ExternalFile = 1
54+
} else {
55+
set discardState.FullExternalName = ##class(SourceControl.Git.Utils).FullExternalName(InternalName)
56+
set discardState.Name = InternalName
57+
set discardState.ExternalFile = 0
58+
}
59+
// Copy over file contents
60+
set fileStream = ##class(%Stream.FileCharacter).%New()
61+
set fileStream.Filename = discardState.FullExternalName
62+
do fileStream.%Open()
63+
do discardState.Contents.CopyFrom(fileStream)
64+
do fileStream.%Close()
65+
66+
// Save extra information
67+
set discardState.Username = $USERNAME
68+
set discardState.Branch = ##class(SourceControl.Git.Utils).GetCurrentBranch()
69+
set discardState.Timestamp = $zdatetime($horolog, 3)
70+
71+
set st = discardState.%Save()
72+
73+
quit st
74+
}
75+
76+
ClassMethod DiscardStatesInBranch() As %DynamicArray
77+
{
78+
set currentBranch = ##class(SourceControl.Git.Utils).GetCurrentBranch()
79+
80+
set query = "SELECT ID FROM SourceControl_Git.DiscardState WHERE branch = ?"
81+
set statement = ##class(%SQL.Statement).%New()
82+
set status = statement.%Prepare(query, 0)
83+
$$$ThrowOnError(status)
84+
set resultSet = statement.%Execute(currentBranch)
85+
if (resultSet.%SQLCODE < 0) {
86+
throw ##class(%Exception.SQL).CreateFromSQLCODE(resultSet.%SQLCODE,resultSet.%Message)
87+
}
88+
89+
set discardStates = []
90+
while resultSet.%Next() {
91+
set discardState = ..%OpenId(resultSet.ID)
92+
do discardState.%JSONExportToString(.JSONStr)
93+
set discardStateObject = ##class(%DynamicAbstractObject).%FromJSON(JSONStr)
94+
set discardStateObject.Id = resultSet.ID
95+
do discardStates.%Push(discardStateObject)
96+
}
97+
98+
quit discardStates
99+
}
100+
101+
Storage Default
102+
{
103+
<Data name="DiscardStateDefaultData">
104+
<Value name="1">
105+
<Value>%%CLASSNAME</Value>
106+
</Value>
107+
<Value name="2">
108+
<Value>FullExternalName</Value>
109+
</Value>
110+
<Value name="3">
111+
<Value>InternalName</Value>
112+
</Value>
113+
<Value name="4">
114+
<Value>Contents</Value>
115+
</Value>
116+
<Value name="5">
117+
<Value>Username</Value>
118+
</Value>
119+
<Value name="6">
120+
<Value>Branch</Value>
121+
</Value>
122+
<Value name="7">
123+
<Value>Timestamp</Value>
124+
</Value>
125+
<Value name="8">
126+
<Value>Name</Value>
127+
</Value>
128+
<Value name="9">
129+
<Value>ExternalFile</Value>
130+
</Value>
131+
</Data>
132+
<DataLocation>^SourceControl22B9.DiscardStateD</DataLocation>
133+
<DefaultData>DiscardStateDefaultData</DefaultData>
134+
<IdLocation>^SourceControl22B9.DiscardStateD</IdLocation>
135+
<IndexLocation>^SourceControl22B9.DiscardStateI</IndexLocation>
136+
<StreamLocation>^SourceControl22B9.DiscardStateS</StreamLocation>
137+
<Type>%Storage.Persistent</Type>
138+
}
139+
140+
}

cls/SourceControl/Git/File.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,4 @@ Storage Default
6868
<Type>%Storage.Persistent</Type>
6969
}
7070

71-
}
72-
71+
}

cls/SourceControl/Git/Modification.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ Property internalName As %String;
1111
/// Type of change (A|C|D|M|R|T|U|X|B). See git diff documentation.
1212
Property changeType As %String;
1313

14-
}
15-
14+
}

cls/SourceControl/Git/PackageManagerContext.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@ Method Dump()
5050
write !?4,"Git-enabled? ",$select(..IsInGitEnabledPackage:"Yes",1:"No"),!
5151
}
5252

53-
}
54-
53+
}

cls/SourceControl/Git/PullEventHandler.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,4 @@ ClassMethod ForInternalNames(InternalName As %String) As %Status
4444
quit ..ForModifications(.files)
4545
}
4646

47-
}
48-
47+
}

cls/SourceControl/Git/PullEventHandler/Default.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ Method OnPull() As %Status
1515
quit ##class(SourceControl.Git.PullEventHandler.IncrementalLoad)$this.OnPull()
1616
}
1717

18-
}
19-
18+
}

cls/SourceControl/Git/PullEventHandler/PackageManager.cls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ Method OnPull() As %Status
1111
quit ##class(%ZPM.PackageManager).Shell("load "_..LocalRoot)
1212
}
1313

14-
}
15-
14+
}

0 commit comments

Comments
 (0)