diff --git a/CHANGELOG.md b/CHANGELOG.md index d63cf7e9..1766908b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added "Status" menu item to editor menu (#285) ### Fixed +- Fatal: bad revision HEAD fixed using an empty commmit (#228) - Fixed empty mappings when SourceControl.Git.Settings is instantiated (#250) - Studio export path doesn't get weird mixed slahes on Windows (#252) - Fixed bug with adding mappings through the Settings page (#270) diff --git a/cls/SourceControl/Git/Extension.cls b/cls/SourceControl/Git/Extension.cls index 7b6515e0..9e639c5c 100644 --- a/cls/SourceControl/Git/Extension.cls +++ b/cls/SourceControl/Git/Extension.cls @@ -346,3 +346,4 @@ Method AddToSourceControl(InternalName As %String, Description As %String = "") } } + diff --git a/cls/SourceControl/Git/Settings.cls b/cls/SourceControl/Git/Settings.cls index afe78ce4..5e3ed17a 100644 --- a/cls/SourceControl/Git/Settings.cls +++ b/cls/SourceControl/Git/Settings.cls @@ -155,6 +155,7 @@ Method OnAfterConfigure() As %Boolean set workMgr = $System.WorkMgr.%New("") $$$ThrowOnError(workMgr.Queue("##class(SourceControl.Git.Utils).Init")) $$$ThrowOnError(workMgr.Sync()) + do ##class(SourceControl.Git.Utils).EmptyInitialCommit() } elseif (value = 2) { set response = ##class(%Library.Prompt).GetString("Git remote URL (note: if authentication is required, use SSH, not HTTPS):",.remote,,,,defaultPromptFlag) if (response '= $$$SuccessResponse) { @@ -172,4 +173,3 @@ Method OnAfterConfigure() As %Boolean } } - diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index 7f29f932..50a34842 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -236,8 +236,7 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe } elseif (menuItemName = "Status") { do ..RunGitCommand("status", .errStream, .outStream) write !, !, "Git Status: " - do outStream.OutputToDevice() - do errStream.OutputToDevice() + do ..PrintStreams(outStream, errStream) } quit ec } @@ -271,10 +270,8 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As % ClassMethod Init() As %Status { do ..RunGitCommand("init",.errStream,.outStream) - $$$NewLineIfNonEmptyStream(errStream) - do errStream.OutputToDevice() - $$$NewLineIfNonEmptyStream(outStream) - do outStream.OutputToDevice() + do ..PrintStreams(outStream, errStream) + quit $$$OK } @@ -295,10 +292,7 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit set email = ..GitUserEmail() set author = username_" <"_email_">" do ..RunGitWithArgs(.errStream, .outStream, "commit", "--author", author, "-m", Message, filename) - $$$NewLineIfNonEmptyStream(outStream) - do outStream.OutputToDevice() - $$$NewLineIfNonEmptyStream(errStream) - do errStream.OutputToDevice() + do ..PrintStreams(outStream, outStream) $$$QuitOnError(##class(SourceControl.Git.Change).RemoveUncommitted(filename)) $$$QuitOnError(##class(SourceControl.Git.Change).RefreshUncommitted()) quit $$$OK @@ -307,20 +301,14 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit ClassMethod NewBranch(newBranchName As %String) As %Status { do ..RunGitWithArgs(.errStream, .outStream, "checkout", "-b", newBranchName) - $$$NewLineIfNonEmptyStream(errStream) - do errStream.OutputToDevice() - $$$NewLineIfNonEmptyStream(outStream) - do outStream.OutputToDevice() + do ..PrintStreams(errStream, outStream) quit $$$OK } ClassMethod SwitchBranch(targetBranchName As %String) As %Status { do ..RunGitWithArgs(.errStream, .outStream, "checkout", targetBranchName) - $$$NewLineIfNonEmptyStream(errStream) - do errStream.OutputToDevice() - $$$NewLineIfNonEmptyStream(outStream) - do outStream.OutputToDevice() + do ..PrintStreams(errStream, outStream) quit $$$OK } @@ -329,10 +317,7 @@ ClassMethod Push(remote As %String = "origin") As %Status do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("branch",,.errStream,.outstream,"--show-current") set branchName = outstream.ReadLine(outstream.Size) do ..RunGitWithArgs(.errStream, .outStream, "push", remote, branchName) - $$$NewLineIfNonEmptyStream(errStream) - do errStream.OutputToDevice() - $$$NewLineIfNonEmptyStream(outStream) - do outStream.OutputToDevice() + do ..PrintStreams(errStream, outStream) quit $$$OK } @@ -358,8 +343,7 @@ ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Stat set sc = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("fetch",,.errStream,.outStream, remote, branchName) if (sc=1){ - $$$NewLineIfNonEmptyStream(errStream) - do errStream.OutputToDevice() + do ..PrintStreams(errStream) quit sc } @@ -394,14 +378,10 @@ ClassMethod Pull(remote As %String = "origin", preview As %Boolean = 0) As %Stat set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName) if (sc=1){ - $$$NewLineIfNonEmptyStream(errStream) - do errStream.OutputToDevice() - $$$NewLineIfNonEmptyStream(outStream) - do outStream.OutputToDevice() + do ..PrintStreams(errStream, outStream) quit $$$ERROR(5001, "Pull event handler not called. Fix errors before compiling.") } - $$$NewLineIfNonEmptyStream(outStream) - do outStream.OutputToDevice() + do ..PrintStreams(outStream) write ! set key = $order(files("")) @@ -444,6 +424,7 @@ ClassMethod Clone(remote As %String) As %Status set settings = ##class(SourceControl.Git.Settings).%New() // TODO: eventually use /ENV flag with GIT_TERMINAL_PROMPT=0. (This isn't doc'd yet and is only in really new versions.) set sc = ..RunGitWithArgs(.errStream, .outStream, "clone", remote, settings.namespaceTemp) + // can I substitute this with the new print method? $$$NewLineIfNonEmptyStream(errStream) while 'errStream.AtEnd { write errStream.ReadLine(),! @@ -480,8 +461,7 @@ ClassMethod GenerateSSHKeyPair() As %Status for stream=errStream,outStream { set stream.RemoveOnClose = 1 } - do outStream.OutputToDevice() - do errStream.OutputToDevice() + do ..PrintStreams(outStream, errStream) quit $$$OK } @@ -543,10 +523,7 @@ ClassMethod AddToSourceControl(InternalName As %String) As %Status set @..#Storage@("items", FileInternalName) = "" do ..RunGitCommand("add",.errStream,.outStream,filenames(i)) write !, "Added ", FileInternalName, " to source control." - $$$NewLineIfNonEmptyStream(outStream) - do outStream.OutputToDevice() - $$$NewLineIfNonEmptyStream(errStream) - do errStream.OutputToDevice() + do ..PrintStreams(outStream, errStream) } } quit ec @@ -556,10 +533,7 @@ ClassMethod RemoveFromGit(InternalName) { #dim fullName = ##class(Utils).FullExternalName(InternalName) do ..RunGitCommand("rm",.errStream,.outStream,"--cached", fullName) - $$$NewLineIfNonEmptyStream(errStream) - do errStream.OutputToDevice() - $$$NewLineIfNonEmptyStream(outStream) - do errStream.OutputToDevice() + do ..PrintStreams(errStream, outStream) } ClassMethod DeleteExternalsForItem(InternalName As %String) As %Status @@ -1534,6 +1508,12 @@ ClassMethod GitStatus(ByRef files, IncludeAllFiles = 0) } } +ClassMethod EmptyInitialCommit() +{ + set ret = ..RunGitCommandWithInput("commit",, .errStream, .outStream, "--allow-empty", "-m", "empty initial commit") + do ..PrintStreams(errStream, outStream) +} + /* Internal name: e.g. SourceControl.Git.Utils.CLS External name e.g. cls/SourceControl/Git/Utils.cls @@ -1995,6 +1975,15 @@ ClassMethod SetDefaultMappings(mappingsNode As %String) set @mappingsNode@("MAC","*")="rtn/" } +ClassMethod PrintStreams(streams... As %Stream.FileCharacter) +{ + for i=1:1:$get(streams, 0) { + set stream = streams(i) + $$$NewLineIfNonEmptyStream(stream) + do stream.OutputToDevice() + } +} + ClassMethod ResetSourceControlClass() { do ##class(%Studio.SourceControl.Interface).SourceControlClassSet("")