Skip to content

Commit fadbaab

Browse files
authored
Merge pull request #653 from intersystems/issue-531
Popping from stash
2 parents b653f15 + 64c2b9c commit fadbaab

File tree

5 files changed

+86
-25
lines changed

5 files changed

+86
-25
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
### Fixed
1414
- Fixed errors on production page when item settings need to be XML escaped (#667)
1515
- Fixed push button not appearing after commit (#654)
16+
- Fixed merge conflict resolution on stash popping (#531)
1617

1718
## [2.8.0] - 2024-12-06
1819

cls/SourceControl/Git/Utils.cls

+32
Original file line numberDiff line numberDiff line change
@@ -3045,4 +3045,36 @@ ClassMethod InDefaultBranchBasicMode() As %Boolean
30453045
quit 0
30463046
}
30473047

3048+
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
3049+
{
3050+
set succeeded = 0
3051+
set initTLevel = $TLEVEL
3052+
try {
3053+
TSTART
3054+
set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput(command,inFile,.errStream,.outStream, args...)
3055+
if (returnCode '= 0) {
3056+
$$$ThrowStatus($$$ERROR($$$GeneralError,"git reported failure"))
3057+
}
3058+
set succeeded = 1
3059+
TCOMMIT
3060+
} catch e {
3061+
write !,"Attempting to resolve differences in production definition..."
3062+
set resolver = ##class(SourceControl.Git.Util.ResolutionManager).FromLog(outStream)
3063+
if resolver.resolved {
3064+
set succeeded = 1
3065+
TCOMMIT
3066+
write " success!"
3067+
} else {
3068+
write " unable to resolve - "_resolver.errorMessage
3069+
}
3070+
}
3071+
while $TLevel > initTLevel {
3072+
TROLLBACK 1
3073+
}
3074+
if succeeded {
3075+
return $$$OK
3076+
}
3077+
return $$$ERROR($$$GeneralError,"git reported failure")
3078+
}
3079+
30483080
}

cls/SourceControl/Git/WebUIDriver.cls

+41-17
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
218218
} else {
219219
set inFile = ""
220220
}
221-
221+
// Want to invoke merge conflict autoresolver in case of issues
222222
set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c",inFile,.errStream,.outStream,gitArgs...)
223-
223+
224224
set %data = ##class(%Stream.TmpCharacter).%New()
225225
set changeTerminators = (%data.LineTerminator '= $char(13,10))
226226
set %data.LineTerminator = $char(13,10) // For the CSPGateway.
@@ -284,24 +284,48 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
284284
}
285285

286286
set inFile = ""
287+
if (gitCmd = "stash") {
288+
set st = ##class(SourceControl.Git.Utils).RunGitAndHandleMerge("-c",inFile, .resolver, .succeeded, .returnCode, .errStream, .outStream, argsArr...)
289+
290+
set %data = ##class(%Stream.TmpCharacter).%New()
291+
set changeTerminators = (%data.LineTerminator '= $char(13,10))
292+
set %data.LineTerminator = $char(13,10) // For the CSPGateway.
293+
do outStream.Rewind()
294+
295+
// Don't show merge error if merge succeeded
296+
if succeeded {
297+
do %data.WriteLine(outStream.ReadLine())
298+
do %data.WriteLine("Git-Stderr-Length: " _ 0)
299+
} else {
300+
set nLines = 0
301+
do errStream.Rewind()
302+
while 'errStream.AtEnd {
303+
do %data.WriteLine(errStream.ReadLine())
304+
set:changeTerminators nLines = nLines + 1
305+
}
306+
do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines))
307+
}
308+
do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected
309+
do %data.Rewind()
310+
} else {
311+
set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c", inFile, .errStream, .outStream, argsArr...)
312+
set %data = ##class(%Stream.TmpCharacter).%New()
313+
set changeTerminators = (%data.LineTerminator '= $char(13,10))
314+
set %data.LineTerminator = $char(13,10) // For the CSPGateway.
315+
while 'outStream.AtEnd {
316+
do %data.WriteLine(outStream.ReadLine())
317+
}
287318

288-
set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c", inFile, .errStream, .outStream, argsArr...)
289-
set %data = ##class(%Stream.TmpCharacter).%New()
290-
set changeTerminators = (%data.LineTerminator '= $char(13,10))
291-
set %data.LineTerminator = $char(13,10) // For the CSPGateway.
292-
while 'outStream.AtEnd {
293-
do %data.WriteLine(outStream.ReadLine())
294-
}
319+
set nLines = 0
320+
while 'errStream.AtEnd {
321+
do %data.WriteLine(errStream.ReadLine())
322+
set:changeTerminators nLines = nLines + 1
323+
}
295324

