diff --git a/CHANGELOG.md b/CHANGELOG.md index c11a5e52..8a7f5dfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed errors on production page when item settings need to be XML escaped (#667) - Fixed push button not appearing after commit (#654) +- Fixed merge conflict resolution on stash popping (#531) ## [2.8.0] - 2024-12-06 diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index e34a265f..f8d751b7 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -3045,4 +3045,36 @@ ClassMethod InDefaultBranchBasicMode() As %Boolean quit 0 } +ClassMethod RunGitAndHandleMerge(command As %String, inFile As %String, Output resolver As SourceControl.Git.Util.ProductionConflictResolver, Output succeeded As %Boolean, Output returnCode As %String, Output errStream, Output outStream, args...) As %Status +{ + set succeeded = 0 + set initTLevel = $TLEVEL + try { + TSTART + set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput(command,inFile,.errStream,.outStream, args...) + if (returnCode '= 0) { + $$$ThrowStatus($$$ERROR($$$GeneralError,"git reported failure")) + } + set succeeded = 1 + TCOMMIT + } catch e { + write !,"Attempting to resolve differences in production definition..." + set resolver = ##class(SourceControl.Git.Util.ResolutionManager).FromLog(outStream) + if resolver.resolved { + set succeeded = 1 + TCOMMIT + write " success!" + } else { + write " unable to resolve - "_resolver.errorMessage + } + } + while $TLevel > initTLevel { + TROLLBACK 1 + } + if succeeded { + return $$$OK + } + return $$$ERROR($$$GeneralError,"git reported failure") +} + } diff --git a/cls/SourceControl/Git/WebUIDriver.cls b/cls/SourceControl/Git/WebUIDriver.cls index fe91feb8..d8c1d3ff 100644 --- a/cls/SourceControl/Git/WebUIDriver.cls +++ b/cls/SourceControl/Git/WebUIDriver.cls @@ -218,9 +218,9 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out } else { set inFile = "" } - + // Want to invoke merge conflict autoresolver in case of issues set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c",inFile,.errStream,.outStream,gitArgs...) - + set %data = ##class(%Stream.TmpCharacter).%New() set changeTerminators = (%data.LineTerminator '= $char(13,10)) set %data.LineTerminator = $char(13,10) // For the CSPGateway. @@ -284,24 +284,48 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out } set inFile = "" + if (gitCmd = "stash") { + set st = ##class(SourceControl.Git.Utils).RunGitAndHandleMerge("-c",inFile, .resolver, .succeeded, .returnCode, .errStream, .outStream, argsArr...) + + set %data = ##class(%Stream.TmpCharacter).%New() + set changeTerminators = (%data.LineTerminator '= $char(13,10)) + set %data.LineTerminator = $char(13,10) // For the CSPGateway. + do outStream.Rewind() + + // Don't show merge error if merge succeeded + if succeeded { + do %data.WriteLine(outStream.ReadLine()) + do %data.WriteLine("Git-Stderr-Length: " _ 0) + } else { + set nLines = 0 + do errStream.Rewind() + while 'errStream.AtEnd { + do %data.WriteLine(errStream.ReadLine()) + set:changeTerminators nLines = nLines + 1 + } + do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines)) + } + do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected + do %data.Rewind() + } else { + set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c", inFile, .errStream, .outStream, argsArr...) + set %data = ##class(%Stream.TmpCharacter).%New() + set changeTerminators = (%data.LineTerminator '= $char(13,10)) + set %data.LineTerminator = $char(13,10) // For the CSPGateway. + while 'outStream.AtEnd { + do %data.WriteLine(outStream.ReadLine()) + } - set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c", inFile, .errStream, .outStream, argsArr...) - set %data = ##class(%Stream.TmpCharacter).%New() - set changeTerminators = (%data.LineTerminator '= $char(13,10)) - set %data.LineTerminator = $char(13,10) // For the CSPGateway. - while 'outStream.AtEnd { - do %data.WriteLine(outStream.ReadLine()) - } + set nLines = 0 + while 'errStream.AtEnd { + do %data.WriteLine(errStream.ReadLine()) + set:changeTerminators nLines = nLines + 1 + } - set nLines = 0 - while 'errStream.AtEnd { - do %data.WriteLine(errStream.ReadLine()) - set:changeTerminators nLines = nLines + 1 + do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines)) + do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected + do %data.Rewind() } - - do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines)) - do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected - do %data.Rewind() set handled = 1 // Make sure discarded items are not in the uncommitted queue diff --git a/git-webui/release/share/git-webui/webui/js/git-webui.js b/git-webui/release/share/git-webui/webui/js/git-webui.js index bfc69d9c..05876cec 100644 --- a/git-webui/release/share/git-webui/webui/js/git-webui.js +++ b/git-webui/release/share/git-webui/webui/js/git-webui.js @@ -1900,8 +1900,10 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi return; } var stashIndex = parseInt($(".log-entry.active .stash-list-index").text()); - webui.git("stash apply stash@{"+stashIndex+"}", function(output){ + webui.git_command(["stash", "apply", "stash@{"+stashIndex+"}"], function(output) { webui.showSuccess(output); + parent.stashView.update(0); + self.clear() }); } @@ -1910,10 +1912,10 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi return; } var stashIndex = parseInt($(".log-entry.active .stash-list-index").text()); - webui.git("stash pop stash@{"+stashIndex+"}", function(output){ + webui.git_command(["stash", "pop", "stash@{"+stashIndex+"}"], function(output) { webui.showSuccess(output); parent.stashView.update(0); - self.clear(); + self.clear() }); } @@ -1922,7 +1924,7 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi return; } var stashIndex = parseInt($(".log-entry.active .stash-list-index").text()); - webui.git("stash drop stash@{"+stashIndex+"}", function(output){ + webui.git_command(["stash", "drop", "stash@{"+stashIndex+"}"], function() { webui.showSuccess(output.substring(output.indexOf("Dropped"))); parent.stashView.update(0); self.clear(); diff --git a/git-webui/src/share/git-webui/webui/js/git-webui.js b/git-webui/src/share/git-webui/webui/js/git-webui.js index bfc69d9c..05876cec 100644 --- a/git-webui/src/share/git-webui/webui/js/git-webui.js +++ b/git-webui/src/share/git-webui/webui/js/git-webui.js @@ -1900,8 +1900,10 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi return; } var stashIndex = parseInt($(".log-entry.active .stash-list-index").text()); - webui.git("stash apply stash@{"+stashIndex+"}", function(output){ + webui.git_command(["stash", "apply", "stash@{"+stashIndex+"}"], function(output) { webui.showSuccess(output); + parent.stashView.update(0); + self.clear() }); } @@ -1910,10 +1912,10 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi return; } var stashIndex = parseInt($(".log-entry.active .stash-list-index").text()); - webui.git("stash pop stash@{"+stashIndex+"}", function(output){ + webui.git_command(["stash", "pop", "stash@{"+stashIndex+"}"], function(output) { webui.showSuccess(output); parent.stashView.update(0); - self.clear(); + self.clear() }); } @@ -1922,7 +1924,7 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi return; } var stashIndex = parseInt($(".log-entry.active .stash-list-index").text()); - webui.git("stash drop stash@{"+stashIndex+"}", function(output){ + webui.git_command(["stash", "drop", "stash@{"+stashIndex+"}"], function() { webui.showSuccess(output.substring(output.indexOf("Dropped"))); parent.stashView.update(0); self.clear();