Skip to content

Commit cd87590

Browse files
authored
Merge branch 'main' into hide-settings
2 parents 5c435e4 + 3477f86 commit cd87590

File tree

12 files changed

+1889
-87
lines changed

12 files changed

+1889
-87
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111
- Web UI includes a "Push Branch" button for local branches that are ahead of upstream
1212
- Support for making the Settings UI read-only through `##class(SourceControl.Git.API).Configure()` (#258)
13+
- Stash option in the Web UI now includes untracked files
14+
- Added "Status" menu item to editor menu (#285)
1315

1416
### Fixed
17+
- Fatal: bad revision HEAD fixed using an empty commmit (#228)
18+
- Fixed empty mappings when SourceControl.Git.Settings is instantiated (#250)
1519
- Studio export path doesn't get weird mixed slahes on Windows (#252)
20+
- Fixed custom PullHandlers not visible on settings UI (now all subclasses are visible) (#267)
1621
- Fixed bug with adding mappings through the Settings page (#270)
1722
- Pulling add/delete of multiple non-IRIS files no longer causes error (#273)
23+
- Fixed -2 timestamp for some items (#275)
24+
- Reset SourceControlClass during module uninstall to prevent "Class does not exist error" (#285)
1825

1926
## [2.2.0] - 2023-06-05
2027

cls/SourceControl/Git/API.cls

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ ClassMethod Configure()
1212
write !,"Configured SourceControl.Git.Extension as source control class for namespace ",$namespace
1313
set mappingsNode = ##class(SourceControl.Git.Utils).MappingsNode()
1414
if '$data(@mappingsNode) {
15-
set @mappingsNode@("CLS","*")="cls/"
16-
set @mappingsNode@("CLS","UnitTest")="test/"
17-
set @mappingsNode@("INC","*")="inc/"
18-
set @mappingsNode@("MAC","*")="rtn/"
15+
do ##class(SourceControl.Git.Utils).SetDefaultMappings(mappingsNode)
1916
write !,"Configured default mappings for classes, routines, and include files. You can customize these in the global:",!?5,mappingsNode
2017
}
2118
set gitExists = ##class(SourceControl.Git.Utils).GitBinExists(.version)

cls/SourceControl/Git/Build.cls

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Class SourceControl.Git.Build
2+
{
3+
4+
ClassMethod BuildUIForDevMode(devMode As %Boolean, rootDirectory As %String)
5+
{
6+
if 'devMode {
7+
return
8+
}
9+
write !, "In developer mode, building web UI:"
10+
set webUIDirectory = ##class(%File).SubDirectoryName(rootDirectory, "git-webui")
11+
write !, "npm ci"
12+
write !, $zf(-100, "/SHELL", "npm", "ci", "--prefix", webUIDirectory)
13+
write !, "npm run build"
14+
write !, $zf(-100, "/SHELL", "npm", "run", "build", "--prefix", webUIDirectory)
15+
}
16+
17+
}
18+

cls/SourceControl/Git/Extension.cls

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ XData Menu
1010
{
1111
<MenuBase>
1212
<Menu Name="%SourceMenu" Type="0">
13+
<MenuItem Name="Status" />
1314
<MenuItem Name="Settings" />
1415
<MenuItem Name="Init" />
1516
<MenuItem Name="GitWebUI" />
@@ -42,6 +43,12 @@ XData Menu
4243

4344
Method UserAction(Type As %Integer, Name As %String, InternalName As %String, SelectedText As %String, ByRef Action As %String, ByRef Target As %String, ByRef Msg As %String, ByRef Reload As %Boolean) As %Status
4445
{
46+
// If namespace change event
47+
if Type = 1, Name = 5 {
48+
// reroute to Status menu option
49+
set Name = "%SourceMenu,Status"
50+
}
51+
4552
#dim ec as %Status = $$$OK
4653
#dim menu as %Status = $piece(Name, ",", 1)
4754
if menu '= "%SourceMenu", menu'="%SourceContext" {
@@ -86,37 +93,41 @@ Method LocalizeName(name As %String) As %String
8693
"Push":$$$Text("@Push@Push to remote branch"),
8794
"Fetch":$$$Text("@Fetch@Fetch from remote"),
8895
"Pull":$$$Text("@Pull@Pull changes from remote branch"),
96+
"Status": $$$Text("@Status@Status"),
8997
:name)
9098
}
9199

92100
Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef DisplayName As %String, InternalName As %String) As %Status
93101
{
94102
if name = "Settings" {
103+
set Enabled = 1
95104
quit $$$OK
96105
}
97106
if ##class(Utils).NeedSettings() {
98107
set Enabled = -1
99108
quit $$$OK
100109
}
101-
set Enabled = 1
102110
if ##class(Utils).IsNamespaceInGit() {
103-
if name = "GitWebUI" {
104-
} elseif name = "Export" {
105-
} elseif name = "ExportForce" {
106-
} elseif name = "Import" {
107-
} elseif name = "ImportForce" {
108-
} elseif $listfind($listbuild("AddToSC","RemoveFromSC","Revert","Commit"),name) {
109-
quit ..OnSourceMenuContextItem(InternalName,name,.Enabled,.DisplayName)
110-
} elseif name = "NewBranch" {
111-
} elseif name = "SwitchBranch" {
112-
} elseif name = "Push" {
113-
} elseif name = "Fetch" {
114-
} elseif name = "Pull" {
115-
} elseif name = "" {
116-
// enable separators if namespace is in git
117-
} else {
118-
set Enabled = -1
119-
}
111+
if $listfind($listbuild("AddToSC", "RemoveFromSC", "Revert", "Commit"), name) {
112+
quit ..OnSourceMenuContextItem(InternalName,name,.Enabled,.DisplayName)
113+
}
114+
set Enabled = $CASE(name,
115+
// cases
116+
"Status": 1,
117+
"GitWebUI" : 1,
118+
"Export": 1,
119+
"ExportForce": 1,
120+
"Import": 1,
121+
"ImportForce": 1,
122+
"NewBranch": 1,
123+
"SwitchBranch": 1,
124+
"Push": 1,
125+
"Fetch": 1,
126+
"Pull": 1,
127+
"": 1,
128+
:-1 // default
129+
)
130+
120131
} elseif ##class(Utils).GitBinExists() {
121132
if name = "Init" {
122133
} else {

cls/SourceControl/Git/Settings.cls

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ Property Mappings [ MultiDimensional ];
3333

3434
Method %OnNew() As %Status
3535
{
36-
merge ..Mappings = @##class(SourceControl.Git.Utils).MappingsNode()
36+
set mappingsNode = ##class(SourceControl.Git.Utils).MappingsNode()
37+
if '$data(@mappingsNode) {
38+
do ##class(SourceControl.Git.Utils).SetDefaultMappings(mappingsNode)
39+
}
40+
merge ..Mappings = @mappingsNode
3741
set gitBinPath = ##class(SourceControl.Git.Utils).GitBinPath(.isDefault)
3842
if ('isDefault) {
3943
set ..gitBinPath = gitBinPath
@@ -155,6 +159,7 @@ Method OnAfterConfigure() As %Boolean
155159
set workMgr = $System.WorkMgr.%New("")
156160
$$$ThrowOnError(workMgr.Queue("##class(SourceControl.Git.Utils).Init"))
157161
$$$ThrowOnError(workMgr.Sync())
162+
do ##class(SourceControl.Git.Utils).EmptyInitialCommit()
158163
} elseif (value = 2) {
159164
set response = ##class(%Library.Prompt).GetString("Git remote URL (note: if authentication is required, use SSH, not HTTPS):",.remote,,,,defaultPromptFlag)
160165
if (response '= $$$SuccessResponse) {

cls/SourceControl/Git/Utils.cls

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ $Find(..#ImportAfterGitMenuItems, ","_menuItemName_",") > 0
156156
ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Target As %String, ByRef Action As %String, ByRef Reload As %Boolean) As %Status
157157
{
158158
#define Force 1
159-
#dim menuName as %String = $piece(MenuName,",")
159+
// MenuName = "<Name of menu>,<Name of menu item>"
160160
#dim menuItemName as %String = $piece(MenuName,",",2)
161161
#dim ec as %Status = $$$OK
162162

@@ -238,10 +238,10 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
238238
set ec = ..AddToSourceControl(InternalName)
239239
} elseif (menuItemName = "RemoveFromSC") {
240240
set ec = ..RemoveFromSourceControl(InternalName)
241-
} elseif (menuItemName = "Commit") {
242-
set Target = "Please enter a commit message"
243-
set Action = 7
244-
quit $$$OK
241+
} elseif (menuItemName = "Status") {
242+
do ..RunGitCommand("status", .errStream, .outStream)
243+
write !, !, "Git Status: "
244+
do ..PrintStreams(outStream, errStream)
245245
}
246246
quit ec
247247
}
@@ -275,10 +275,8 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %
275275
ClassMethod Init() As %Status
276276
{
277277
do ..RunGitCommand("init",.errStream,.outStream)
278-
$$$NewLineIfNonEmptyStream(errStream)
279-
do errStream.OutputToDevice()
280-
$$$NewLineIfNonEmptyStream(outStream)
281-
do outStream.OutputToDevice()
278+
do ..PrintStreams(outStream, errStream)
279+
282280
quit $$$OK
283281
}
284282

@@ -299,10 +297,7 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
299297
set email = ..GitUserEmail()
300298
set author = username_" <"_email_">"
301299
do ..RunGitWithArgs(.errStream, .outStream, "commit", "--author", author, "-m", Message, filename)
302-
$$$NewLineIfNonEmptyStream(outStream)
303-
do outStream.OutputToDevice()
304-
$$$NewLineIfNonEmptyStream(errStream)
305-
do errStream.OutputToDevice()
300+
do ..PrintStreams(outStream, outStream)
306301
$$$QuitOnError(##class(SourceControl.Git.Change).RemoveUncommitted(filename))
307302
$$$QuitOnError(##class(SourceControl.Git.Change).RefreshUncommitted())
308303
quit $$$OK
@@ -311,20 +306,14 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
311306
ClassMethod NewBranch(newBranchName As %String) As %Status
312307
{
313308
do ..RunGitWithArgs(.errStream, .outStream, "checkout", "-b", newBranchName)
314-
$$$NewLineIfNonEmptyStream(errStream)
315-
do errStream.OutputToDevice()
316-
$$$NewLineIfNonEmptyStream(outStream)
317-
do outStream.OutputToDevice()
309+
do ..PrintStreams(errStream, outStream)
318310
quit $$$OK
319311
}
320312

321313
ClassMethod SwitchBranch(targetBranchName As %String) As %Status
322314
{
323315
do ..RunGitWithArgs(.errStream, .outStream, "checkout", targetBranchName)
324-
$$$NewLineIfNonEmptyStream(errStream)
325-
do errStream.OutputToDevice()
326-
$$$NewLineIfNonEmptyStream(outStream)
327-
do outStream.OutputToDevice()
316+
do ..PrintStreams(errStream, outStream)
328317
quit $$$OK
329318
}
330319

@@ -333,10 +322,7 @@ ClassMethod Push(remote As %String = "origin") As %Status
333322
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("branch",,.errStream,.outstream,"--show-current")
334323
set branchName = outstream.ReadLine(outstream.Size)
335324
do ..RunGitWithArgs(.errStream, .outStream, "push", remote, branchName)
336-
$$$NewLineIfNonEmptyStream(errStream)
337-
do errStream.OutputToDevice()
338-
$$$NewLineIfNonEmptyStream(outStream)
339-
do outStream.OutputToDevice()
325+
do ..PrintStreams(errStream, outStream)
340326
quit $$$OK
341327
}
342328

@@ -362,8 +348,7 @@ ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Stat
362348

363349
set sc = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("fetch",,.errStream,.outStream, remote, branchName)
364350
if (sc=1){
365-
$$$NewLineIfNonEmptyStream(errStream)
366-
do errStream.OutputToDevice()
351+
do ..PrintStreams(errStream)
367352
quit sc
368353
}
369354

@@ -398,14 +383,10 @@ ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Stat
398383

399384
set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName)
400385
if (sc=1){
401-
$$$NewLineIfNonEmptyStream(errStream)
402-
do errStream.OutputToDevice()
403-
$$$NewLineIfNonEmptyStream(outStream)
404-
do outStream.OutputToDevice()
386+
do ..PrintStreams(errStream, outStream)
405387
quit $$$ERROR(5001, "Pull event handler not called. Fix errors before compiling.")
406388
}
407-
$$$NewLineIfNonEmptyStream(outStream)
408-
do outStream.OutputToDevice()
389+
do ..PrintStreams(outStream)
409390
write !
410391

411392
set key = $order(files(""))
@@ -448,6 +429,7 @@ ClassMethod Clone(remote As %String) As %Status
448429
set settings = ##class(SourceControl.Git.Settings).%New()
449430
// TODO: eventually use /ENV flag with GIT_TERMINAL_PROMPT=0. (This isn't doc'd yet and is only in really new versions.)
450431
set sc = ..RunGitWithArgs(.errStream, .outStream, "clone", remote, settings.namespaceTemp)
432+
// can I substitute this with the new print method?
451433
$$$NewLineIfNonEmptyStream(errStream)
452434
while 'errStream.AtEnd {
453435
write errStream.ReadLine(),!
@@ -484,8 +466,7 @@ ClassMethod GenerateSSHKeyPair() As %Status
484466
for stream=errStream,outStream {
485467
set stream.RemoveOnClose = 1
486468
}
487-
do outStream.OutputToDevice()
488-
do errStream.OutputToDevice()
469+
do ..PrintStreams(outStream, errStream)
489470
quit $$$OK
490471
}
491472

@@ -547,10 +528,7 @@ ClassMethod AddToSourceControl(InternalName As %String) As %Status
547528
set @..#Storage@("items", FileInternalName) = ""
548529
do ..RunGitCommand("add",.errStream,.outStream,filenames(i))
549530
write !, "Added ", FileInternalName, " to source control."
550-
$$$NewLineIfNonEmptyStream(outStream)
551-
do outStream.OutputToDevice()
552-
$$$NewLineIfNonEmptyStream(errStream)
553-
do errStream.OutputToDevice()
531+
do ..PrintStreams(outStream, errStream)
554532
}
555533
}
556534
quit ec
@@ -560,10 +538,7 @@ ClassMethod RemoveFromGit(InternalName)
560538
{
561539
#dim fullName = ##class(Utils).FullExternalName(InternalName)
562540
do ..RunGitCommand("rm",.errStream,.outStream,"--cached", fullName)
563-
$$$NewLineIfNonEmptyStream(errStream)
564-
do errStream.OutputToDevice()
565-
$$$NewLineIfNonEmptyStream(outStream)
566-
do errStream.OutputToDevice()
541+
do ..PrintStreams(errStream, outStream)
567542
}
568543

569544
ClassMethod DeleteExternalsForItem(InternalName As %String) As %Status
@@ -1031,6 +1006,10 @@ ClassMethod RoutineTSH(InternalName As %String) As %String
10311006
#dim type = ..Type(InternalName)
10321007
//for csp-files (csp,js,html,css, all that stored in csp/...) we always check for changes in external file
10331008
#dim tsh = $case(type,"csp":"",:$get(@..#Storage@("TSH", ..NormalizeExtension(InternalName))))
1009+
1010+
// in case an OS level error is returned
1011+
set:(($$$isUNIX & (tsh = -2)) || ($$$isWINDOWS & (tsh = -3))) tsh = 0
1012+
10341013
if tsh = "" {
10351014
#dim ts as %String = ##class(%RoutineMgr).TS(InternalName)
10361015
if ts '= "" {
@@ -1538,6 +1517,12 @@ ClassMethod GitStatus(ByRef files, IncludeAllFiles = 0)
15381517
}
15391518
}
15401519

1520+
ClassMethod EmptyInitialCommit()
1521+
{
1522+
set ret = ..RunGitCommandWithInput("commit",, .errStream, .outStream, "--allow-empty", "-m", "empty initial commit")
1523+
do ..PrintStreams(errStream, outStream)
1524+
}
1525+
15411526
/*
15421527
Internal name: e.g. SourceControl.Git.Utils.CLS
15431528
External name e.g. cls/SourceControl/Git/Utils.cls
@@ -1991,5 +1976,26 @@ ClassMethod BuildCEInstallationPackage(ByRef destination As %String) As %Status
19911976
quit sc
19921977
}
19931978

1979+
ClassMethod SetDefaultMappings(mappingsNode As %String)
1980+
{
1981+
set @mappingsNode@("CLS","*")="cls/"
1982+
set @mappingsNode@("CLS","UnitTest")="test/"
1983+
set @mappingsNode@("INC","*")="inc/"
1984+
set @mappingsNode@("MAC","*")="rtn/"
1985+
}
1986+
1987+
ClassMethod PrintStreams(streams... As %Stream.FileCharacter)
1988+
{
1989+
for i=1:1:$get(streams, 0) {
1990+
set stream = streams(i)
1991+
$$$NewLineIfNonEmptyStream(stream)
1992+
do stream.OutputToDevice()
1993+
}
1994+
}
1995+
1996+
ClassMethod ResetSourceControlClass()
1997+
{
1998+
do ##class(%Studio.SourceControl.Interface).SourceControlClassSet("")
19941999
}
19952000

2001+
}

csp/gitprojectsettings.csp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,14 @@ body {
242242
<label for="pullEventClass" class="col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Handler class for git pull">Pull Event Class</label>
243243
<div class="col-sm-7">
244244
<select class="form-control" id="pullEventClass" name="pullEventClass">
245-
<option value="SourceControl.Git.PullEventHandler.Default" #($Case(settings.pullEventClass,"SourceControl.Git.PullEventHandler.Default":"selected",:""))#>Default</option>
246-
<option value="SourceControl.Git.PullEventHandler.PackageManager" #($Case(settings.pullEventClass,"SourceControl.Git.PullEventHandler.PackageManager":"selected",:""))#>PackageManager</option>
245+
<server>
246+
set rs = ##class(%Dictionary.ClassDefinition).SubclassOfFunc("SourceControl.Git.PullEventHandler")
247+
while rs.%Next() {
248+
set subclass = rs.%GetData(1)
249+
// create option with subclass, set selected if subclass == current pullEventClass
250+
&html<<option value=#(subclass)# #($CASE(subclass, settings.pullEventClass: "selected", :""))#>#($PIECE(subclass, ".", *-0))# </option>>
251+
}
252+
</server>
247253
</select>
248254
</div>
249255
</div>

0 commit comments

Comments
 (0)