Skip to content

Commit da6f5fa

Browse files
committed
Improved behavior for commits when attribution settings are not configured
1 parent f3fd329 commit da6f5fa

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

CHANGELOG.md

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

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

cls/SourceControl/Git/Utils.cls

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
262262
set Action = 7
263263
quit $$$OK
264264
} elseif (menuItemName = "Commit") {
265+
do ..CheckUserIdentity()
265266
set Target = "Please enter a commit message"
266267
set Action = 7
267268
quit $$$OK
@@ -350,9 +351,12 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
350351
set filename = ..FullExternalName(.InternalName)
351352
set username = ..GitUserName()
352353
set email = ..GitUserEmail()
353-
set author = username_" <"_email_">"
354+
set author = ""
355+
if ((username '= "") && (email '= "")) {
356+
set author = username_" <"_email_">"
357+
}
354358
do ..RunGitWithArgs(.errStream, .outStream, "commit", "--author", author, "-m", Message, filename)
355-
do ..PrintStreams(outStream, outStream)
359+
do ..PrintStreams(errStream, outStream)
356360
$$$QuitOnError(##class(SourceControl.Git.Change).RemoveUncommitted(filename))
357361
$$$QuitOnError(##class(SourceControl.Git.Change).RefreshUncommitted(,,,1))
358362
quit $$$OK
@@ -1659,6 +1663,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16591663
set diffCompare = ""
16601664
set invert = 0
16611665
set whichStash = ""
1666+
set isCommit = 0
16621667

16631668
// Find / build file list
16641669
set hasFileList = 0
@@ -1705,6 +1710,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
17051710
set syncIrisWithDiff = 1
17061711
set diffCompare = whichStash
17071712
}
1713+
} elseif (command = "commit") {
1714+
set isCommit = 1
17081715
}
17091716

17101717
// WebUI prefixes with "color.ui=true" so we need to grab the command
@@ -1740,6 +1747,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
17401747
} elseif (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull") {
17411748
set syncIrisWithCommand = 1
17421749
set diffCompare = args(i + 1)
1750+
} elseif (args(i) = "commit") {
1751+
set isCommit = 1
17431752
}
17441753
}
17451754
}
@@ -1783,6 +1792,15 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
17831792
set errStream = ##class(%Stream.FileCharacter).%OpenId(errLog,,.sc)
17841793
set outStream = ##class(%Stream.FileCharacter).%OpenId(outLog,,.sc)
17851794
set outStream.TranslateTable="UTF8"
1795+
1796+
if ((isCommit) && (returnCode = 128)){
1797+
set errStreamLine = errStream.ReadLine()
1798+
if (((errStreamLine = "Committer identity unknown") || (errStreamLine = "Author identity unknown"))) {
1799+
do errStream.Clear()
1800+
do errStream.WriteLine("Commit failed as user identity unknown."_$c(13,10)_$c(13,10)_"Go to settings to configure Git committer name and email."_$c(13,10))
1801+
}
1802+
}
1803+
17861804
for stream=errStream,outStream {
17871805
set stream.RemoveOnClose = 1
17881806
}
@@ -2692,4 +2710,14 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
26922710
return sc
26932711
}
26942712

2713+
ClassMethod CheckUserIdentity()
2714+
{
2715+
if ..GitUserName() = "" {
2716+
write !, "WARNING: Git committer name is not configured. Go to settings to configure the committer name."
2717+
}
2718+
if ..GitUserEmail() = "" {
2719+
write !, "WARNING: Git committer email is not configured. Go to settings to configure the committer email."
2720+
}
2721+
}
2722+
26952723
}

0 commit comments

Comments
 (0)