Skip to content

Commit b6eb0ba

Browse files
authored
Merge pull request #512 from intersystems/fix-450
Improved behavior for commits when attribution settings are not configured
2 parents 9018c6f + 21e5044 commit b6eb0ba

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Files in uncommitted queue in any namespace warn users when opened except for in VSCode (#370)
1313
- Added link back to IRIS management portal from Settings, Git WebUI pages (#449)
1414
- Added Import all and Import All (Force) to basic mode menu (#498)
15+
- Improved behavior for commits when attribution settings are not configured (#450)
1516

1617
### Fixed
1718
- Changed prompts in configure from 0/1 to no/yes (#461)

cls/SourceControl/Git/Extension.cls

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ 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-
}
52+
do ..CheckCommitterIdentity(settings, .Action, .Target)
53+
}
5354

5455
if (Type = 1) && (Name = 3) {
5556
if settings.warnInstanceWideUncommitted {
@@ -74,10 +75,17 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
7475

7576
#dim ec as %Status = $$$OK
7677
#dim menu as %Status = $piece(Name, ",", 1)
78+
#dim menuItemName as %String = $piece(Name,",",2)
7779
if menu '= "%SourceMenu", menu'="%SourceContext" {
7880
quit $$$OK
7981
}
8082

83+
if (menuItemName = "Commit") || (menuItemName = "Sync") {
84+
if ..CheckCommitterIdentity(settings, .Action, .Target) {
85+
quit $$$OK
86+
}
87+
}
88+
8189
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
8290
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
8391
set ec = ##class(SourceControl.Git.Utils).UserAction(InternalName, Name, .Target, .Action, .Reload, .Msg)
@@ -433,4 +441,15 @@ Method AddToSourceControl(InternalName As %String, Description As %String = "")
433441
Quit ##class(SourceControl.Git.Utils).AddToSourceControl(InternalName)
434442
}
435443

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+
436455
}

cls/SourceControl/Git/Utils.cls

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,12 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
351351
set filename = ..FullExternalName(.InternalName)
352352
set username = ..GitUserName()
353353
set email = ..GitUserEmail()
354-
set author = username_" <"_email_">"
354+
set author = ""
355+
if ((username '= "") && (email '= "")) {
356+
set author = username_" <"_email_">"
357+
}
355358
do ..RunGitWithArgs(.errStream, .outStream, "commit", "--author", author, "-m", Message, filename)
356-
do ..PrintStreams(outStream, outStream)
359+
do ..PrintStreams(errStream, outStream)
357360
$$$QuitOnError(##class(SourceControl.Git.Change).RemoveUncommitted(filename))
358361
$$$QuitOnError(##class(SourceControl.Git.Change).RefreshUncommitted(,,,1))
359362
quit $$$OK
@@ -397,7 +400,10 @@ ClassMethod SyncCommit(Msg As %String) As %Status
397400
set uncommittedFilesWithAction = ##class(SourceControl.Git.Utils).UncommittedWithAction().%Get("user")
398401
set username = ..GitUserName()
399402
set email = ..GitUserEmail()
400-
set author = username_" <"_email_">"
403+
set author = ""
404+
if ((username '= "") && (email '= "")) {
405+
set author = username_" <"_email_">"
406+
}
401407
do ..RunGitWithArgs(.errStream, .outStream, "commit", "--author", author, "-m", Msg)
402408
do ..PrintStreams(errStream, outStream)
403409
$$$QuitOnError(..ClearUncommitted(uncommittedFilesWithAction))
@@ -1672,8 +1678,13 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16721678
set newArgs($increment(newArgs)) = "core.sshCommand=ssh -F /dev/null -o StrictHostKeyChecking=accept-new -i "_privateKeyFile
16731679
}
16741680

1675-
set username = ..GitUserName()
1676-
set email = ..GitUserEmail()
1681+
set username = ""
1682+
set email = ""
1683+
1684+
if (..GitUserName() '= "") && (..GitUserEmail() '= "") {
1685+
set username = ..GitUserName()
1686+
set email = ..GitUserEmail()
1687+
}
16771688

16781689
set newArgs($increment(newArgs)) = "-c"
16791690
set newArgs($increment(newArgs)) = "user.name="_username
@@ -1689,6 +1700,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16891700
set diffCompare = ""
16901701
set invert = 0
16911702
set whichStash = ""
1703+
set isCommit = 0
16921704

16931705
// Find / build file list
16941706
set hasFileList = 0
@@ -1735,6 +1747,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
17351747
set syncIrisWithDiff = 1
17361748
set diffCompare = whichStash
17371749
}
1750+
} elseif (command = "commit") {
1751+
set isCommit = 1
17381752
}
17391753

17401754
// WebUI prefixes with "color.ui=true" so we need to grab the command
@@ -1770,6 +1784,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
17701784
} elseif (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull") {
17711785
set syncIrisWithCommand = 1
17721786
set diffCompare = args(i + 1)
1787+
} elseif (args(i) = "commit") {
1788+
set isCommit = 1
17731789
}
17741790
}
17751791
}
@@ -1813,6 +1829,15 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
18131829
set errStream = ##class(%Stream.FileCharacter).%OpenId(errLog,,.sc)
18141830
set outStream = ##class(%Stream.FileCharacter).%OpenId(outLog,,.sc)
18151831
set outStream.TranslateTable="UTF8"
1832+
1833+
if ((isCommit) && (returnCode = 128)){
1834+
set errStreamLine = errStream.ReadLine()
1835+
if (((errStreamLine = "Committer identity unknown") || (errStreamLine = "Author identity unknown"))) {
1836+
do errStream.Clear()
1837+
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))
1838+
}
1839+
}
1840+
18161841
for stream=errStream,outStream {
18171842
set stream.RemoveOnClose = 1
18181843
}

0 commit comments

Comments
 (0)