Skip to content

Commit 3b9ccc4

Browse files
authored
Merge pull request #288 from intersystems/fix-new-git-repo-error
Fix new git repo error
2 parents af2a53b + 267afa0 commit 3b9ccc4

File tree

4 files changed

+32
-41
lines changed

4 files changed

+32
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Added "Status" menu item to editor menu (#285)
1313

1414
### Fixed
15+
- Fatal: bad revision HEAD fixed using an empty commmit (#228)
1516
- Fixed empty mappings when SourceControl.Git.Settings is instantiated (#250)
1617
- Studio export path doesn't get weird mixed slahes on Windows (#252)
1718
- Fixed bug with adding mappings through the Settings page (#270)

cls/SourceControl/Git/Extension.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,4 @@ Method AddToSourceControl(InternalName As %String, Description As %String = "")
346346
}
347347

348348
}
349+

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: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
236236
} elseif (menuItemName = "Status") {
237237
do ..RunGitCommand("status", .errStream, .outStream)
238238
write !, !, "Git Status: "
239-
do outStream.OutputToDevice()
240-
do errStream.OutputToDevice()
239+
do ..PrintStreams(outStream, errStream)
241240
}
242241
quit ec
243242
}
@@ -271,10 +270,8 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %
271270
ClassMethod Init() As %Status
272271
{
273272
do ..RunGitCommand("init",.errStream,.outStream)
274-
$$$NewLineIfNonEmptyStream(errStream)
275-
do errStream.OutputToDevice()
276-
$$$NewLineIfNonEmptyStream(outStream)
277-
do outStream.OutputToDevice()
273+
do ..PrintStreams(outStream, errStream)
274+
278275
quit $$$OK
279276
}
280277

@@ -295,10 +292,7 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
295292
set email = ..GitUserEmail()
296293
set author = username_" <"_email_">"
297294
do ..RunGitWithArgs(.errStream, .outStream, "commit", "--author", author, "-m", Message, filename)
298-
$$$NewLineIfNonEmptyStream(outStream)
299-
do outStream.OutputToDevice()
300-
$$$NewLineIfNonEmptyStream(errStream)
301-
do errStream.OutputToDevice()
295+
do ..PrintStreams(outStream, outStream)
302296
$$$QuitOnError(##class(SourceControl.Git.Change).RemoveUncommitted(filename))
303297
$$$QuitOnError(##class(SourceControl.Git.Change).RefreshUncommitted())
304298
quit $$$OK
@@ -307,20 +301,14 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
307301
ClassMethod NewBranch(newBranchName As %String) As %Status
308302
{
309303
do ..RunGitWithArgs(.errStream, .outStream, "checkout", "-b", newBranchName)
310-
$$$NewLineIfNonEmptyStream(errStream)
311-
do errStream.OutputToDevice()
312-
$$$NewLineIfNonEmptyStream(outStream)
313-
do outStream.OutputToDevice()
304+
do ..PrintStreams(errStream, outStream)
314305
quit $$$OK
315306
}
316307

317308
ClassMethod SwitchBranch(targetBranchName As %String) As %Status
318309
{
319310
do ..RunGitWithArgs(.errStream, .outStream, "checkout", targetBranchName)
320-
$$$NewLineIfNonEmptyStream(errStream)
321-
do errStream.OutputToDevice()
322-
$$$NewLineIfNonEmptyStream(outStream)
323-
do outStream.OutputToDevice()
311+
do ..PrintStreams(errStream, outStream)
324312
quit $$$OK
325313
}
326314

@@ -329,10 +317,7 @@ ClassMethod Push(remote As %String = "origin") As %Status
329317
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("branch",,.errStream,.outstream,"--show-current")
330318
set branchName = outstream.ReadLine(outstream.Size)
331319
do ..RunGitWithArgs(.errStream, .outStream, "push", remote, branchName)
332-
$$$NewLineIfNonEmptyStream(errStream)
333-
do errStream.OutputToDevice()
334-
$$$NewLineIfNonEmptyStream(outStream)
335-
do outStream.OutputToDevice()
320+
do ..PrintStreams(errStream, outStream)
336321
quit $$$OK
337322
}
338323

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

359344
set sc = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("fetch",,.errStream,.outStream, remote, branchName)
360345
if (sc=1){
361-
$$$NewLineIfNonEmptyStream(errStream)
362-
do errStream.OutputToDevice()
346+
do ..PrintStreams(errStream)
363347
quit sc
364348
}
365349

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

395379
set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName)
396380
if (sc=1){
397-
$$$NewLineIfNonEmptyStream(errStream)
398-
do errStream.OutputToDevice()
399-
$$$NewLineIfNonEmptyStream(outStream)
400-
do outStream.OutputToDevice()
381+
do ..PrintStreams(errStream, outStream)
401382
quit $$$ERROR(5001, "Pull event handler not called. Fix errors before compiling.")
402383
}
403-
$$$NewLineIfNonEmptyStream(outStream)
404-
do outStream.OutputToDevice()
384+
do ..PrintStreams(outStream)
405385
write !
406386

