Skip to content

Commit 3c72844

Browse files
authored
Refresh uncommitted now adds records when applicable, better conditions for removing records that are no longer relevant, calling the method after any git request (#193)
Co-authored-by: Sarmishta Velury <isc-svelury@users.noreply.github.com>
1 parent 418bbd8 commit 3c72844

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

cls/SourceControl/Git/Change.cls

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ClassMethod IsUncommitted(Filename, ByRef ID) As %Boolean
7979
}
8080

8181
/// Goes through Uncommitted queue and removes any items of action 'edit' or 'add' which are ReadOnly or non-existent on the filesystem
82-
ClassMethod RefreshUncommitted(Display = 1, IncludeRevert = 0) As %Status
82+
ClassMethod RefreshUncommitted(Display = 0, IncludeRevert = 0) As %Status
8383
{
8484
// files from the uncommitted queue
8585
set sc=..ListUncommitted(.tFileList,IncludeRevert,0)
@@ -88,21 +88,42 @@ ClassMethod RefreshUncommitted(Display = 1, IncludeRevert = 0) As %Status
8888
// files from git status
8989
do ##class(Utils).GitStatus(.gitFiles)
9090

91+
// Remove entries in the uncommitted queue that don't correspond to changes as tracked by git
9192
set filename="", filename=$order(tFileList(filename),1,action)
92-
while (filename'="") {
93-
set examine=$select(action="add":1,action="edit":1,IncludeRevert&&(action="revert"):1,1:0)
93+
while (filename'="") {
94+
set examine=$select(action="add":1,action="edit":1,action="delete":1, IncludeRevert&&(action="revert"):1,1:0)
9495
if 'examine set filename=$order(tFileList(filename),1,action) continue
9596

9697
set InternalName = ##class(SourceControl.Git.Utils).NameToInternalName(filename,0,0)
9798

98-
if (('##class(%File).Exists(filename)) || ((InternalName '= "") && ('$data(gitFiles(InternalName), found)) && ($data($$$TrackedItems(InternalName))))) {
99+
if (('##class(%File).Exists(filename)) || (InternalName = "") || ((InternalName '= "") && ('$data(gitFiles(InternalName), found)) &&
100+
(($data($$$TrackedItems(InternalName))) || ##class(SourceControl.Git.Utils).NormalizeExtension($data($$$TrackedItems(InternalName)))))) {
99101
set sc=..RemoveUncommitted(filename,Display,0,0)
100102
if $$$ISERR(sc) set filename="" continue
101103
}
102104
set filename=$order(tFileList(filename),1,action)
103105
}
106+
107+
// Add missing records to the uncommitted queue that correspond to changes as tracked by git
108+
set filename="", filename=$order(gitFiles(filename),1,details)
109+
while (filename'="") {
110+
set InternalName = filename
111+
set ExternalName = ##class(%File).NormalizeFilename(##class(SourceControl.Git.Utils).TempFolder()_$list(details,2))
112+
set changeType = $list(details,1)
113+
114+
set action = $select(changeType="A":"add",
115+
changeType="M":"edit",
116+
changeType="D":"delete",
117+
changeType="U":"add",
118+
1:"add")
119+
120+
if ((##class(%File).Exists(ExternalName)) && ('$ISVALIDNUM(InternalName)) && ('..IsUncommitted(ExternalName)) && ($data($$$TrackedItems(InternalName)))) {
121+
set sc=..SetUncommitted(ExternalName, action, InternalName, $USERNAME, "", 1, "", "", 0)
122+
if $$$ISERR(sc) w sc set filename="" continue
123+
}
124+
set filename=$order(gitFiles(filename),1,details)
125+
}
104126
quit sc
105127
}
106128

107129
}
108-

cls/SourceControl/Git/Extension.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ Method GetStatus(InternalName As %String, ByRef IsInSourceControl As %Boolean, B
289289
if '$$$FileExists(filename) {
290290
set IsCheckedOut=0
291291
}
292+
do ##class(SourceControl.Git.Change).RefreshUncommitted()
292293
do ##class(SourceControl.Git.Utils).GitStatus(.files)
293294
if $get(files(InternalName)) '= "" {
294295
///it's in source control, checked out, and should be locked to editing by other users

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
3939
if $piece(pagePath,"/",3) = "cat-file" {
4040
set file = $piece(pagePath,"/",4,*)
4141
do ##class(SourceControl.Git.Utils).RunGitCommand("-c",,.%data,"color.ui=false","cat-file","-p",file)
42+
do ##class(SourceControl.Git.Change).RefreshUncommitted()
4243
set handled = 1
4344
}
4445
} elseif (pathStart = "hostname") {
@@ -133,6 +134,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
133134
do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines))
134135
do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected
135136
do %data.Rewind()
137+
do ##class(SourceControl.Git.Change).RefreshUncommitted()
136138
set handled = 1
137139
}
138140
}
@@ -151,7 +153,8 @@ ClassMethod UserInfo() As %SystemBase
151153
ClassMethod Uncommitted() As %SystemBase
152154
{
153155
// Stub
154-
do ##class(Utils).GitStatus(.files, 1)
156+
do ##class(SourceControl.Git.Change).RefreshUncommitted()
157+
do ##class(SourceControl.Git.Utils).GitStatus(.files, 1)
155158
set output = ""
156159
set key = ""
157160

0 commit comments

Comments
 (0)