Skip to content

Sync IRIS with repo changes when switching to a remote branch #788

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 4 commits into from
Jun 6, 2025
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 @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changing remotes in the git project settings pages now works if remote is not already defined (#746)
- User-specific basic mode setting can now be changed when settingsUIReadOnly is set (#775)
- Fixed an error displaying the Web UI after reverting a commit (#776)
- Fixed checkout of a remote branch not syncing files with IRIS (#783)
- Fixed errors exporting items when directory casing does not match mappings (#781)
- Improved accessibility of UI when tabbing through items (#764)

Expand Down
37 changes: 26 additions & 11 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,8 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
set newArgs($increment(newArgs)) = command

set syncIrisWithDiff = 0 // whether IRIS needs to be synced with repo file changes using diff output
set syncIrisWithDiffAfterGit = 0 // whether to sync using diff output after the git command is performed
set syncIrisWithDiffVerbose = 1 // whether to use verbose output when syncing using diff output
set syncIrisWithCommand = 0 // // whether IRIS needs to be synced with repo file changes using command output
set diffBase = ""
set diffCompare = ""
Expand Down Expand Up @@ -1888,16 +1890,26 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O

if (command = "checkout") {
set syncIrisWithDiff = 1
// Sync using diff output after the checkout has been performed
// Allows syncing remote branches as the diff will otherwise fail prior
set syncIrisWithDiffAfterGit = 1
if hasFileList {
set invert = 1
} elseif $data(args) && $data(args(args),diffCompare) {
// no-op
// Record the current branch to diff against after the checkout
set diffBase = ..GetCurrentBranch()
}
} elseif (command = "restore") {
// Leave diffCompare empty, this actually does the right thing.
set syncIrisWithDiff = 1
} elseif (command = "pull") {
set syncIrisWithDiff = 1
// If performing a pull don't perform a diff until after the pull has occured.
// This is to avoid a double fetch, as pull performs one for us and also to avoid a potential
// race condition if the remote changes between now and the pull actually being performed.
set syncIrisWithDiffAfterGit = 1
// Verbose output should not be required as pull already outputs a summary
set syncIrisWithDiffVerbose = 0
// The current revision, prior to the pull, will be compared against
set diffCompare = ..GetCurrentRevision()
} elseif (command = "merge") || (command = "rebase") {
Expand Down Expand Up @@ -1927,12 +1939,18 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
set newArgs($increment(newArgs)) = args(i)
if (args(i) = "checkout") {
set syncIrisWithDiff = 1
// Sync using diff output after the checkout has been performed
// Allows syncing remote branches as the diff will otherwise fail prior
set syncIrisWithDiffAfterGit = 1
if hasFileList {
set invert = 1
} else {
set diffCompare = args(i + 1)
if args = (i + 2) {
set diffBase = args(i + 2)
} else {
// Record the current branch to diff against after the checkout
set diffBase = ..GetCurrentBranch()
}
}
} elseif (args(i) = "restore") {
Expand Down Expand Up @@ -1964,18 +1982,16 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
set syncIrisWithCommand = 0
}

// If performing a pull don't perform a diff until after the pull has occured.
// This is to avoid a double fetch, as pull performs one for us and also to avoid a potential
// race condition if the remote changes between now and the pull actually being performed.
if syncIrisWithDiff && (command '= "pull") {
// If syncing with diff output before the git command
if syncIrisWithDiff && 'syncIrisWithDiffAfterGit {
if diffBase = "" {
set diffBase = ..GetCurrentBranch()
}

do ..RunGitCommand("fetch", .errorStream, .outputStream,"--prune")
kill errorStream, outputStream
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errorStream,.outputStream, diffBase_$Case(diffCompare,"":"",:"..")_diffCompare, "--name-status")
do ..ParseDiffStream(outputStream,,.files)
do ..ParseDiffStream(outputStream,syncIrisWithDiffVerbose,.files)
}

set outLog = ##class(%Library.File).TempFilename()
Expand All @@ -1998,11 +2014,10 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
}
}

// If performing a pull then do a diff now after the pull has occured.
if syncIrisWithDiff && (command = "pull") {
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errorStream,.outputStream, diffCompare, "--name-status")
// Verbose output should not be required as pull already outputs a summary
do ..ParseDiffStream(outputStream,0,.files)
// If syncing with diff output after the git command
if syncIrisWithDiff && syncIrisWithDiffAfterGit {
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("diff",,.errorStream,.outputStream, diffBase_$Case(diffCompare,"":"",:"..")_diffCompare, "--name-status")
do ..ParseDiffStream(outputStream,syncIrisWithDiffVerbose,.files)
}

set errStream = ##class(%Stream.FileCharacter).%OpenId(errLog,,.sc)
Expand Down
Loading