Skip to content

Commit 8400412

Browse files
authored
Pull functionality (#13)
* Initial commit * Pull works in terminal, not in Studio or VS Code * Added default parameter for remote name * After pulling we compile files * Added better error handling * Logging minor changes to error handling * Forcing export after pull * Import instead of export * Fixed internal name for compile and made compile list * Cleaned up code and logging, removed condition checking * better printing of diff files + minor changes * Update Extension.cls Co-authored-by: Sarmishta Velury <[email protected]>
1 parent d0a03c4 commit 8400412

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

cls/SourceControl/Git/Change.cls

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ ClassMethod IsUncommitted(Filename, ByRef ID) As %Boolean
6262
}
6363
}
6464

65-
//this is also to test fetch
6665
/// Goes through Uncommitted queue and removes any items of action 'edit' or 'add' which are ReadOnly or non-existent on the filesystem
6766
ClassMethod RefreshUncommitted(Display = 1, IncludeRevert = 0) As %Status
6867
{
@@ -82,4 +81,3 @@ ClassMethod RefreshUncommitted(Display = 1, IncludeRevert = 0) As %Status
8281
}
8382

8483
}
85-

cls/SourceControl/Git/Extension.cls

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef Display
131131
set Enabled = 1
132132
set DisplayName = "Fetch"
133133
}elseif name = "%Pull" {
134-
// TODO: Only display if there are no files checked out by other users
135-
set Enabled = 0
134+
set Enabled = 1
136135
set DisplayName = "Pull"
137136
}elseif ##class(Utils).IsMenuGitCommand(name) && ##class(Utils).GitBinExists() {
138137
set DisplayName = $case(name,"%StashSave":"Stash save",
@@ -308,4 +307,3 @@ Method GetStatus(InternalName As %String, ByRef IsInSourceControl As %Boolean, B
308307
}
309308

310309
}
311-

cls/SourceControl/Git/Utils.cls

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,15 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
198198
quit $$$OK
199199
}elseif (menuItemName = "%Push") {
200200
quit ..Push()
201-
//, Studio still crashes when calling rungitcommand with push as command
202-
//quit $$$OK
203201
}elseif (menuItemName = "%Fetch") {
204-
//TODO: Implement fetch git command
205202
$$$QuitOnError(..Fetch(.diffFiles))
206203
set pointer = 0
207204
while $ListNext(diffFiles, pointer, item){
208205
write !,item
209206
}
210207
write !
211208
}elseif (menuItemName = "%Pull") {
212-
//TODO: Implement pull git command
213-
quit $$$OK
209+
quit ..Pull()
214210
}
215211
elseif ..IsMenuGitCommand(menuItemName) {
216212
set Action = 3
@@ -302,8 +298,6 @@ ClassMethod Fetch(ByRef diffFiles) As %Status
302298
{
303299
do ..RunGitCommand("fetch", .errStream, .outStream)
304300
w !, "git fetch"
305-
//git diff ..origin --name-only
306-
//another test for push
307301
kill errStream, outStream
308302
do ..RunGitCommand("diff", .errStream, .outStream, "..origin", "--name-only")
309303
set diffFiles = ""
@@ -315,8 +309,61 @@ ClassMethod Fetch(ByRef diffFiles) As %Status
315309
quit $$$OK
316310
}
317311

318-
ClassMethod Pull() As %Status
312+
ClassMethod Pull(remote As %String = "origin") As %Status
319313
{
314+
315+
#define Force 1
316+
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("branch",,.errStream,.outStream,"--show-current")
317+
set branchName = outStream.ReadLine(outStream.Size)
318+
write !, "Pulling from branch: ", branchName
319+
320+
set sc = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("fetch",,.errStream,.outStream,)
321+
if (sc=1){
322+
do errStream.OutputToDevice()
323+
quit sc
324+
}
325+
326+
write !, "Fetch done"
327+
write !, "Files in diff: "
328+
329+
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errStream,.outStream,"--name-only",".."_remote)
330+
while (outStream.AtEnd = 0) {
331+
set file = outStream.ReadLine()
332+
set files($I(files)) = file
333+
write !,?4, file
334+
}
335+
336+
set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName)
337+
if (sc=1){
338+
do errStream.OutputToDevice()
339+
do outStream.OutputToDevice()
340+
quit $$$ERROR(5001, "Not compiled. Fix errors before compiling.")
341+
}
342+
write !
343+
do outStream.OutputToDevice()
344+
write !
345+
346+
set nFiles = 0
347+
for i=1:1:$g(files)
348+
{
349+
if ($DATA(files(i))) {
350+
set internalName = ..NameToInternalName(files(i))
351+
if (internalName = "") {
352+
write files(i), " was not imported into the database and will not be compiled. ", !
353+
}
354+
else{
355+
set compilelist(internalName) = ""
356+
set nFiles = nFiles + 1
357+
set ec = ..ImportItem(internalName, $$$Force)
358+
}
359+
}
360+
}
361+
362+
if (nFiles = 0){
363+
write "Nothing to compile.",!
364+
quit $$$OK
365+
}
366+
Do $System.OBJ.CompileList(.compilelist, "cukb")
320367
quit $$$OK
321368
}
322369

@@ -1101,7 +1148,6 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
11011148
if ($DATA(args(i))) {
11021149
set newArgs($i(newArgs)) = args(i)
11031150
}
1104-
11051151
}
11061152

11071153
set outLog = ##class(%Library.File).TempFilename()
@@ -1301,4 +1347,3 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1) A
13011347
}
13021348

13031349
}
1304-

0 commit comments

Comments
 (0)