Skip to content

Commit 449c1e1

Browse files
authored
Merge branch 'main' into stash-untracked
2 parents c1deb3e + 3b9ccc4 commit 449c1e1

File tree

5 files changed

+72
-58
lines changed

5 files changed

+72
-58
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ 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
- Stash option in the Web UI now includes untracked files
13+
- Added "Status" menu item to editor menu (#285)
1314

1415
### Fixed
16+
- Fatal: bad revision HEAD fixed using an empty commmit (#228)
1517
- Fixed empty mappings when SourceControl.Git.Settings is instantiated (#250)
1618
- Studio export path doesn't get weird mixed slahes on Windows (#252)
1719
- Fixed bug with adding mappings through the Settings page (#270)
1820
- Pulling add/delete of multiple non-IRIS files no longer causes error (#273)
21+
- Reset SourceControlClass during module uninstall to prevent "Class does not exist error" (#285)
1922

2023
## [2.2.0] - 2023-06-05
2124

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Method OnAfterConfigure() As %Boolean
155155
set workMgr = $System.WorkMgr.%New("")
156156
$$$ThrowOnError(workMgr.Queue("##class(SourceControl.Git.Utils).Init"))
157157
$$$ThrowOnError(workMgr.Sync())
158+
do ##class(SourceControl.Git.Utils).EmptyInitialCommit()
158159
} elseif (value = 2) {
159160
set response = ##class(%Library.Prompt).GetString("Git remote URL (note: if authentication is required, use SSH, not HTTPS):",.remote,,,,defaultPromptFlag)
160161
if (response '= $$$SuccessResponse) {
@@ -172,4 +173,3 @@ Method OnAfterConfigure() As %Boolean
172173
}
173174

174175
}
175-

cls/SourceControl/Git/Utils.cls

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ $Find(..#ImportAfterGitMenuItems, ","_menuItemName_",") > 0
151151
ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Target As %String, ByRef Action As %String, ByRef Reload As %Boolean) As %Status
152152
{
153153
#define Force 1
154-
#dim menuName as %String = $piece(MenuName,",")
154+
// MenuName = "<Name of menu>,<Name of menu item>"
155155
#dim menuItemName as %String = $piece(MenuName,",",2)
156156
#dim ec as %Status = $$$OK
157157

@@ -233,6 +233,10 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
233233
set ec = ..AddToSourceControl(InternalName)
234234
} elseif (menuItemName = "RemoveFromSC") {
235235
set ec = ..RemoveFromSourceControl(InternalName)
236+
} elseif (menuItemName = "Status") {
237+
do ..RunGitCommand("status", .errStream, .outStream)
238+
write !, !, "Git Status: "
239+
do ..PrintStreams(outStream, errStream)
236240
}
237241
quit ec
238242
}
@@ -266,10 +270,8 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %
266270
ClassMethod Init() As %Status
267271
{
268272
do ..RunGitCommand("init",.errStream,.outStream)
269-
$$$NewLineIfNonEmptyStream(errStream)
270-
do errStream.OutputToDevice()
271-
$$$NewLineIfNonEmptyStream(outStream)
272-
do outStream.OutputToDevice()
273+
do ..PrintStreams(outStream, errStream)
274+
273275
quit $$$OK
274276
}
275277

@@ -290,10 +292,7 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
290292
set email = ..GitUserEmail()
291293
set author = username_" <"_email_">"
292294
do ..RunGitWithArgs(.errStream, .outStream, "commit", "--author", author, "-m", Message, filename)
293-
$$$NewLineIfNonEmptyStream(outStream)
294-
do outStream.OutputToDevice()
295-
$$$NewLineIfNonEmptyStream(errStream)
296-
do errStream.OutputToDevice()
295+
do ..PrintStreams(outStream, outStream)
297296
$$$QuitOnError(##class(SourceControl.Git.Change).RemoveUncommitted(filename))
298297
$$$QuitOnError(##class(SourceControl.Git.Change).RefreshUncommitted())
299298
quit $$$OK
@@ -302,20 +301,14 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
302301
ClassMethod NewBranch(newBranchName As %String) As %Status
303302
{
304303
do ..RunGitWithArgs(.errStream, .outStream, "checkout", "-b", newBranchName)
305-
$$$NewLineIfNonEmptyStream(errStream)
306-
do errStream.OutputToDevice()
307-
$$$NewLineIfNonEmptyStream(outStream)
308-
do outStream.OutputToDevice()
304+
do ..PrintStreams(errStream, outStream)
309305
quit $$$OK
310306
}
311307

312308
ClassMethod SwitchBranch(targetBranchName As %String) As %Status
313309
{
314310
do ..RunGitWithArgs(.errStream, .outStream, "checkout", targetBranchName)
315-
$$$NewLineIfNonEmptyStream(errStream)
316-
do errStream.OutputToDevice()
317-
$$$NewLineIfNonEmptyStream(outStream)
318-
do outStream.OutputToDevice()
311+
do ..PrintStreams(errStream, outStream)
319312
quit $$$OK
320313
}
321314

@@ -324,10 +317,7 @@ ClassMethod Push(remote As %String = "origin") As %Status
324317
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("branch",,.errStream,.outstream,"--show-current")
325318
set branchName = outstream.ReadLine(outstream.Size)
326319
do ..RunGitWithArgs(.errStream, .outStream, "push", remote, branchName)
327-
$$$NewLineIfNonEmptyStream(errStream)
328-
do errStream.OutputToDevice()
329-
$$$NewLineIfNonEmptyStream(outStream)
330-
do outStream.OutputToDevice()
320+
do ..PrintStreams(errStream, outStream)
331321
quit $$$OK
332322
}
333323

@@ -353,8 +343,7 @@ ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Stat
353343

354344
set sc = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("fetch",,.errStream,.outStream, remote, branchName)
355345
if (sc=1){
356-
$$$NewLineIfNonEmptyStream(errStream)
357-
do errStream.OutputToDevice()
346+
do ..PrintStreams(errStream)
358347
quit sc
359348
}
360349

@@ -389,14 +378,10 @@ ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Stat
389378

390379
set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName)
391380
if (sc=1){
392-
$$$NewLineIfNonEmptyStream(errStream)
393-
do errStream.OutputToDevice()
394-
$$$NewLineIfNonEmptyStream(outStream)
395-
do outStream.OutputToDevice()
381+
do ..PrintStreams(errStream, outStream)
396382
quit $$$ERROR(5001, "Pull event handler not called. Fix errors before compiling.")
397383
}
398-
$$$NewLineIfNonEmptyStream(outStream)
399-
do outStream.OutputToDevice()
384+
do ..PrintStreams(outStream)
400385
write !
401386

402387
set key = $order(files(""))
@@ -439,6 +424,7 @@ ClassMethod Clone(remote As %String) As %Status
439424
set settings = ##class(SourceControl.Git.Settings).%New()
440425
// TODO: eventually use /ENV flag with GIT_TERMINAL_PROMPT=0. (This isn't doc'd yet and is only in really new versions.)
441426
set sc = ..RunGitWithArgs(.errStream, .outStream, "clone", remote, settings.namespaceTemp)
427+
// can I substitute this with the new print method?
442428
$$$NewLineIfNonEmptyStream(errStream)
443429
while 'errStream.AtEnd {
444430
write errStream.ReadLine(),!
@@ -475,8 +461,7 @@ ClassMethod GenerateSSHKeyPair() As %Status
475461
for stream=errStream,outStream {
476462
set stream.RemoveOnClose = 1
477463
}
478-
do outStream.OutputToDevice()
479-
do errStream.OutputToDevice()
464+
do ..PrintStreams(outStream, errStream)
480465
quit $$$OK
481466
}
482467

@@ -538,10 +523,7 @@ ClassMethod AddToSourceControl(InternalName As %String) As %Status
538523
set @..#Storage@("items", FileInternalName) = ""
539524
do ..RunGitCommand("add",.errStream,.outStream,filenames(i))
540525
write !, "Added ", FileInternalName, " to source control."
541-
$$$NewLineIfNonEmptyStream(outStream)
542-
do outStream.OutputToDevice()
543-
$$$NewLineIfNonEmptyStream(errStream)
544-
do errStream.OutputToDevice()
526+
do ..PrintStreams(outStream, errStream)
545527
}
546528
}
547529
quit ec
@@ -551,10 +533,7 @@ ClassMethod RemoveFromGit(InternalName)
551533
{
552534
#dim fullName = ##class(Utils).FullExternalName(InternalName)
553535
do ..RunGitCommand("rm",.errStream,.outStream,"--cached", fullName)
554-
$$$NewLineIfNonEmptyStream(errStream)
555-
do errStream.OutputToDevice()
556-
$$$NewLineIfNonEmptyStream(outStream)
557-
do errStream.OutputToDevice()
536+
do ..PrintStreams(errStream, outStream)
558537
}
559538

560539
ClassMethod DeleteExternalsForItem(InternalName As %String) As %Status
@@ -1529,6 +1508,12 @@ ClassMethod GitStatus(ByRef files, IncludeAllFiles = 0)
15291508
}
15301509
}
15311510