296-
set nLines = 0
297-
while 'errStream.AtEnd {
298-
do %data.WriteLine(errStream.ReadLine())
299-
set:changeTerminators nLines = nLines + 1
325+
do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines))
326+
do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected
327+
do %data.Rewind()
300328
}
301-
302-
do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines))
303-
do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected
304-
do %data.Rewind()
305329
set handled = 1
306330

307331
// Make sure discarded items are not in the uncommitted queue

git-webui/release/share/git-webui/webui/js/git-webui.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1900,8 +1900,10 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
19001900
return;
19011901
}
19021902
var stashIndex = parseInt($(".log-entry.active .stash-list-index").text());
1903-
webui.git("stash apply stash@{"+stashIndex+"}", function(output){
1903+
webui.git_command(["stash", "apply", "stash@{"+stashIndex+"}"], function(output) {
19041904
webui.showSuccess(output);
1905+
parent.stashView.update(0);
1906+
self.clear()
19051907
});
19061908
}
19071909

@@ -1910,10 +1912,10 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
19101912
return;
19111913
}
19121914
var stashIndex = parseInt($(".log-entry.active .stash-list-index").text());
1913-
webui.git("stash pop stash@{"+stashIndex+"}", function(output){
1915+
webui.git_command(["stash", "pop", "stash@{"+stashIndex+"}"], function(output) {
19141916
webui.showSuccess(output);
19151917
parent.stashView.update(0);
1916-
self.clear();
1918+
self.clear()
19171919
});
19181920
}
19191921

@@ -1922,7 +1924,7 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
19221924
return;
19231925
}
19241926
var stashIndex = parseInt($(".log-entry.active .stash-list-index").text());
1925-
webui.git("stash drop stash@{"+stashIndex+"}", function(output){
1927+
webui.git_command(["stash", "drop", "stash@{"+stashIndex+"}"], function() {
19261928
webui.showSuccess(output.substring(output.indexOf("Dropped")));
19271929
parent.stashView.update(0);
19281930
self.clear();

git-webui/src/share/git-webui/webui/js/git-webui.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1900,8 +1900,10 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
19001900
return;
19011901
}
19021902
var stashIndex = parseInt($(".log-entry.active .stash-list-index").text());
1903-
webui.git("stash apply stash@{"+stashIndex+"}", function(output){
1903+
webui.git_command(["stash", "apply", "stash@{"+stashIndex+"}"], function(output) {
19041904
webui.showSuccess(output);
1905+
parent.stashView.update(0);
1906+
self.clear()
19051907
});
19061908
}
19071909

@@ -1910,10 +1912,10 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
19101912
return;
19111913
}
19121914
var stashIndex = parseInt($(".log-entry.active .stash-list-index").text());
1913-
webui.git("stash pop stash@{"+stashIndex+"}", function(output){
1915+
webui.git_command(["stash", "pop", "stash@{"+stashIndex+"}"], function(output) {
19141916
webui.showSuccess(output);
19151917
parent.stashView.update(0);
1916-
self.clear();
1918+
self.clear()
19171919
});
19181920
}
19191921

@@ -1922,7 +1924,7 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
19221924
return;
19231925
}
19241926
var stashIndex = parseInt($(".log-entry.active .stash-list-index").text());
1925-
webui.git("stash drop stash@{"+stashIndex+"}", function(output){
1927+
webui.git_command(["stash", "drop", "stash@{"+stashIndex+"}"], function() {
19261928
webui.showSuccess(output.substring(output.indexOf("Dropped")));
19271929
parent.stashView.update(0);
19281930
self.clear();

0 commit comments

Comments
 (0)