407387
set key = $order(files(""))
@@ -444,6 +424,7 @@ ClassMethod Clone(remote As %String) As %Status
444424
set settings = ##class(SourceControl.Git.Settings).%New()
445425
// TODO: eventually use /ENV flag with GIT_TERMINAL_PROMPT=0. (This isn't doc'd yet and is only in really new versions.)
446426
set sc = ..RunGitWithArgs(.errStream, .outStream, "clone", remote, settings.namespaceTemp)
427+
// can I substitute this with the new print method?
447428
$$$NewLineIfNonEmptyStream(errStream)
448429
while 'errStream.AtEnd {
449430
write errStream.ReadLine(),!
@@ -480,8 +461,7 @@ ClassMethod GenerateSSHKeyPair() As %Status
480461
for stream=errStream,outStream {
481462
set stream.RemoveOnClose = 1
482463
}
483-
do outStream.OutputToDevice()
484-
do errStream.OutputToDevice()
464+
do ..PrintStreams(outStream, errStream)
485465
quit $$$OK
486466
}
487467

@@ -543,10 +523,7 @@ ClassMethod AddToSourceControl(InternalName As %String) As %Status
543523
set @..#Storage@("items", FileInternalName) = ""
544524
do ..RunGitCommand("add",.errStream,.outStream,filenames(i))
545525
write !, "Added ", FileInternalName, " to source control."
546-
$$$NewLineIfNonEmptyStream(outStream)
547-
do outStream.OutputToDevice()
548-
$$$NewLineIfNonEmptyStream(errStream)
549-
do errStream.OutputToDevice()
526+
do ..PrintStreams(outStream, errStream)
550527
}
551528
}
552529
quit ec
@@ -556,10 +533,7 @@ ClassMethod RemoveFromGit(InternalName)
556533
{
557534
#dim fullName = ##class(Utils).FullExternalName(InternalName)
558535
do ..RunGitCommand("rm",.errStream,.outStream,"--cached", fullName)
559-
$$$NewLineIfNonEmptyStream(errStream)
560-
do errStream.OutputToDevice()
561-
$$$NewLineIfNonEmptyStream(outStream)
562-
do errStream.OutputToDevice()
536+
do ..PrintStreams(errStream, outStream)
563537
}
564538

565539
ClassMethod DeleteExternalsForItem(InternalName As %String) As %Status
@@ -1534,6 +1508,12 @@ ClassMethod GitStatus(ByRef files, IncludeAllFiles = 0)
15341508
}
15351509
}
15361510

1511+
ClassMethod EmptyInitialCommit()
1512+
{
1513+
set ret = ..RunGitCommandWithInput("commit",, .errStream, .outStream, "--allow-empty", "-m", "empty initial commit")
1514+
do ..PrintStreams(errStream, outStream)
1515+
}
1516+
15371517
/*
15381518
Internal name: e.g. SourceControl.Git.Utils.CLS
15391519
External name e.g. cls/SourceControl/Git/Utils.cls
@@ -1995,6 +1975,15 @@ ClassMethod SetDefaultMappings(mappingsNode As %String)
19951975
set @mappingsNode@("MAC","*")="rtn/"
19961976
}
19971977

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+
}
1985+
}
1986+
19981987
ClassMethod ResetSourceControlClass()
19991988
{
20001989
do ##class(%Studio.SourceControl.Interface).SourceControlClassSet("")

0 commit comments

Comments
 (0)