Skip to content

Improved behavior for commits when attribution settings are not configured #512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Files in uncommitted queue in any namespace warn users when opened except for in VSCode (#370)
- Added link back to IRIS management portal from Settings, Git WebUI pages (#449)
- Added Import all and Import All (Force) to basic mode menu (#498)
- Improved behavior for commits when attribution settings are not configured (#450)

### Fixed
- Changed prompts in configure from 0/1 to no/yes (#461)
Expand Down
21 changes: 20 additions & 1 deletion cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
if Type = 1, Name = 5 {
// reroute to Status menu option
set Name = "%SourceMenu,Status"
}
do ..CheckCommitterIdentity(settings, .Action, .Target)
}

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

#dim ec as %Status = $$$OK
#dim menu as %Status = $piece(Name, ",", 1)
#dim menuItemName as %String = $piece(Name,",",2)
if menu '= "%SourceMenu", menu'="%SourceContext" {
quit $$$OK
}

if (menuItemName = "Commit") || (menuItemName = "Sync") {
if ..CheckCommitterIdentity(settings, .Action, .Target) {
quit $$$OK
}
}

set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
set ec = ##class(SourceControl.Git.Utils).UserAction(InternalName, Name, .Target, .Action, .Reload, .Msg)
Expand Down Expand Up @@ -433,4 +441,15 @@ Method AddToSourceControl(InternalName As %String, Description As %String = "")
Quit ##class(SourceControl.Git.Utils).AddToSourceControl(InternalName)
}

/// Called to check if committer identity is configured.
Method CheckCommitterIdentity(Settings As SourceControl.Git.Settings, ByRef Action As %String, ByRef Target As %String) As %Boolean
{
if ((Settings.gitUserName = "") || (Settings.gitUserEmail = "")) {
set Target = "Git committer name or email is not configured. Go to the Settings page in the Source Control menu to fix this."
set Action = 6
return 1
}
return 0
}

}
35 changes: 30 additions & 5 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,12 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
set filename = ..FullExternalName(.InternalName)
set username = ..GitUserName()
set email = ..GitUserEmail()
set author = username_" <"_email_">"
set author = ""
if ((username '= "") && (email '= "")) {
set author = username_" <"_email_">"
}
do ..RunGitWithArgs(.errStream, .outStream, "commit", "--author", author, "-m", Message, filename)
do ..PrintStreams(outStream, outStream)
do ..PrintStreams(errStream, outStream)
$$$QuitOnError(##class(SourceControl.Git.Change).RemoveUncommitted(filename))
$$$QuitOnError(##class(SourceControl.Git.Change).RefreshUncommitted(,,,1))
quit $$$OK
Expand Down Expand Up @@ -397,7 +400,10 @@ ClassMethod SyncCommit(Msg As %String) As %Status
set uncommittedFilesWithAction = ##class(SourceControl.Git.Utils).UncommittedWithAction().%Get("user")
set username = ..GitUserName()
set email = ..GitUserEmail()
set author = username_" <"_email_">"
set author = ""
if ((username '= "") && (email '= "")) {
set author = username_" <"_email_">"
}
do ..RunGitWithArgs(.errStream, .outStream, "commit", "--author", author, "-m", Msg)
do ..PrintStreams(errStream, outStream)
$$$QuitOnError(..ClearUncommitted(uncommittedFilesWithAction))
Expand Down Expand Up @@ -1643,8 +1649,13 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
set newArgs($increment(newArgs)) = "core.sshCommand=ssh -F /dev/null -o StrictHostKeyChecking=accept-new -i "_privateKeyFile
}

set username = ..GitUserName()
set email = ..GitUserEmail()
set username = ""
set email = ""

if (..GitUserName() '= "") && (..GitUserEmail() '= "") {
set username = ..GitUserName()
set email = ..GitUserEmail()
}

set newArgs($increment(newArgs)) = "-c"
set newArgs($increment(newArgs)) = "user.name="_username
Expand All @@ -1660,6 +1671,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
set diffCompare = ""
set invert = 0
set whichStash = ""
set isCommit = 0

// Find / build file list
set hasFileList = 0
Expand Down Expand Up @@ -1706,6 +1718,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
set syncIrisWithDiff = 1
set diffCompare = whichStash
}
} elseif (command = "commit") {
set isCommit = 1
}

// WebUI prefixes with "color.ui=true" so we need to grab the command
Expand Down Expand Up @@ -1741,6 +1755,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
} elseif (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull") {
set syncIrisWithCommand = 1
set diffCompare = args(i + 1)
} elseif (args(i) = "commit") {
set isCommit = 1
}
}
}
Expand Down Expand Up @@ -1784,6 +1800,15 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
set errStream = ##class(%Stream.FileCharacter).%OpenId(errLog,,.sc)
set outStream = ##class(%Stream.FileCharacter).%OpenId(outLog,,.sc)
set outStream.TranslateTable="UTF8"

if ((isCommit) && (returnCode = 128)){
set errStreamLine = errStream.ReadLine()
if (((errStreamLine = "Committer identity unknown") || (errStreamLine = "Author identity unknown"))) {
do errStream.Clear()
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))
}
}

for stream=errStream,outStream {
set stream.RemoveOnClose = 1
}
Expand Down
Loading