Skip to content

Commit 6394841

Browse files
committed
Support locking/unlocking environment
General tidying of code in preparation for upcoming review
1 parent 5093dff commit 6394841

File tree

3 files changed

+66
-46
lines changed

3 files changed

+66
-46
lines changed

cls/SourceControl/Git/API.cls

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Class SourceControl.Git.API
22
{
33

4+
/// Configures settings for Git integration
45
ClassMethod Configure()
56
{
67
set sc = $$$OK
@@ -32,5 +33,19 @@ ClassMethod Configure()
3233
}
3334
}
3435

36+
/// Locks the environment to prevent changes to code other than through git pull.
37+
/// Returns 1 if the environment was already locked, 0 if it was previously unlocked.
38+
ClassMethod Lock()
39+
{
40+
quit ##class(SourceControl.Git.Utils).Locked(1)
41+
}
42+
43+
/// Unlocks the environment to allow changes through the IDE.
44+
/// Returns 1 if the environment was already locked, 0 if it was previously unlocked.
45+
ClassMethod Unlock()
46+
{
47+
quit ##class(SourceControl.Git.Utils).Locked(0)
48+
}
49+
3550
}
3651

cls/SourceControl/Git/Extension.cls

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,21 @@ Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef Display
9393
if '(##class(Change).IsUncommitted(##class(Utils).FullExternalName(InternalName))) || ($username '= userCheckedOut) {
9494
set Enabled = 0
9595
}
96-
}elseif name = "%Push" {
96+
} elseif name = "%Push" {
9797
// TODO: Only display if there are no files checked out by other users
9898
set Enabled = 1
9999
set DisplayName = "Push"
100-
}elseif name = "%Fetch" {
100+
} elseif name = "%Fetch" {
101101
set Enabled = 1
102102
set DisplayName = "Fetch"
103-
}elseif name = "%Pull" {
103+
} elseif name = "%Pull" {
104104
set Enabled = 1
105105
set DisplayName = "Pull"
106-
}elseif ##class(Utils).IsMenuGitCommand(name) && ##class(Utils).GitBinExists() {
106+
} elseif ##class(Utils).IsMenuGitCommand(name) && ##class(Utils).GitBinExists() {
107107
set DisplayName = $case(name,"%StashSave":"Stash save",
108108
"%StashPop":"Stash pop",
109109
:$Extract(name, 2, *))
110-
}
111-
else {
110+
} else {
112111
set Enabled = -1
113112
}
114113
} elseif ##class(Utils).GitBinExists() {
@@ -132,9 +131,9 @@ Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByR
132131