1511+
ClassMethod EmptyInitialCommit()
1512+
{
1513+
set ret = ..RunGitCommandWithInput("commit",, .errStream, .outStream, "--allow-empty", "-m", "empty initial commit")
1514+
do ..PrintStreams(errStream, outStream)
1515+
}
1516+
15321517
/*
15331518
Internal name: e.g. SourceControl.Git.Utils.CLS
15341519
External name e.g. cls/SourceControl/Git/Utils.cls
@@ -1990,5 +1975,18 @@ ClassMethod SetDefaultMappings(mappingsNode As %String)
19901975
set @mappingsNode@("MAC","*")="rtn/"
19911976
}
19921977

1978+
ClassMethod PrintStreams(streams... As %Stream.FileCharacter)
1979+
{
1980+
for i=1:1:$get(streams, 0) {
1981+
set stream = streams(i)
1982+
$$$NewLineIfNonEmptyStream(stream)
1983+
do stream.OutputToDevice()
1984+
}
19931985
}
19941986

1987+
ClassMethod ResetSourceControlClass()
1988+
{
1989+
do ##class(%Studio.SourceControl.Interface).SourceControlClassSet("")
1990+
}
1991+
1992+
}

module.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<Invoke Class="SourceControl.Git.Utils" Method="Localize" />
3434
<Invoke Class="SourceControl.Git.Utils" Method="ConfigureWeb" />
3535
<Invoke Class="SourceControl.Git.Utils" Method="CheckInitialization" />
36+
37+
<Invoke Class="SourceControl.Git.Utils" Method="ResetSourceControlClass" Phase="Unconfigure" />
3638
</Module>
3739
</Document>
3840
</Export>

0 commit comments

Comments
 (0)