Skip to content

Commit 3ce71a0

Browse files
authored
Merge pull request #355 from intersystems/basic-export-modes
Issue #349 added basic and expert modes to the application
2 parents 33ed837 + c12ef63 commit 3ce71a0

File tree

7 files changed

+359
-51
lines changed

7 files changed

+359
-51
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Pre-release support for IPM v0.9.0+
1313
- Items mapped from database other than namespace's default routine database are now ignored by default when exporting or adding files
1414
- New setting to configure whether mapped items should be should be treated as read-only
15+
- Added a basic mode to automatically perform functionality expected in basic use cases (#349)
16+
- New sync operation for basic mode that fetches, pulls, commits and then pushes (#349)
1517
- Now skips files belonging to other git enabled packages in `##class(SourceControl.Git.Change).RefreshUncommitted()` (#347)
1618
- Added a new "Branch" parameter to `##class(SourceControl.Git.PullEventHandler)` (#351)
1719
- Command-line utility to do a baseline export of items in a namespace

cls/SourceControl/Git/Extension.cls

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ XData Menu
2020
<MenuItem Name="Revert" />
2121
<MenuItem Name="Commit" />
2222
<MenuItem Separator="true"/>
23+
<MenuItem Name="Sync" />
2324
<MenuItem Name="Push" />
2425
<MenuItem Name="Fetch" />
2526
<MenuItem Name="Pull" />
@@ -49,15 +50,20 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
4950
set Name = "%SourceMenu,Status"
5051
}
5152

53+
if (Type = 1) && ((Name = 1) || (Name = 7)) {
54+
do ..AddToSourceControl(InternalName)
55+
}
56+
57+
5258
#dim ec as %Status = $$$OK
5359
#dim menu as %Status = $piece(Name, ",", 1)
5460
if menu '= "%SourceMenu", menu'="%SourceContext" {
5561
quit $$$OK
5662
}
5763

58-
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
64+
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
5965
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
60-
set ec = ##class(Utils).UserAction(InternalName, Name, .Target, .Action, .Reload)
66+
set ec = ##class(SourceControl.Git.Utils).UserAction(InternalName, Name, .Target, .Action, .Reload, .Msg)
6167
quit ec
6268
}
6369

@@ -68,9 +74,9 @@ Method AfterUserAction(Type As %Integer, Name As %String, InternalName As %Strin
6874
if menu '= "%SourceMenu", menu'="%SourceContext" {
6975
quit $$$OK
7076
}
71-
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
77+
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
7278
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
73-
set ec = ##class(Utils).AfterUserAction(Type, Name, InternalName, .Answer, .Msg, .Reload)
79+
set ec = ##class(SourceControl.Git.Utils).AfterUserAction(Type, Name, InternalName, .Answer, .Msg, .Reload)
7480
quit ec
7581
}
7682

@@ -90,6 +96,7 @@ Method LocalizeName(name As %String) As %String
9096
"SwitchBranch":$$$Text("@SwitchBranch@Check out an existing branch"),
9197
"Revert":$$$Text("@Revert@Discard changes to file"),
9298
"Commit":$$$Text("@Commit@Commit changes to file"),
99+
"Sync":$$$Text("@Sync@Sync"),
93100
"Push":$$$Text("@Push@Push to remote branch"),
94101
"Fetch":$$$Text("@Fetch@Fetch from remote"),
95102
"Pull":$$$Text("@Pull@Pull changes from remote branch"),
@@ -99,36 +106,52 @@ Method LocalizeName(name As %String) As %String
99106

100107
Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef DisplayName As %String, InternalName As %String) As %Status
101108
{
109+
102110
if name = "Settings" {
103111
set Enabled = 1
104112
quit $$$OK
105113
}
106-
if ##class(Utils).NeedSettings() {
114+
if ##class(SourceControl.Git.Utils).NeedSettings() {
107115
set Enabled = -1
108116
quit $$$OK
109117
}
110-
if ##class(Utils).IsNamespaceInGit() {
111-
if $listfind($listbuild("AddToSC", "RemoveFromSC", "Revert", "Commit"), name) {
112-
quit ..OnSourceMenuContextItem(InternalName,name,.Enabled,.DisplayName)
113-
}
114-
set Enabled = $CASE(name,
115-
// cases
116-
"Status": 1,
117-
"GitWebUI" : 1,
118-
"Export": 1,
119-
"ExportForce": 1,
120-
"Import": 1,
121-
"ImportForce": 1,
122-
"NewBranch": 1,
123-
"SwitchBranch": 1,
124-
"Push": 1,
125-
"Fetch": 1,
126-
"Pull": 1,
127-
"": 1,
128-
:-1 // default
129-
)
118+
if ##class(SourceControl.Git.Utils).IsNamespaceInGit() {
119+
120+
if $listfind($listbuild("AddToSC", "RemoveFromSC", "Revert", "Commit"), name) {
121+
quit ..OnSourceMenuContextItem(InternalName,name,.Enabled,.DisplayName)
122+
}
123+
124+
if ##class(SourceControl.Git.Utils).BasicMode() {
125+
set Enabled = $CASE(name,
126+
"Status": 1,
127+
"GitWebUI" : 1,
128+
"Sync": 1,
129+
"": 1,
130+
:-1
131+
132+
)
133+
} else {
134+
set Enabled = $CASE(name,
135+
// cases
136+
"Status": 1,
137+
"GitWebUI" : 1,
138+
"Export": 1,
139+
"ExportForce": 1,
140+
"Import": 1,
141+
"ImportForce": 1,
142+
"NewBranch": 1,
143+
"SwitchBranch": 1,
144+
"Push": 1,
145+
"Fetch": 1,
146+
"Pull": 1,
147+
"Sync": -1,
148+
"": 1,
149+
:-1 // default
150+
)
151+
}
130152

