Skip to content

Commit 21e5044

Browse files
committed
Added attribution check for commit and sync menu items
1 parent e7ade4f commit 21e5044

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

cls/SourceControl/Git/Extension.cls

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
4949
if Type = 1, Name = 5 {
5050
// reroute to Status menu option
5151
set Name = "%SourceMenu,Status"
52-
if (settings.gitUserName = "") || (settings.gitUserEmail = "") {
53-
set Target = "Warning: Git committer name or email is not configured. Go to settings."
54-
set Action = 6
55-
}
52+
do ..CheckCommitterIdentity(settings, .Action, .Target)
5653
}
5754

5855
if (Type = 1) && (Name = 3) {
@@ -78,10 +75,17 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
7875

7976
#dim ec as %Status = $$$OK
8077
#dim menu as %Status = $piece(Name, ",", 1)
78+
#dim menuItemName as %String = $piece(Name,",",2)
8179
if menu '= "%SourceMenu", menu'="%SourceContext" {
8280
quit $$$OK
8381
}
8482

83+
if (menuItemName = "Commit") || (menuItemName = "Sync") {
84+
if ..CheckCommitterIdentity(settings, .Action, .Target) {
85+
quit $$$OK
86+
}
87+
}
88+
8589
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
8690
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
8791
set ec = ##class(SourceControl.Git.Utils).UserAction(InternalName, Name, .Target, .Action, .Reload, .Msg)
@@ -437,4 +441,15 @@ Method AddToSourceControl(InternalName As %String, Description As %String = "")
437441
Quit ##class(SourceControl.Git.Utils).AddToSourceControl(InternalName)
438442
}
439443

444+
/// Called to check if committer identity is configured.
445+
Method CheckCommitterIdentity(Settings As SourceControl.Git.Settings, ByRef Action As %String, ByRef Target As %String) As %Boolean
446+
{
447+
if ((Settings.gitUserName = "") || (Settings.gitUserEmail = "")) {
448+
set Target = "Git committer name or email is not configured. Go to the Settings page in the Source Control menu to fix this."
449+
set Action = 6
450+
return 1
451+
}
452+
return 0
453+
}
454+
440455
}

cls/SourceControl/Git/Utils.cls

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,8 +1649,13 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16491649
set newArgs($increment(newArgs)) = "core.sshCommand=ssh -F /dev/null -o StrictHostKeyChecking=accept-new -i "_privateKeyFile
16501650
}
16511651

1652-
set username = ..GitUserName()
1653-
set email = ..GitUserEmail()
1652+
set username = ""
1653+
set email = ""
1654+
1655+
if (..GitUserName() '= "") && (..GitUserEmail() '= "") {
1656+
set username = ..GitUserName()
1657+
set email = ..GitUserEmail()
1658+
}
16541659

16551660
set newArgs($increment(newArgs)) = "-c"
16561661
set newArgs($increment(newArgs)) = "user.name="_username
@@ -1800,7 +1805,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
18001805
set errStreamLine = errStream.ReadLine()
18011806
if (((errStreamLine = "Committer identity unknown") || (errStreamLine = "Author identity unknown"))) {
18021807
do errStream.Clear()
1803-
do errStream.WriteLine("Commit failed as user identity unknown."_$c(13,10)_$c(13,10)_"Go to settings."_$c(13,10))
1808+
do errStream.WriteLine("Commit failed as user identity unknown."_$c(13,10)_$c(13,10)_"Go to the Settings page in the Source Control menu to fix this."_$c(13,10))
18041809
}
18051810
}
18061811

0 commit comments

Comments
 (0)