From 4a146f562d6f55d328637cdc6dab149ce3911021 Mon Sep 17 00:00:00 2001 From: Raymond Rebbeck Date: Thu, 5 Jun 2025 18:57:23 +0930 Subject: [PATCH 1/3] Refactor syncing with diff output after the Git command so it can be more easily applied to other commands Use additional flags to control when and how this behaviour takes effect rather than checking for specific commands. Will allow this to be more easily applied to other commands in the future and also to WebUI commands. --- cls/SourceControl/Git/Utils.cls | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index 924da7dd..828732e1 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -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 = "" @@ -1898,6 +1900,12 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O 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") { @@ -1964,10 +1972,8 @@ 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() } @@ -1975,7 +1981,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O 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() @@ -1998,11 +2004,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) From 445ba8283bd297d8ddbc37f06aa89f7c19f72b9d Mon Sep 17 00:00:00 2001 From: Raymond Rebbeck Date: Thu, 5 Jun 2025 23:09:24 +0930 Subject: [PATCH 2/3] Sync with diff output after a checkout is performed, allowing syncing when switching to a remote branch Switching to a remote branch would previously not sync IRIS with the file repo changes. The diff previously performed prior to the checkout Git command would fail due to the branch not yet existing locally, with nothing being synced. --- cls/SourceControl/Git/Utils.cls | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cls/SourceControl/Git/Utils.cls b/cls/SourceControl/Git/Utils.cls index 828732e1..f3ab812c 100644 --- a/cls/SourceControl/Git/Utils.cls +++ b/cls/SourceControl/Git/Utils.cls @@ -1890,10 +1890,14 @@ 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. @@ -1935,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") { From 50e4e4a46c1d3f5911c5f453fac59cbbe86ea1b0 Mon Sep 17 00:00:00 2001 From: Raymond Rebbeck Date: Thu, 5 Jun 2025 23:17:01 +0930 Subject: [PATCH 3/3] Update changelog for remote branch checkout fix (#783) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f05a05b4..6cb614cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) ## [2.11.0] - 2025-04-23