133132
if (itemName = "") || '##class(Utils).IsNamespaceInGit() {
134133
set Enabled = -1
135-
}elseif $F(itemName,",") > 0 { //if more than one item is selected, we can only add/remove, no diff or blame
134+
} elseif $F(itemName,",") > 0 { //if more than one item is selected, we can only add/remove, no diff or blame
136135
set Enabled = $case(menuItemName,"%AddToSC":1,"%RemoveFromSC":1,:-1)
137-
}elseif ##class(Utils).IsInSourceControl(##class(Utils).NormalizeInternalName(itemName)) {
136+
} elseif ##class(Utils).IsInSourceControl(##class(Utils).NormalizeInternalName(itemName)) {
138137
set Enabled = $Case(menuItemName, "%AddToSC":-1,:1)
139138
} else {
140139
set Enabled = $Case(menuItemName, "%AddToSC":1,:-1)
@@ -161,10 +160,10 @@ Method OnMenuItem(MenuName As %String, InternalName As %String, SelectedText As
161160

162161
if menu = "%SourceMenu" {
163162
set ec = ..OnSourceMenuItem(name, .Enabled, .DisplayName, InternalName)
164-
}elseif menu = "%SourceContext" {
163+
} elseif menu = "%SourceContext" {
165164
set ec = ..OnSourceMenuContextItem(InternalName, name, .Enabled, .DisplayName)
166165
}
167-
Quit ec
166+
quit ec
168167
}
169168

170169
/// This is called before the actual load of data to give the chance
@@ -205,7 +204,7 @@ Method OnAfterSave(InternalName As %String, Object As %RegisteredObject = {$$$NU
205204
/// Called after the compile of the item is done.
206205
Method OnAfterCompile(InternalName As %String) As %Status
207206
{
208-
Quit ..OnAfterSave(InternalName)
207+
quit ..OnAfterSave(InternalName)
209208
}
210209

211210
/// Returns true if this item is in source control and false otherwise.
@@ -228,7 +227,12 @@ Method OnAfterDelete(InternalName As %String) As %Status
228227
/// the routine/class/csp item. This is often a filename to write the file out to.
229228
Method ExternalName(InternalName As %String) As %String
230229
{
231-
Quit ##class(Utils).Name(InternalName)
230+
quit ##class(Utils).Name(InternalName)
231+
}
232+
233+
Method IsReadOnly(InternalName As %String) As %Boolean
234+
{
235+
quit ##class(SourceControl.Git.Utils).Locked()
232236
}
233237

234238
/// Check the status of the given item
@@ -237,42 +241,41 @@ Method ExternalName(InternalName As %String) As %String
237241
Method GetStatus(InternalName As %String, ByRef IsInSourceControl As %Boolean, ByRef Editable As %Boolean, ByRef IsCheckedOut As %Boolean, ByRef UserCheckedOut As %String) As %Status
238242
{
239243
#; Quit ##super(InternalName,.IsInSourceControl,.Editable,.IsCheckedOut,.UserCheckedOut)
240-
Set Editable=1,IsCheckedOut=1,UserCheckedOut=""
241-
Set filename=##class(SourceControl.Git.Utils).FullExternalName(InternalName)
242-
Set IsInSourceControl=(filename'=""&&($$$FileExists(filename)))
243-
If filename="" Quit $$$OK
244-
If InternalName="" Quit $$$OK
245-
#; If the file does not exist then it must be a new item so it is editable.
246-
If '$$$FileExists(filename) {
247-
Set IsCheckedOut=0
248-
}
249-
do ##class(Utils).GitStatus(.files)
250-
if $Get(files(InternalName)) '= "" {
251-
///it's in source control, checked out, and should be locked to editing by other users
252-
///find out who has it edited
253-
set IsCheckedOut=1
254-
Set sc=##class(SourceControl.Git.Change).GetUncommitted(filename,.tAction,.tInternalName,.UncommittedUser,.tSource,.UncommittedLastUpdated)
255-
If $$$ISOK(sc) {
256-
if ($D(tAction)&&(UncommittedUser'=$USERNAME)){
257-
Set msg="NOTICE: "_InternalName_" is currently checked out by user '"_UncommittedUser_"', and was last updated at "_UncommittedLastUpdated
258-
Write !,msg
259-
Set Editable=0
260-
Set IsInSourceControl=0 ;set this to 0 to prevent user from being prompted to Check Out file
261-
}
262-
Set UserCheckedOut=UncommittedUser
263-
}
264-
}
265-
// If it doesn't show up in git status, there are no uncommitted changes so it should not be locked or checked out by any user
266-
else {
267-
set Editable=1, IsCheckedOut=0, UserCheckedOut=""
268-
if ##class(SourceControl.Git.Change).IsUncommitted(filename){
269-
#; Remove the item from the list of uncommitted changes;
270-
Set sc=##class(SourceControl.Git.Change).RemoveUncommitted(filename,1,1)
271-
If $$$ISERR(sc) Write "Error removing uncommitted file "_filename_" - "_$System.OBJ.DisplayError(sc)
244+
set Editable='..IsReadOnly(),IsCheckedOut=1,UserCheckedOut=""
245+
set filename=##class(SourceControl.Git.Utils).FullExternalName(InternalName)
246+
set IsInSourceControl=(filename'=""&&($$$FileExists(filename)))
247+
if filename="" Quit $$$OK
248+
if InternalName="" Quit $$$OK
249+
#; If the file does not exist then it must be a new item so it is editable.
250+
if '$$$FileExists(filename) {
251+
set IsCheckedOut=0
252+
}
253+
do ##class(Utils).GitStatus(.files)
254+
if $Get(files(InternalName)) '= "" {
255+
///it's in source control, checked out, and should be locked to editing by other users
256+
///find out who has it edited
257+
set IsCheckedOut=1
258+
set sc=##class(SourceControl.Git.Change).GetUncommitted(filename,.tAction,.tInternalName,.UncommittedUser,.tSource,.UncommittedLastUpdated)
259+
if $$$ISOK(sc) {
260+
if ($D(tAction)&&(UncommittedUser'=$USERNAME)){
261+
set msg="NOTICE: "_InternalName_" is currently checked out by user '"_UncommittedUser_"', and was last updated at "_UncommittedLastUpdated
262+
write !,msg
263+
set Editable=0
264+
set IsInSourceControl=0 ;set this to 0 to prevent user from being prompted to Check Out file
272265
}
266+
set UserCheckedOut=UncommittedUser
267+
}
268+
} else {
269+
// If it doesn't show up in git status, there are no uncommitted changes so it should not be locked or checked out by any user
270+
set Editable=1, IsCheckedOut=0, UserCheckedOut=""
271+
if ##class(SourceControl.Git.Change).IsUncommitted(filename){
272+
#; Remove the item from the list of uncommitted changes;
273+
set sc=##class(SourceControl.Git.Change).RemoveUncommitted(filename,1,1)
274+
if $$$ISERR(sc) Write "Error removing uncommitted file "_filename_" - "_$System.OBJ.DisplayError(sc)
273275
}
274-
275-
Quit $$$OK
276+
}
277+
278+
quit $$$OK
276279
}
277280

278281
}

module.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<FileCopy Name="csp/gitprojectsettings.csp" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/gitprojectsettings.csp" />
2121
<FileCopy Name="csp/webuidriver.csp" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/webuidriver.csp" />
2222
<FileCopy Name="git-webui/release/share/git-webui/webui/" Target="${libdir}../devuser/studio/templates/gitsourcecontrol/" Overlay="1" />
23+
24+
<Invoke Class="SourceControl.Git.Utils" Method="OutputConfigureMessage" />
2325
</Module>
2426
</Document>
2527
</Export>

0 commit comments

Comments
 (0)