Skip to content

Commit 54a3a20

Browse files
authored
Fix misc issues on Linux (#51)
* Fix misc issues on Linux * Clarify git bin settings to support Git being on the path and show the version * Clarify git/PATH behavior via API configure method * Note on git version in readme
1 parent a168320 commit 54a3a20

File tree

6 files changed

+57
-25
lines changed

6 files changed

+57
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Prerequisites/Dependencies
55

66
* IRIS instance with license key
7-
* Git
7+
* Git 2.x (tested as far back as 2.22)
88
* InterSystems package manager (https://openexchange.intersystems.com/package/ObjectScript-Package-Manager)
99

1010
## Installation and Setup

cls/SourceControl/Git/API.cls

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ ClassMethod Configure()
1818
set @mappingsNode@("MAC","*")="rtn/"
1919
write !,"Configured default mappings for classes, routines, and include files. You can customize these in the global:",!?5,mappingsNode
2020
}
21+
set gitExists = ##class(SourceControl.Git.Utils).GitBinExists(.version)
22+
set gitBinPath = ##class(SourceControl.Git.Utils).GitBinPath(.isDefault)
23+
if gitExists && isDefault {
24+
// Note: version starts with "git version"
25+
write !,version," is available via PATH. You may enter a path to a different version if needed."
26+
}
2127
set good = ##class(SourceControl.Git.Settings).Configure()
2228
if 'good {
2329
write !,"Cancelled."

cls/SourceControl/Git/Settings.cls

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Class SourceControl.Git.Settings Extends %RegisteredObject
66
{
77

88
/// Path to git executable
9-
Property gitBinPath As %String [ InitialExpression = {##class(SourceControl.Git.Utils).GitBinPath()}, Required ];
9+
Property gitBinPath As %String;
1010

1111
/// Local git repo root folder
1212
Property namespaceTemp As %String [ InitialExpression = {##class(SourceControl.Git.Utils).TempFolder()}, Required ];
@@ -28,14 +28,21 @@ Property Mappings [ MultiDimensional ];
2828
Method %OnNew() As %Status
2929
{
3030
Merge ..Mappings = @##class(SourceControl.Git.Utils).MappingsNode()
31+
Set gitBinPath = ##class(SourceControl.Git.Utils).GitBinPath(.isDefault)
32+
If ('isDefault) {
33+
Set ..gitBinPath = gitBinPath
34+
}
3135
quit $$$OK
3236
}
3337

3438
Method %Save() As %Status
3539
{
3640
set sysStorage = ##class(SourceControl.Git.Utils).InstallNamespaceStorage()
3741
set storage = ##class(SourceControl.Git.Utils).#Storage
38-
set @sysStorage@("%gitBinPath") = ..gitBinPath
42+
kill @sysStorage@("%gitBinPath")
43+
if (..gitBinPath '= "") {
44+
set @sysStorage@("%gitBinPath") = ..gitBinPath
45+
}
3946
kill @sysStorage@("%gitBinExists")
4047

4148
set @storage@("settings","namespaceTemp") = ##class(SourceControl.Git.Utils).AddSlash(..namespaceTemp)
@@ -80,3 +87,4 @@ ClassMethod Configure() As %Boolean [ CodeMode = objectgenerator ]
8087
}
8188

8289
}
90+

cls/SourceControl/Git/Utils.cls

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,24 @@ ClassMethod Locked(newFlagValue As %Boolean) As %Boolean
6363
quit result
6464
}
6565

66-
ClassMethod GitBinExists() As %Boolean
66+
ClassMethod GitBinExists(ByRef version) As %Boolean
6767
{
68-
#if $system.Version.GetOS()'="Windows"
69-
quit 0
70-
#else
71-
if '$Data(@..InstallNamespaceStorage()@("%gitBinExists")) {
72-
set @..InstallNamespaceStorage()@("%gitBinExists") = ##class(%File).Exists($Extract(..GitBinPath(),2,*-1))
73-
}
74-
quit @..InstallNamespaceStorage()@("%gitBinExists")
75-
#endif
68+
Try {
69+
Do ..RunGitCommand("--version",.err,.out)
70+
Set version = out.ReadLine()
71+
} Catch e {
72+
Set version = ""
73+
}
74+
Quit (version '= "")
7675
}
7776

78-
ClassMethod GitBinPath() As %String
77+
ClassMethod GitBinPath(Output isDefault) As %String
7978
{
80-
set binPath = $Get(@..InstallNamespaceStorage()@("%gitBinPath"))
79+
set isDefault = 0
80+
set binPath = "git"
81+
if '$Data(@..InstallNamespaceStorage()@("%gitBinPath"),binPath)#2 {
82+
set isDefault = 1
83+
}
8184
quit $case($Extract(binPath),"""":binPath,:""""_binPath_"""")
8285
}
8386

@@ -136,11 +139,6 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
136139
#dim menuItemName As %String = $Piece(MenuName,",",2)
137140
#dim ec As %Status = $$$OK
138141

139-
if ..GitBinExists() = 0 && (menuItemName'="%Cache-Git-Settings") &&
140-
($system.Version.GetOS()="Windows") {
141-
write !!,"===Path to git.exe not found: "_..GitBinPath()_"!===",!
142-
}
143-
144142
if (..Type(InternalName) = "csp") && ($Extract(InternalName,1) '= "/") {
145143
set InternalName = "/" _ InternalName
146144
}
@@ -1149,7 +1147,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
11491147
set outLog = ##class(%Library.File).TempFilename()
11501148
set errLog = ##class(%Library.File).TempFilename()
11511149

1152-
set returnCode = $zf(-100,"/STDOUT="_$$$QUOTE(outLog)_" /STDERR="_$$$QUOTE(errLog)_$Case(inFile, "":"", :" /STDIN="_inFile),"git",newArgs...)
1150+
set command = $Extract(..GitBinPath(),2,*-1)
1151+
set returnCode = $zf(-100,"/STDOUT="_$$$QUOTE(outLog)_" /STDERR="_$$$QUOTE(errLog)_$Case(inFile, "":"", :" /STDIN="_inFile),command,newArgs...)
11531152

11541153
set errStream = ##class(%Stream.FileCharacter).%OpenId(errLog,,.sc)
11551154
set outStream = ##class(%Stream.FileCharacter).%OpenId(outLog,,.sc)
@@ -1356,3 +1355,4 @@ ClassMethod OutputConfigureMessage()
13561355
}
13571356

13581357
}
1358+

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,25 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
151151
} else {
152152
set inFile = ""
153153
}
154-
set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c",inFile,.errStream,.%data,gitArgs...)
154+
set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c",inFile,.errStream,.outStream,gitArgs...)
155155

156-
do %data.MoveToEnd()
156+
set %data = ##class(%Stream.TmpCharacter).%New()
157+
set changeTerminators = (%data.LineTerminator '= $c(13,10))
158+
set %data.LineTerminator = $c(13,10) // For the CSPGateway.
159+
while 'outStream.AtEnd {
160+
do %data.WriteLine(outStream.ReadLine())
161+
}
157162

163+
set nLines = 0
158164
while 'errStream.AtEnd {
159165
do %data.WriteLine(errStream.ReadLine())
166+
set:changeTerminators nLines = nLines + 1
160167
}
161168

162169
// Need to write out two lines or we get an infinite loop in JavaScript...
163170
do %data.WriteLine()
164171
do %data.WriteLine()
165-
do %data.WriteLine("Git-Stderr-Length: " _ errStream.Size)
172+
do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines))
166173
do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected
167174
do %data.Rewind()
168175
set handled = 1

csp/gitprojectsettings.csp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,20 @@ hr {
7373
<div class="form-group row mb-3">
7474
<label for="gitBinPath" class="col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Absolute path to the Git executable">Path to git.exe</label>
7575
<div class="col-sm-7">
76-
<input type="text" class="form-control" id="gitBinPath" name="gitBinPath" value='#(..EscapeHTML(settings.gitBinPath))#' placeholder="(e.g. C:\Program Files\Git\bin\git.exe)">
77-
<csp:if condition='$D(%request.Data("gitsettings",1)) && (##class(SourceControl.Git.Utils).GitBinExists()=0)'>
76+
<server>
77+
set exists = ##class(SourceControl.Git.Utils).GitBinExists(.version)
78+
set placeholder = $Select($system.Version.GetOS()="Windows":"(e.g. C:\Program Files\Git\bin\git.exe)",
79+
1:"(e.g., /usr/bin/git)")
80+
if (exists && (settings.gitBinPath = "")) {
81+
set placeholder = "(available via PATH at version shown below)"
82+
}
83+
</server>
84+
<input type="text" class="form-control" id="gitBinPath" name="gitBinPath" value='#(..EscapeHTML(settings.gitBinPath))#' placeholder="#(placeholder)#">
85+
<csp:if condition="'$length(version)">
7886
<p class="text-danger">File not found</p>
87+
<csp:else>
88+
<p><em>#(version)#</em></p>
89+
</csp:else>
7990
</csp:if>
8091
</div>
8192
</div>

0 commit comments

Comments
 (0)