131-
} elseif ##class(Utils).GitBinExists() {
153+
154+
} elseif ##class(SourceControl.Git.Utils).GitBinExists() {
132155
if name = "Init" {
133156
} else {
134157
set Enabled = -1
@@ -141,7 +164,7 @@ Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef Display
141164

142165
Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByRef Enabled As %String, ByRef DisplayName As %String) As %Status
143166
{
144-
if (itemName = "") || '##class(Utils).IsNamespaceInGit() {
167+
if (itemName = "") || '##class(SourceControl.Git.Utils).IsNamespaceInGit() {
145168
set Enabled = -1
146169
} elseif (($find(itemName,",") > 0) || (##class(SourceControl.Git.Utils).Type(itemName) = "pkg")) {
147170
//if more than one item is selected, we can only add/remove, no diff or blame
@@ -150,16 +173,16 @@ Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByR
150173
} elseif menuItemName = "Revert" {
151174
set Enabled = 1
152175
do ..GetStatus(.itemName, .isInSourceControl, .isEditable,.isCheckedOut,.userCheckedOut)
153-
if '(##class(Change).IsUncommitted(##class(Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
176+
if '(##class(SourceControl.Git.Change).IsUncommitted(##class(SourceControl.Git.Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
154177
set Enabled = 0
155178
}
156179
} elseif menuItemName = "Commit" {
157180
set Enabled = 1
158181
do ..GetStatus(.itemName, .isInSourceControl, .isEditable,.isCheckedOut,.userCheckedOut)
159-
if '(##class(Change).IsUncommitted(##class(Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
182+
if '(##class(SourceControl.Git.Change).IsUncommitted(##class(SourceControl.Git.Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
160183
set Enabled = 0
161184
}
162-
} elseif ##class(Utils).IsInSourceControl(itemName) {
185+
} elseif ##class(SourceControl.Git.Utils).IsInSourceControl(itemName) {
163186
set Enabled = $case(menuItemName, "AddToSC":-1,:1)
164187
} else {
165188
set Enabled = $case(menuItemName, "AddToSC":1,:-1)
@@ -174,7 +197,7 @@ Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByR
174197
/// this menu item from the list totally, 0 will gray the menu item out and the default 1 will display the menu item as normal.
175198
Method OnMenuItem(MenuName As %String, InternalName As %String, SelectedText As %String, ByRef Enabled As %Boolean, ByRef DisplayName As %String) As %Status
176199
{
177-
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
200+
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
178201
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
179202

180203
#dim menu as %String= $piece(MenuName,",")
@@ -200,9 +223,9 @@ Method OnMenuItem(MenuName As %String, InternalName As %String, SelectedText As
200223
Method OnBeforeLoad(InternalName As %String, verbose As %Boolean) As %Status
201224
{
202225
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
203-
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
204-
if ##class(Utils).IsInSourceControl(InternalName) {
205-
quit ##class(Utils).ImportItem(InternalName,,0)
226+
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
227+
if ##class(SourceControl.Git.Utils).IsInSourceControl(InternalName) {
228+
quit ##class(SourceControl.Git.Utils).ImportItem(InternalName,,0)
206229
}
207230
quit $$$OK
208231
}
@@ -236,12 +259,12 @@ Method OnAfterSave(InternalName As %String, Object As %RegisteredObject = {$$$NU
236259
{
237260
set sc = $$$OK
238261
try {
239-
set InternalName = ##class(Utils).NormalizeInternalName(.InternalName)
262+
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(.InternalName)
240263
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
241-
if ##class(Utils).IsNamespaceInGit() && ..IsInSourceControl(InternalName) {
242-
set filename = ##class(Utils).FullExternalName(InternalName)
243-
$$$ThrowOnError(##class(Utils).RemoveRoutineTSH(InternalName))
244-
$$$ThrowOnError(##class(Utils).ExportItem(InternalName))
264+
if ##class(SourceControl.Git.Utils).IsNamespaceInGit() && ..IsInSourceControl(InternalName) {
265+
set filename = ##class(SourceControl.Git.Utils).FullExternalName(InternalName)
266+
$$$ThrowOnError(##class(SourceControl.Git.Utils).RemoveRoutineTSH(InternalName))
267+
$$$ThrowOnError(##class(SourceControl.Git.Utils).ExportItem(InternalName))
245268
if '##class(SourceControl.Git.Change).IsUncommitted(filename) {
246269
$$$ThrowOnError(##class(SourceControl.Git.Change).SetUncommitted(filename, "edit", InternalName, $username, "", 1, "", "", 0))
247270
}
@@ -262,7 +285,7 @@ Method OnAfterCompile(InternalName As %String) As %Status
262285
/// Returns true if this item is in source control and false otherwise.
263286
Method IsInSourceControl(InternalName As %String) As %Boolean [ CodeMode = expression ]
264287
{
265-
InternalName'="" && ##class(Utils).IsInSourceControl(##class(Utils).NormalizeInternalName(InternalName))
288+
InternalName'="" && ##class(SourceControl.Git.Utils).IsInSourceControl(##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName))
266289
}
267290

268291
/// Called before an item is deleted.
@@ -273,10 +296,10 @@ Method OnBeforeDelete(InternalName As %String) As %Status
273296
Throw ##class(%Exception.General).%New("Can't delete in locked environment")
274297
} else {
275298
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
276-
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
277-
set Filename = ##class(Utils).FullExternalName(InternalName)
278-
if ##class(Utils).IsInSourceControl(InternalName) && ##class(%File).Exists(Filename) {
279-
quit ##class(Change).AddDeletedToUncommitted(Filename, InternalName)
299+
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
300+
set Filename = ##class(SourceControl.Git.Utils).FullExternalName(InternalName)
301+
if ##class(SourceControl.Git.Utils).IsInSourceControl(InternalName) && ##class(%File).Exists(Filename) {
302+
quit ##class(SourceControl.Git.Change).AddDeletedToUncommitted(Filename, InternalName)
280303
}
281304
quit $$$OK
282305
}
@@ -286,9 +309,9 @@ Method OnBeforeDelete(InternalName As %String) As %Status
286309
Method OnAfterDelete(InternalName As %String) As %Status
287310
{
288311
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
289-
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
290-
if ##class(Utils).IsInSourceControl(InternalName) {
291-
quit ##class(Utils).DeleteExternalFile(InternalName)
312+
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
313+
if ##class(SourceControl.Git.Utils).IsInSourceControl(InternalName) {
314+
quit ##class(SourceControl.Git.Utils).DeleteExternalFile(InternalName)
292315
}
293316
quit $$$OK
294317
}
@@ -297,7 +320,7 @@ Method OnAfterDelete(InternalName As %String) As %Status
297320
/// the routine/class/csp item. This is often a filename to write the file out to.
298321
Method ExternalName(InternalName As %String) As %String
299322
{
300-
quit ##class(Utils).ExternalName(InternalName)
323+
quit ##class(SourceControl.Git.Utils).ExternalName(InternalName)
301324
}
302325

303326
Method IsReadOnly(InternalName As %String) As %Boolean

cls/SourceControl/Git/Settings.cls

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ Property gitUserEmail As %String(MAXLEN = 255) [ InitialExpression = {##class(So
3232
/// Attribution: Whether mapped items should be read-only, preventing them from being added to source control
3333
Property mappedItemsReadOnly As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).MappedItemsReadOnly()} ];
3434

35+
/// Whether basic mode should be enabled for user ${username}, greatly simplifying the functionality of the package, requiring no knowledge of git
36+
Property basicMode As %String [ InitialExpression = {##class(SourceControl.Git.Utils).BasicMode()} ];
37+
38+
/// A read-only setting used to display the basic mode setting that is chosen in the settings page
39+
Property userBasicMode As %String [ InitialExpression = {##class(SourceControl.Git.Utils).UserBasicMode()} ];
40+
41+
/// The system's default mode. If true, the system defaults to basic mode
42+
Property systemBasicMode As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).SystemBasicMode()} ];
43+
3544
Property Mappings [ MultiDimensional ];
3645

3746
Method %OnNew() As %Status
@@ -84,6 +93,16 @@ Method %Save() As %Status
8493
set @storage@("settings","percentClassReplace") = ..percentClassReplace
8594
set @storage@("settings","settingsUIReadOnly") = ..settingsUIReadOnly
8695
set @storage@("settings", "mappedItemsReadOnly") = ..mappedItemsReadOnly
96+
set @storage@("settings", "basicMode") = ..systemBasicMode
97+
if ..basicMode = "system" {
98+
kill @storage@("settings", "user", $username, "basicMode")
99+
} else {
100+
set @storage@("settings", "user", $username, "basicMode") = ..basicMode
101+
}
102+
103+
// update value of basicUserMode to reflect the updated setting for basicMode
104+
set ..userBasicMode = ##class(SourceControl.Git.Utils).UserBasicMode()
105+
87106

88107
kill @##class(SourceControl.Git.Utils).MappingsNode()
89108
merge @##class(SourceControl.Git.Utils).MappingsNode() = ..Mappings
@@ -106,6 +125,7 @@ ClassMethod Configure() As %Boolean [ CodeMode = objectgenerator ]
106125
for {
107126
set sequence = $order(orderedProperties(sequence),1,property)
108127
quit:sequence=""
128+
continue:property="userBasicMode"
109129
do %code.WriteLine(" set value = inst."_property)
110130
set prompt = $$$comMemberKeyGet(%class.Name,$$$cCLASSproperty,property,$$$cPROPdescription)
111131
set promptQuoted = $$$QUOTE(prompt_":")

0 commit comments

Comments
 (0)