Skip to content

Commit f3f74ac

Browse files
authored
Merge pull request #15 from intersystems/better-configurability
Add configuration API method
2 parents 4a27980 + d125f39 commit f3f74ac

File tree

8 files changed

+166
-161
lines changed

8 files changed

+166
-161
lines changed

README.md

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,45 @@
11
# git-source-control
22
Server-side source control extension for Git on InterSystems' platforms
33

4-
<br/>
4+
## Prerequisites/Dependencies
55

6-
## Prerequisites
7-
8-
IRIS instance with license key
9-
10-
<br/>
6+
* IRIS instance with license key
7+
* Git
8+
* ObjectScript package manager (https://openexchange.intersystems.com/package/ObjectScript-Package-Manager)
119

1210
## Installation and Setup
1311
---
1412

1513
1. Clone this repository
16-
2. Install an instance of IRIS.
17-
3. Install ZPM, following the directions here: https://openexchange.intersystems.com/package/ObjectScript-Package-Manager
18-
4. Load this repository into IRIS using ZPM.
14+
2. Load this repository into IRIS using ZPM.
1915
```
2016
zpm "load <absolute path to git-source-control> -verbose"
2117
```
22-
5. To port your Git settings to IRIS, set the following globals:
23-
```
24-
set ^|"%SYS"|SYS("SourceControl","Git","%defaultTemp")="c:\temp\"
25-
set ^|"%SYS"|SYS("SourceControl","Git","%gitBinExists")=1
26-
set ^|"%SYS"|SYS("SourceControl","Git","%gitBinPath")="C:\Program Files\Git\bin\git.exe"
18+
3. Configure settings by running the following method and answering the prompts:
2719
```
28-
29-
6. Run this to set the extension interface up in your editor.
20+
d ##class(SourceControl.Git.API).Configure()
3021
```
31-
do ##class(%Studio.SourceControl.Interface).SourceControlClassSet("SourceControl.Git.Extension")
32-
```
33-
7. In the USER namespace in IRIS, set the following globals:
34-
```
35-
set ^SYS("SourceControl","Git","settings","groupByFolder")=""
36-
set ^SYS("SourceControl","Git","settings","mappings","CLS","*")="cls/"
37-
set ^SYS("SourceControl","Git","settings","mappings","CLS","UnitTest")="test/"
38-
39-
set ^SYS("SourceControl","Git","settings","namespaceTemp")="<absolute path to the git repo>"
40-
set ^SYS("SourceControl","Git","settings","user",$Username,"gitUserEmail")="<git-username>@users.noreply.github.com"
41-
set ^SYS("SourceControl","Git","settings","user",$Username,"gitUserName")="<Your Name>"
42-
```
43-
8. Set up `isfs` server-side editing in VS Code. First save your current workspace in which you have the code open. Then, open the `.code-workspace` file generated by VS Code and add the following to the list of folders:
22+
4. If using VSCode: Set up `isfs` server-side editing. First, save your current workspace in which you have the code open. Then, open the `.code-workspace` file generated by VS Code and add the following to the list of folders:
4423
```
4524
{
4625
"name": "<whatever you want the folder to show up as in the project explorer view>",
4726
"uri": "isfs://<instance_name>:<namespace_name>/"
4827
}
4928
```
50-
9. Go to the URL [http://localhost:<port_number>/isc/studio/usertemplates/gitsourcecontrol/webuidriver.csp/USER]([http://localhost:<port_number>/isc/studio/usertemplates/gitsourcecontrol/webuidriver.csp/USER) and verify that you can see the commit history of your current project.
51-
10. Verify that the server side source control on your editor shows all the Git options by selecting a file on the server and clicking the Server-side Source Control button on the top right-hand corner. Launch the Git UI and verify it runs as expected.
5229
53-
<br/>
30+
## Basic Use
31+
32+
### Studio
33+
Add a file for tracking by right clicking on it in the workspace/project view and choosing Git &gt; Add.
34+
This same menu also has options to remove (stop tracking the file), discard changes (revert to the index), or commit changes.
35+
36+
You can browse file history and commit changes through a user interface launched from the top level Git > "Launch Git UI" menu item. There is also a page for configuring settings.
37+
38+
### VSCode
39+
The same right click menus as in Studio live under "Server Source Control..." when right clicking in a file (in the editor) or on a file when exploring an isfs folder. The top level "source control" menu is accessible through the command palette or the source control icon in the top right of the editor.
40+
41+
### A Note on Security
42+
If you want to interact with remotes from VSCode/Studio directly (e.g., to push/pull), you must use ssh (rather than https), create a public/private key pair to identify the instance (not yourself), configure the private key file for use in Settings, and configure the public key as a deploy key in the remote(s).
5443
5544
## During Development
5645

cls/SourceControl/Git/API.cls

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Class SourceControl.Git.API
2+
{
3+
4+
ClassMethod Configure()
5+
{
6+
set sc = $$$OK
7+
set initTLevel = $TLevel
8+
try {
9+
TSTART
10+
$$$ThrowOnError(##class(%Studio.SourceControl.Interface).SourceControlClassSet("SourceControl.Git.Extension"))
11+
write !,"Configured SourceControl.Git.Extension as source control class for namespace ",$namespace
12+
set mappingsNode = ##class(SourceControl.Git.Utils).MappingsNode()
13+
if '$Data(@mappingsNode) {
14+
set @mappingsNode@("CLS","*")="cls/"
15+
set @mappingsNode@("CLS","UnitTest")="test/"
16+
set @mappingsNode@("INC","*")="inc/"
17+
set @mappingsNode@("MAC","*")="rtn/"
18+
write !,"Configured default mappings for classes, routines, and include files. You can customize these in the global:",!?5,mappingsNode
19+
}
20+
set good = ##class(SourceControl.Git.Settings).Configure()
21+
if 'good {
22+
write !,"Cancelled."
23+
quit
24+
}
25+
TCOMMIT
26+
} catch e {
27+
set sc = e.AsStatus()
28+
write !,$System.Status.GetErrorText(sc)
29+
}
30+
while $TLevel > initTLevel {
31+
TROLLBACK 1
32+
}
33+
}
34+
35+
}
36+

cls/SourceControl/Git/Extension.cls

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,27 @@ XData Menu
88
{
99
<MenuBase>
1010
<Menu Name="%SourceMenu" Type="0">
11-
<MenuItem Name="%Cache-Git-Settings" />
12-
<MenuItem Name="%CreateRepo" Save = "001"/>
13-
<MenuItem Name="%Clone" Save = "001"/>
14-
<MenuItem Separator="true"/>
15-
<MenuItem Name="%GitWebUI" Save = "111" />
16-
<!--
1711
<MenuItem Name="%Settings" />
18-
<MenuItem Name="%Commit" Save = "001"/>
19-
<MenuItem Separator="true"/>
20-
<MenuItem Name="%Pull" Save = "001"/>
21-
<MenuItem Name="%Fetch" Save = "001"/>
22-
<MenuItem Name="%Switch" Save = "001"/>
23-
<MenuItem Name="%Merge" Save = "001"/>
24-
<MenuItem Name="%Push" Save = "001"/>
12+
<MenuItem Name="%Init" Save = "001"/>
2513
<MenuItem Separator="true"/>
26-
<MenuItem Name="%Diff" Save = "001"/>
27-
<MenuItem Name="%RepoStatus" Save = "001"/>
28-
<MenuItem Name="%Resolve" Save = "001"/>
29-
<MenuItem Name="%Revert" Save = "001"/>
30-
<MenuItem Name="%Log" Save = "001"/>
31-
<MenuItem Separator="true"/>
32-
<MenuItem Name="%StashSave" Save = "001"/>
33-
<MenuItem Name="%StashPop" Save = "001"/>
34-
-->
14+
<MenuItem Name="%GitWebUI" Save = "111" />
3515
<MenuItem Separator="true"/>
3616
<MenuItem Name="%Export" Save = "001" />
3717
<MenuItem Name="%ExportForce" Save = "001" />
3818
<MenuItem Name="%Import" Save = "001" />
3919
<MenuItem Name="%ImportForce" Save = "001" />
4020
<MenuItem Name="%Revert" Save = "001" />
4121
<MenuItem Separator="true"/>
42-
<MenuItem Name="%OpenRepoFolder" Save = "001" />
4322
<MenuItem Name="%Commit" Save = "001" />
4423
<MenuItem Name="%Push" Save = "001"/>
4524
<MenuItem Name="%Fetch" Save = "001"/>
4625
<MenuItem Name="%Pull" Save = "001"/>
4726
</Menu>
4827
<Menu Name="%SourceContext" Type="1">
49-
<MenuItem Name="%AddToSC"/>
28+
<MenuItem Name="%AddToSC" Save = "001" />
5029
<MenuItem Name="%RemoveFromSC"/>
51-
<!--
52-
<MenuItem Name="%Diff" Save = "001"/>
53-
<MenuItem Name="%Blame" Save = "001"/>
54-
-->
30+
<MenuItem Name="%Revert" Save = "001" />
31+
<MenuItem Name="%Commit" Save = "001" />
5532
</Menu>
5633
</MenuBase>
5734
}
@@ -82,16 +59,11 @@ Method AfterUserAction(Type As %Integer, Name As %String, InternalName As %Strin
8259

8360
Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef DisplayName As %String, InternalName As %String) As %Status
8461
{
85-
if name = "%Cache-Git-Settings" {
62+
if name = "%Settings" {
8663
// We always show Settings
8764
set DisplayName = "Settings"
8865
quit $$$OK
89-
}
90-
if name = "%Settings" && ##class(Utils).GitBinExists() {
91-
set DisplayName = "TortoiseGit Settings"
92-
quit $$$OK
9366
}
94-
9567
if ##class(Utils).NeedSettings() {
9668
set Enabled = -1
9769
quit $$$OK
@@ -109,9 +81,6 @@ Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef Display
10981
set DisplayName = "Import All Force"
11082
} elseif name = "%RepoStatus" && ##class(Utils).GitBinExists() {
11183
set DisplayName = "Check for modifications"
112-
} elseif name = "%OpenRepoFolder" {
113-
// TODO: Only display if running locally
114-
set DisplayName = "Open Repo Folder"
11584
} elseif name = "%Revert" {
11685
set DisplayName = "Revert Changes"
11786
do ..GetStatus(InternalName, .isInSourceControl, .isEditable,.isCheckedOut,.userCheckedOut)
@@ -143,10 +112,8 @@ Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef Display
143112
set Enabled = -1
144113
}
145114
} elseif ##class(Utils).GitBinExists() {
146-
if name = "%CreateRepo" {
147-
set DisplayName = "Create Repo"
148-
} elseif name = "%Clone" {
149-
set DisplayName = "Clone"
115+
if name = "%Init" {
116+
set DisplayName = "Initialize"
150117
} else {
151118
set Enabled = -1
152119
}
@@ -158,14 +125,15 @@ Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef Display
158125

159126
Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByRef Enabled As %String, ByRef DisplayName As %String) As %Status
160127
{
161-
set:menuItemName="%AddToSC" DisplayName = "Add to SourceControl"
162-
set:menuItemName="%RemoveFromSC" DisplayName = "Remove from SourceControl"
163-
128+
set:menuItemName="%AddToSC" DisplayName = "Add"
129+
set:menuItemName="%RemoveFromSC" DisplayName = "Remove"
130+
set:menuItemName="%Revert" DisplayName = "Discard changes to file"
131+
set:menuItemName="%Commit" DisplayName = "Commit changes to file"
132+
164133
if (itemName = "") || '##class(Utils).IsNamespaceInGit() {
165134
set Enabled = -1
166135
}elseif $F(itemName,",") > 0 { //if more than one item is selected, we can only add/remove, no diff or blame
167136
set Enabled = $case(menuItemName,"%AddToSC":1,"%RemoveFromSC":1,:-1)
168-
169137
}elseif ##class(Utils).IsInSourceControl(##class(Utils).NormalizeInternalName(itemName)) {
170138
set Enabled = $Case(menuItemName, "%AddToSC":-1,:1)
171139
} else {

cls/SourceControl/Git/Settings.cls

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Include %syPrompt
2+
3+
IncludeGenerator %syPrompt
4+
5+
Class SourceControl.Git.Settings Extends %RegisteredObject
6+
{
7+
8+
/// Path to git executable
9+
Property gitBinPath As %String [ InitialExpression = {##class(SourceControl.Git.Utils).GitBinPath()}, Required ];
10+
11+
/// Local git repo root folder
12+
Property namespaceTemp As %String [ InitialExpression = {##class(SourceControl.Git.Utils).TempFolder()}, Required ];
13+
14+
/// Path to private key file (for ssh remotes)
15+
Property privateKeyFile As %String [ InitialExpression = {##class(SourceControl.Git.Utils).PrivateKeyFile()} ];
16+
17+
/// Event handler class for git pull
18+
Property pullEventClass As %String [ InitialExpression = {##class(SourceControl.Git.Utils).PullEventClass()}, Required ];
19+
20+
/// Attribution: Git username for user ${username}
21+
Property gitUserName As %String [ InitialExpression = {##class(SourceControl.Git.Utils).GitUserName()}, Required ];
22+
23+
/// Attribution: Email address for user ${username}
24+
Property gitUserEmail As %String [ InitialExpression = {##class(SourceControl.Git.Utils).GitUserEmail()}, Required ];
25+
26+
Method %Save() As %Status
27+
{
28+
set sysStorage = ##class(SourceControl.Git.Utils).InstallNamespaceStorage()
29+
set storage = ##class(SourceControl.Git.Utils).#Storage
30+
set @sysStorage@("%gitBinPath") = ..gitBinPath
31+
kill @sysStorage@("%gitBinExists")
32+
33+
set @storage@("settings","namespaceTemp") = ##class(SourceControl.Git.Utils).AddSlash(..namespaceTemp)
34+
set @storage@("settings","user",$username,"gitUserName") = ..gitUserName
35+
36+
set @storage@("settings","user",$username,"gitUserEmail") = ..gitUserEmail
37+
set @storage@("settings","ssh","privateKeyFile") = ..privateKeyFile
38+
set @storage@("settings","pullEventClass") = ..pullEventClass
39+
40+
quit $$$OK
41+
}
42+
43+
ClassMethod Configure() As %Boolean [ CodeMode = objectgenerator ]
44+
{
45+
do %code.WriteLine(" set inst = ..%New()")
46+
set defaultPromptFlag = $$$DisableBackupCharMask + $$$TrapCtrlCMask + $$$EnableQuitCharMask + $$$DisableHelpCharMask + $$$DisableHelpContextCharMask + $$$TrapErrorMask
47+
set property = ""
48+
for {
49+
set property = $$$defMemberNext(%class.Name,$$$cCLASSproperty,property)
50+
quit:property=""
51+
set sequence = $$$comMemberKeyGet(%class.Name,$$$cCLASSproperty,property,$$$cPROPsequencenumber)
52+
set orderedProperties(sequence) = property
53+
}
54+
set sequence = ""
55+
for {
56+
set sequence = $Order(orderedProperties(sequence),1,property)
57+
quit:sequence=""
58+
do %code.WriteLine(" set value = inst."_property)
59+
set prompt = $$$comMemberKeyGet(%class.Name,$$$cCLASSproperty,property,$$$cPROPdescription)
60+
set promptQuoted = $$$QUOTE(prompt_":")
61+
set promptQuoted = $Replace(promptQuoted,"${username}","'""_$Username_""'")
62+
do %code.WriteLine(" set response = ##class(%Library.Prompt).GetString("_promptQuoted_",.value,,,,"_defaultPromptFlag_")")
63+
do %code.WriteLine(" if response '= $$$SuccessResponse { quit 0 }")
64+
do %code.WriteLine(" set inst."_property_" = value")
65+
}
66+
do %code.WriteLine(" $$$ThrowOnError(inst.%Save())")
67+
do %code.WriteLine(" write !,""Settings saved.""")
68+
do %code.WriteLine(" quit 1")
69+
}
70+
71+
}
72+

0 commit comments

Comments
 (0)