Skip to content

Fix new git repo error #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,4 @@ Method AddToSourceControl(InternalName As %String, Description As %String = "")
}

}

2 changes: 1 addition & 1 deletion cls/SourceControl/Git/Settings.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -172,4 +173,3 @@ Method OnAfterConfigure() As %Boolean
}

}

69 changes: 29 additions & 40 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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(""))
Expand Down Expand Up @@ -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(),!
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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("")
Expand Down