Skip to content
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

Popping from stash #653

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.8.1] - Unreleased

### Fixed
- Fixed merge conflict resolution on stash popping (#531)

## [2.8.0] - 2024-12-06

### Added
Expand Down
32 changes: 32 additions & 0 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3043,4 +3043,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")
}

}
58 changes: 41 additions & 17 deletions cls/SourceControl/Git/WebUIDriver.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions git-webui/release/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1895,8 +1895,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()
});
}

Expand All @@ -1905,10 +1907,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()
});
}

Expand All @@ -1917,7 +1919,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();
Expand Down
10 changes: 6 additions & 4 deletions git-webui/src/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1895,8 +1895,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()
});
}

Expand All @@ -1905,10 +1907,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()
});
}

Expand All @@ -1917,7 +1919,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();
Expand Down
Loading